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 /cloudinit/CloudConfig/__init__.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 'cloudinit/CloudConfig/__init__.py')
-rw-r--r-- | cloudinit/CloudConfig/__init__.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py index 0a91059a..bfed44b7 100644 --- a/cloudinit/CloudConfig/__init__.py +++ b/cloudinit/CloudConfig/__init__.py @@ -29,8 +29,11 @@ class CloudConfig(): cfgfile = None cfg = None - def __init__(self,cfgfile): - self.cloud = cloudinit.CloudInit() + def __init__(self,cfgfile, cloud=None): + if cloud == None: + self.cloud = cloudinit.CloudInit() + else: + self.cloud = cloud self.cfg = self.get_config_obj(cfgfile) self.cloud.get_data_source() @@ -38,6 +41,7 @@ class CloudConfig(): try: cfg = util.read_conf(cfgfile) except: + # TODO: this 'log' could/should be passed in cloudinit.log.critical("Failed loading of cloud config '%s'. Continuing with empty config\n" % cfgfile) cloudinit.log.debug(traceback.format_exc() + "\n") cfg = None @@ -58,3 +62,43 @@ class CloudConfig(): except: raise +# reads a cloudconfig module list, returns +# a 2 dimensional array suitable to pass to run_cc_modules +def read_cc_modules(cfg,name): + if name not in cfg: return([]) + module_list = [] + # create 'module_list', an array of arrays + # where array[0] = config + # array[1] = freq + # array[2:] = arguemnts + for item in cfg[name]: + if isinstance(item,str): + module_list.append((item,)) + elif isinstance(item,list): + module_list.append(item) + else: + raise TypeError("failed to read '%s' item in config") + return(module_list) + +def run_cc_modules(cc,module_list,log): + 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()) + log.err("config handling of %s, %s, %s failed\n" % + (name,freq,run_args)) + failures.append(name) + + return(failures) |