summaryrefslogtreecommitdiff
path: root/cloudinit/sources/helpers
diff options
context:
space:
mode:
authorRyan Harper <ryan.harper@canonical.com>2016-03-23 11:05:22 -0500
committerRyan Harper <ryan.harper@canonical.com>2016-03-23 11:05:22 -0500
commit2b85dabb802766e0b3b1949d744c8860c0cb838a (patch)
treeb35a267b5e18822613af225e7af98295674e8ef7 /cloudinit/sources/helpers
parent7f0871dc5b141ff4bf601b6d96021eba8a3bb0ec (diff)
downloadvyos-cloud-init-2b85dabb802766e0b3b1949d744c8860c0cb838a.tar.gz
vyos-cloud-init-2b85dabb802766e0b3b1949d744c8860c0cb838a.zip
configdata: parse and convert openstack network_data json to network_config
Diffstat (limited to 'cloudinit/sources/helpers')
-rw-r--r--cloudinit/sources/helpers/openstack.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
index bd93d22f..eb50a7be 100644
--- a/cloudinit/sources/helpers/openstack.py
+++ b/cloudinit/sources/helpers/openstack.py
@@ -51,11 +51,13 @@ OS_LATEST = 'latest'
OS_FOLSOM = '2012-08-10'
OS_GRIZZLY = '2013-04-04'
OS_HAVANA = '2013-10-17'
+OS_KILO = '2015-10-15'
# keep this in chronological order. new supported versions go at the end.
OS_VERSIONS = (
OS_FOLSOM,
OS_GRIZZLY,
OS_HAVANA,
+ OS_KILO,
)
@@ -229,6 +231,11 @@ class BaseReader(object):
False,
load_json_anytype,
)
+ files['networkdata'] = (
+ self._path_join("openstack", version, 'network_data.json'),
+ False,
+ load_json_anytype,
+ )
return files
results = {
@@ -334,7 +341,7 @@ class ConfigDriveReader(BaseReader):
path = self._path_join(self.base_path, 'openstack')
found = [d for d in os.listdir(path)
if os.path.isdir(os.path.join(path))]
- self._versions = found
+ self._versions = sorted(found)
return self._versions
def _read_ec2_metadata(self):
@@ -490,3 +497,28 @@ def convert_vendordata_json(data, recurse=True):
recurse=False)
raise ValueError("vendordata['cloud-init'] cannot be dict")
raise ValueError("Unknown data type for vendordata: %s" % type(data))
+
+
+def convert_networkdata_json(data, recurse=True):
+ """ data: a loaded json *object* (strings, arrays, dicts).
+ return something suitable for cloudinit networkdata_raw.
+
+ if data is:
+ None: return None
+ string: return string
+ list: return data
+ the list is then processed in UserDataProcessor
+ dict: return convert_networkdata_json(data.get('cloud-init'))
+ """
+ if not data:
+ return None
+ if isinstance(data, six.string_types):
+ return data
+ if isinstance(data, list):
+ return copy.deepcopy(data)
+ if isinstance(data, dict):
+ if recurse is True:
+ return convert_networkdata_json(data.get('cloud-init'),
+ recurse=False)
+ raise ValueError("networkdata['cloud-init'] cannot be dict")
+ raise ValueError("Unknown data type for networkdata: %s" % type(data))