summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>2016-05-23 11:59:14 +0200
committerChristian Ehrhardt <christian.ehrhardt@canonical.com>2016-05-23 11:59:14 +0200
commitee239517c5342cbd62c9fdeaf735d78d6fd1fbb8 (patch)
tree53e3ca3e9100497db2b8a1779a639c163b7c8a45 /cloudinit/util.py
parent1926eb2476f9e1fda3356c7828479231dccc309b (diff)
downloadvyos-cloud-init-ee239517c5342cbd62c9fdeaf735d78d6fd1fbb8.tar.gz
vyos-cloud-init-ee239517c5342cbd62c9fdeaf735d78d6fd1fbb8.zip
support apt_sources to be a dictionary
key is the filename, and "old" input shall be handled as it was all the time. For compatibility this will (continue to) overwrite the file of multiple options that did not specify an output file (they all get the same default). Yet it will process them all - as it always did - e.g. to add the keys of all of them. Any users of the new format won't have these issues, as they will always have a key.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 0d21e11b..2931efbd 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -335,6 +335,14 @@ def rand_str(strlen=32, select_from=None):
select_from = string.ascii_letters + string.digits
return "".join([random.choice(select_from) for _x in range(0, strlen)])
+def rand_dict_key(dictionary, postfix=None):
+ if not postfix:
+ postfix = ""
+ while True:
+ newkey = rand_str(strlen=8) + "_" + postfix
+ if newkey not in dictionary:
+ break
+ return newkey
def read_conf(fname):
try: