summaryrefslogtreecommitdiff
path: root/cloud-init-cfg.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloud-init-cfg.py')
-rwxr-xr-xcloud-init-cfg.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/cloud-init-cfg.py b/cloud-init-cfg.py
index 2930cd88..3a475c1c 100755
--- a/cloud-init-cfg.py
+++ b/cloud-init-cfg.py
@@ -2,8 +2,10 @@
# vi: ts=4 expandtab
#
# Copyright (C) 2009-2010 Canonical Ltd.
+# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
#
# Author: Scott Moser <scott.moser@canonical.com>
+# Author: Juerg Haefliger <juerg.haefliger@hp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
@@ -23,11 +25,12 @@ import cloudinit.util as util
import cloudinit.CloudConfig as CC
import logging
import os
-import traceback
-def Usage(out = sys.stdout):
+
+def Usage(out=sys.stdout):
out.write("Usage: %s name\n" % sys.argv[0])
-
+
+
def main():
# expect to be called with
# name [ freq [ args ]
@@ -39,7 +42,7 @@ def main():
util.close_stdin()
modename = "config"
-
+
if len(sys.argv) < 2:
Usage(sys.stderr)
sys.exit(1)
@@ -50,30 +53,30 @@ def main():
else:
freq = None
run_args = []
- name=sys.argv[1]
+ 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:]
+ run_args = sys.argv[3:]
cfg_path = cloudinit.get_ipath_cur("cloud_config")
cfg_env_name = cloudinit.cfg_env_name
- if os.environ.has_key(cfg_env_name):
+ if cfg_env_name in os.environ:
cfg_path = os.environ[cfg_env_name]
- cloud = cloudinit.CloudInit(ds_deps=[]) # ds_deps=[], get only cached
+ cloud = cloudinit.CloudInit(ds_deps=[]) # ds_deps=[], get only cached
try:
cloud.get_data_source()
except cloudinit.DataSourceNotFoundException as e:
# there was no datasource found, theres nothing to do
sys.exit(0)
- cc = CC.CloudConfig(cfg_path,cloud)
+ cc = CC.CloudConfig(cfg_path, cloud)
try:
- (outfmt, errfmt) = CC.get_output_cfg(cc.cfg,modename)
+ (outfmt, errfmt) = CC.get_output_cfg(cc.cfg, modename)
CC.redirect_output(outfmt, errfmt)
except Exception as e:
err("Failed to get and set output config: %s\n" % e)
@@ -82,28 +85,30 @@ def main():
log = logging.getLogger()
log.info("cloud-init-cfg %s" % sys.argv[1:])
- module_list = [ ]
+ module_list = []
if name == "all":
modlist_cfg_name = "cloud_%s_modules" % modename
- module_list = CC.read_cc_modules(cc.cfg,modlist_cfg_name)
+ module_list = CC.read_cc_modules(cc.cfg, modlist_cfg_name)
if not len(module_list):
- err("no modules to run in cloud_config [%s]" % modename,log)
+ err("no modules to run in cloud_config [%s]" % modename, log)
sys.exit(0)
else:
- module_list.append( [ name, freq ] + run_args )
+ module_list.append([name, freq] + run_args)
- failures = CC.run_cc_modules(cc,module_list,log)
+ failures = CC.run_cc_modules(cc, module_list, log)
if len(failures):
- err("errors running cloud_config [%s]: %s" % (modename,failures), log)
+ err("errors running cloud_config [%s]: %s" % (modename, failures), log)
sys.exit(len(failures))
-def err(msg,log=None):
+
+def err(msg, log=None):
if log:
log.error(msg)
sys.stderr.write(msg + "\n")
-def fail(msg,log=None):
- err(msg,log)
+
+def fail(msg, log=None):
+ err(msg, log)
sys.exit(1)
if __name__ == '__main__':