summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-01-29 14:32:51 -0500
committerScott Moser <smoser@ubuntu.com>2014-01-29 14:32:51 -0500
commit3cfe9b3d8958b1a4e450d5ff31d805c424945027 (patch)
treeb05977c13f4d8dbdb111b7392e2a5689ad381b84 /cloudinit/util.py
parent06c80d8b0dcb8cf1013885fc745bf48d57b39ce4 (diff)
parent29b56e5ad6a5ec0eedbedcc598f633b1f5302a8a (diff)
downloadvyos-cloud-init-3cfe9b3d8958b1a4e450d5ff31d805c424945027.tar.gz
vyos-cloud-init-3cfe9b3d8958b1a4e450d5ff31d805c424945027.zip
DataSourceNoCloud: support reading vendor-data
Here we add the ability to read vendor-data from a file named vendor-data at the same location as the user-data and meta-data files. At the moment, vendor-data is not read at all from 'seedfrom'.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 61bcdeb1..08cdd8c8 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -369,11 +369,11 @@ def is_ipv4(instr):
return False
try:
- toks = [x for x in toks if (int(x) < 256 and int(x) >= 0)]
+ toks = [x for x in toks if int(x) < 256 and int(x) >= 0]
except:
return False
- return (len(toks) == 4)
+ return len(toks) == 4
def get_cfg_option_bool(yobj, key, default=False):
@@ -972,7 +972,7 @@ def gethostbyaddr(ip):
def is_resolvable_url(url):
"""determine if this url is resolvable (existing or ip)."""
- return (is_resolvable(urlparse.urlparse(url).hostname))
+ return is_resolvable(urlparse.urlparse(url).hostname)
def search_for_mirror(candidates):
@@ -1889,3 +1889,28 @@ def expand_dotted_devname(dotted):
return toks
else:
return (dotted, None)
+
+
+def pathprefix2dict(base, required=None, optional=None, delim=os.path.sep):
+ # return a dictionary populated with keys in 'required' and 'optional'
+ # by reading files in prefix + delim + entry
+ if required is None:
+ required = []
+ if optional is None:
+ optional = []
+
+ missing = []
+ ret = {}
+ for f in required + optional:
+ try:
+ ret[f] = load_file(base + delim + f, quiet=False)
+ except IOError as e:
+ if e.errno != errno.ENOENT:
+ raise
+ if f in required:
+ missing.append(f)
+
+ if len(missing):
+ raise ValueError("Missing required files: %s", ','.join(missing))
+
+ return ret