From b35772387cb9ae8232ec5986950ec6789f46b202 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 18 Jun 2012 21:09:11 -0700 Subject: 1. Allow the built-in config to be passed in when getting the base config 2. Move the cloudinit util function that writes the command line url to a file to here. --- cloudinit/util.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'cloudinit/util.py') diff --git a/cloudinit/util.py b/cloudinit/util.py index aaeaa5fc..164bcea8 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1021,6 +1021,25 @@ def ensure_dirs(dirlist, mode=0755): ensure_dir(d, mode) +def read_write_cmdline_url(target_fn): + if not os.path.exists(target_fn): + try: + (key, url, content) = get_cmdline_url() + except: + logexc(LOG, "Failed fetching command line url") + return + try: + if key and content: + write_file(target_fn, content, mode=0600) + LOG.debug(("Wrote to %s with contents of command line" + " url %s (len=%s)"), target_fn, url, len(content)) + elif key and not content: + LOG.debug(("Command line key %s with url" + " %s had no contents"), key, url) + except: + logexc(LOG, "Failed writing url content to %s", target_fn) + + def yaml_dumps(obj): formatted = yaml.dump(obj, line_break="\n", @@ -1045,10 +1064,12 @@ def ensure_dir(path, mode=None): chmod(path, mode) -def get_base_cfg(cfg_path=None): +def get_base_cfg(cfg_path=None, builtin=None): if not cfg_path: cfg_path = CLOUD_CONFIG - return merge_base_cfg(cfg_path, get_builtin_cfg()) + if not builtin: + builtin = get_builtin_cfg() + return merge_base_cfg(cfg_path, builtin) @contextlib.contextmanager -- cgit v1.2.3