summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-30 09:30:17 -0400
committerScott Moser <smoser@ubuntu.com>2012-09-30 09:30:17 -0400
commit497972223afd5193a40e3e9c4e69ce31319a1ebc (patch)
treebda83abe5575a0d51b01f3e4c04916c667520346 /cloudinit/util.py
parenta28d7fe46cf8e3277a13c35c5dd0185f65ab1d0c (diff)
parent72fc1f762e5c5df563380e9ed90bfaba131e811b (diff)
downloadvyos-cloud-init-497972223afd5193a40e3e9c4e69ce31319a1ebc.tar.gz
vyos-cloud-init-497972223afd5193a40e3e9c4e69ce31319a1ebc.zip
rework the rest of the users of old single 'user' to support lists
Rework the rest of the locations that used the previous 'user' and make those locations go through the new distros functions to select the default user or the user list (depending on usage). Adjust the tests to check the new 'default' field that signifies the default user + test the new method to extract just the default user from a normalized user dictionary. "default" user is now marked in the user dict and get_default_user uses that.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 46d490f7..f5a7ac12 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -249,6 +249,36 @@ def read_conf(fname):
raise
+# Merges X lists, and then keeps the
+# unique ones, but orders by sort order
+# instead of by the original order
+def uniq_merge_sorted(*lists):
+ return sorted(uniq_merge(*lists))
+
+
+# Merges X lists and then iterates over those
+# and only keeps the unique items (order preserving)
+# and returns that merged and uniqued list as the
+# final result.
+#
+# Note: if any entry is a string it will be
+# split on commas and empty entries will be
+# evicted and merged in accordingly.
+def uniq_merge(*lists):
+ combined_list = []
+ for a_list in lists:
+ if isinstance(a_list, (str, basestring)):
+ a_list = a_list.strip().split(",")
+ # Kickout the empty ones
+ a_list = [a for a in a_list if len(a)]
+ combined_list.extend(a_list)
+ uniq_list = []
+ for i in combined_list:
+ if i not in uniq_list:
+ uniq_list.append(i)
+ return uniq_list
+
+
def clean_filename(fn):
for (k, v) in FN_REPLACEMENTS.iteritems():
fn = fn.replace(k, v)