summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-18 21:09:11 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-18 21:09:11 -0700
commitb35772387cb9ae8232ec5986950ec6789f46b202 (patch)
tree649a104336936fa5937d6fd8ce34150ca7e75bbe /cloudinit/util.py
parent55771ac86ae46232aabc9ec7419e9da0782f9986 (diff)
downloadvyos-cloud-init-b35772387cb9ae8232ec5986950ec6789f46b202.tar.gz
vyos-cloud-init-b35772387cb9ae8232ec5986950ec6789f46b202.zip
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.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py25
1 files changed, 23 insertions, 2 deletions
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