summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-09-28 13:20:55 -0700
committerScott Moser <smoser@brickies.net>2017-06-08 12:59:48 -0400
commit41d46bfb85929c79dabcec3cf21c8d71401fd2b8 (patch)
treea8d1dfca99db8f172f936f2ae22b486d2749241e /tools
parente7c95208451422cfd3da7edfbd67dd271e7aa337 (diff)
downloadvyos-cloud-init-41d46bfb85929c79dabcec3cf21c8d71401fd2b8.tar.gz
vyos-cloud-init-41d46bfb85929c79dabcec3cf21c8d71401fd2b8.zip
cloud.cfg: move to a template. setup.py changes along the way.
Here we move the config/cloud.cfg to be rendered as a template. That allows us to maintain deltas between distros in one place. Currently we use 'variant' variable to make decisions. A tools/render-cloudcfg is provided to render the file. There were changes to setup.py, MANIFEST.in to allow us to put all files into a virtual env installation and to render the cloud-config file in 'install' or 'bdist' targets. We have also included some config changes that were found in the redhat distro spec. * include some config changes from the redhat distro spec. The rendered cloud.cfg has some differences. Ubuntu: white space and comment changes only. Freebsd: - whitespace changes and comment changes - datasource_list definition moved to be closer to 'datasource'. - enable modules: migrator, write_files - move package-update-upgrade-install to final. The initial work was done by Josh Harlow.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/render-cloudcfg43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/render-cloudcfg b/tools/render-cloudcfg
new file mode 100755
index 00000000..e624541a
--- /dev/null
+++ b/tools/render-cloudcfg
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import sys
+
+if "avoid-pep8-E402-import-not-top-of-file":
+ _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+ sys.path.insert(0, _tdir)
+ from cloudinit import templater
+ from cloudinit import util
+ from cloudinit.atomic_helper import write_file
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ variants = ["bsd", "centos", "fedora", "rhel", "ubuntu", "unknown"]
+ platform = util.system_info()
+ parser.add_argument(
+ "--variant", default=platform['variant'], action="store",
+ help="define the variant.", choices=variants)
+ parser.add_argument(
+ "template", nargs="?", action="store",
+ default='./config/cloud.cfg.tmpl',
+ help="Path to the cloud.cfg template")
+ parser.add_argument(
+ "output", nargs="?", action="store", default="-",
+ help="Output file. Use '-' to write to stdout")
+
+ args = parser.parse_args()
+
+ with open(args.template, 'r') as fh:
+ contents = fh.read()
+ tpl_params = {'variant': args.variant}
+ contents = (templater.render_string(contents, tpl_params)).rstrip() + "\n"
+ util.load_yaml(contents)
+ if args.output == "-":
+ sys.stdout.write(contents)
+ else:
+ write_file(args.output, contents, omode="w")
+
+if __name__ == '__main__':
+ main()