diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-01-21 21:49:55 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-01-21 21:49:55 -0500 |
commit | 7e2e87f2de893835900eb5a96458a865f36c624c (patch) | |
tree | 9f4e168b418b18eb4df0bedaaad5ed57bc09cbd3 /cloud-init-cfg.py | |
parent | 154722cc740299c6c9d1b3bc9d1e96088f9259eb (diff) | |
download | vyos-cloud-init-7e2e87f2de893835900eb5a96458a865f36c624c.tar.gz vyos-cloud-init-7e2e87f2de893835900eb5a96458a865f36c624c.zip |
add function to cloud-init to run cloud-config style modules
add 'hostname' cloud-config option for setting hostname
make rsyslog and resizefs run at cloud-init time
Diffstat (limited to 'cloud-init-cfg.py')
-rwxr-xr-x | cloud-init-cfg.py | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/cloud-init-cfg.py b/cloud-init-cfg.py index 326062a8..b1c63a17 100755 --- a/cloud-init-cfg.py +++ b/cloud-init-cfg.py @@ -19,7 +19,7 @@ import sys import cloudinit -import cloudinit.CloudConfig +import cloudinit.CloudConfig as CC import logging import os import traceback @@ -60,47 +60,20 @@ def main(): if os.environ.has_key(cfg_env_name): cfg_path = os.environ[cfg_env_name] - cc = cloudinit.CloudConfig.CloudConfig(cfg_path) + cc = CC.CloudConfig(cfg_path) module_list = [ ] if name == "all": - # create 'module_list', an array of arrays - # where array[0] = config - # array[1] = freq - # array[2:] = arguemnts - if "cloud_config_modules" in cc.cfg: - for item in cc.cfg["cloud_config_modules"]: - if isinstance(item,str): - module_list.append((item,)) - elif isinstance(item,list): - module_list.append(item) - else: - fail("Failed to parse cloud_config_modules",log) - else: - fail("No cloud_config_modules found in config",log) + modules_list = CC.read_cc_modules(cc.cfg,"cloud_config_modules") + if not len(modules_list): + err("no modules to run in cloud_config",log) + sys.exit(0) else: module_list.append( [ name, freq ] + run_args ) - failures = [] - for cfg_mod in module_list: - name = cfg_mod[0] - freq = None - run_args = [ ] - if len(cfg_mod) > 1: - freq = cfg_mod[1] - if len(cfg_mod) > 2: - run_args = cfg_mod[2:] - - try: - log.debug("handling %s with freq=%s and args=%s" % - (name, freq, run_args )) - cc.handle(name, run_args, freq=freq) - except: - log.warn(traceback.format_exc()) - err("config handling of %s, %s, %s failed\n" % - (name,freq,run_args), log) - failures.append(name) - + failures = CC.run_cc_modules(cc,module_list,log) + if len(failures): + err("errors running cloud_config modules: %s" % failures) sys.exit(len(failures)) def err(msg,log=None): |