From 271e40c869046a892473ec33f94ead263a4d24c7 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Jun 2010 14:20:26 -0400 Subject: change syntax of cloud-init-cfg to allow for specifying freq for module The previous syntax was either cloud-init-cfg all or cloud-init-cfg args Ie, you could not specify the frequency if you gave a name. Now, you can. Something like: sudo cloud-init-cfg ssh always --- cloud-init-cfg.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'cloud-init-cfg.py') diff --git a/cloud-init-cfg.py b/cloud-init-cfg.py index 01c2d4f5..c29efd92 100755 --- a/cloud-init-cfg.py +++ b/cloud-init-cfg.py @@ -28,7 +28,7 @@ def Usage(out = sys.stdout): def main(): # expect to be called with - # name [ args ] + # name [ freq [ args ] # run the cloud-config job 'name' at with given args # or # read cloud config jobs from config (builtin -> system) @@ -37,9 +37,18 @@ def main(): if len(sys.argv) < 2: Usage(sys.stderr) sys.exit(1) - - name=sys.argv[1] - run_args=sys.argv[2:] + if sys.argv[1] == "all": + name = "all" + else: + freq = None + run_args = [] + name=sys.argv[1] + if len(sys.argv) > 2: + freq = sys.argv[2] + if freq == "None": + freq = None + if len(sys.argv) > 3: + run_args=sys.argv[3:] cloudinit.logging_set_from_cfg_file() log = logging.getLogger() @@ -69,8 +78,7 @@ def main(): else: fail("No cloud_config_modules found in config",log) else: - args = [ name, None ] + run_args - module_list.append = ( args ) + module_list.append( [ name, freq ] + run_args ) failures = [] for cfg_mod in module_list: @@ -84,14 +92,12 @@ def main(): try: log.debug("handling %s with freq=%s and args=%s" % - (name, run_args, freq)) + (name, freq, run_args )) cc.handle(name, run_args, freq=freq) except: - import traceback - traceback.print_exc(file=sys.stderr) - err("config handling of %s failed\n" % name,log) + err("config handling of %s, %s, %s failed\n" % + (name,freq,run_args), log) failures.append(name) - sys.exit(len(failures)) sys.exit(len(failures)) -- cgit v1.2.3