summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index a8ddb390..b69e2bb0 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -606,7 +606,7 @@ def del_dir(path):
shutil.rmtree(path)
-def runparts(dirp, skip_no_exist=True):
+def runparts(dirp, skip_no_exist=True, exe_prefix=None):
if skip_no_exist and not os.path.isdir(dirp):
return
@@ -617,7 +617,10 @@ def runparts(dirp, skip_no_exist=True):
if os.path.isfile(exe_path) and os.access(exe_path, os.X_OK):
attempted.append(exe_path)
try:
- subp([exe_path], capture=False)
+ exe_cmd = exe_prefix
+ if isinstance(exe_prefix, list):
+ exe_cmd.extend(exe_path)
+ subp([exe_cmd], capture=False)
except ProcessExecutionError as e:
logexc(LOG, "Failed running %s [%s]", exe_path, e.exit_code)
failed.append(e)
@@ -1847,3 +1850,26 @@ def expand_dotted_devname(dotted):
return toks
else:
return (dotted, None)
+
+
+def get_nested_option_as_list(dct, first, second):
+ """
+ Return a nested option from a dict as a list
+ """
+ if not isinstance(dct, dict):
+ raise TypeError("get_nested_option_as_list only works with dicts")
+ root = dct.get(first)
+ if not isinstance(root, dict):
+ return None
+
+ token = root.get(second)
+ if isinstance(token, list):
+ return token
+ elif isinstance(token, dict):
+ ret_list = []
+ for k, v in dct.iteritems():
+ ret_list.append((k, v))
+ return ret_list
+ elif isinstance(token, str):
+ return token.split()
+ return None