summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-09-10 16:12:28 -0400
committerScott Moser <smoser@ubuntu.com>2014-09-10 16:12:28 -0400
commit4a03c618b58e4da727992441aa760057e5424379 (patch)
tree7ff89798777a0ee0418d959db81147853db380c3 /cloudinit/sources
parent67f198ceb6dfeb82b2d3f78955d21d09d43fa7db (diff)
parent44113217719ebee756325b40a5d14045ba8f3a3a (diff)
downloadvyos-cloud-init-4a03c618b58e4da727992441aa760057e5424379.tar.gz
vyos-cloud-init-4a03c618b58e4da727992441aa760057e5424379.zip
ConfigDrive: support reading vendor_data similar to OpenStack MD reader
This makes the DataSourceConfigDrive support vendor-data in the same way the metadata service reader does. There are still some things to fix here, but now we're similar between these two. Also drops the ability to specify a version (as in YYYY-MM-DD) that you want to look for. Nothing was using this, but it may be useful to add back in in the future and expose as a datasource config option.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py13
-rw-r--r--cloudinit/sources/DataSourceOpenStack.py7
-rw-r--r--cloudinit/sources/helpers/openstack.py23
3 files changed, 24 insertions, 19 deletions
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 0c35f83a..a27d07fb 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -125,7 +125,14 @@ class DataSourceConfigDrive(openstack.SourceMixin, sources.DataSource):
self.userdata_raw = results.get('userdata')
self.version = results['version']
self.files.update(results.get('files', {}))
- self.vendordata_raw = results.get('vendordata')
+
+ # If there is no vendordata, set vd to an empty dict instead of None
+ vd = results.get('vendordata', {})
+ # if vendordata includes 'cloud-init', then read that explicitly
+ # for cloud-init (for namespacing).
+ if 'cloud-init' in vd:
+ self.vendordata_raw = vd['cloud-init']
+
return True
@@ -160,10 +167,10 @@ def get_ds_mode(cfgdrv_ver, ds_cfg=None, user=None):
return "net"
-def read_config_drive(source_dir, version="2012-08-10"):
+def read_config_drive(source_dir):
reader = openstack.ConfigDriveReader(source_dir)
finders = [
- (reader.read_v2, [], {'version': version}),
+ (reader.read_v2, [], {}),
(reader.read_v1, [], {}),
]
excps = []
diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py
index 0970d07b..466de8f4 100644
--- a/cloudinit/sources/DataSourceOpenStack.py
+++ b/cloudinit/sources/DataSourceOpenStack.py
@@ -119,8 +119,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
'Crawl of openstack metadata service',
read_metadata_service,
args=[self.metadata_address],
- kwargs={'ssl_details': self.ssl_details,
- 'version': openstack.OS_HAVANA})
+ kwargs={'ssl_details': self.ssl_details})
except openstack.NonReadable:
return False
except (openstack.BrokenMetadata, IOError):
@@ -154,9 +153,9 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
return True
-def read_metadata_service(base_url, version=None, ssl_details=None):
+def read_metadata_service(base_url, ssl_details=None):
reader = openstack.MetadataReader(base_url, ssl_details=ssl_details)
- return reader.read_v2(version=version)
+ return reader.read_v2()
# Used to match classes to dependencies
diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
index 3c3de7e4..a7dd05df 100644
--- a/cloudinit/sources/helpers/openstack.py
+++ b/cloudinit/sources/helpers/openstack.py
@@ -48,6 +48,7 @@ OS_LATEST = 'latest'
OS_FOLSOM = '2012-08-10'
OS_GRIZZLY = '2013-04-04'
OS_HAVANA = '2013-10-17'
+# keep this in chronological order. new supported versions go at the end.
OS_VERSIONS = (
OS_FOLSOM,
OS_GRIZZLY,
@@ -161,7 +162,7 @@ class BaseReader(object):
def _read_ec2_metadata(self):
pass
- def _find_working_version(self, version):
+ def _find_working_version(self):
try:
versions_available = self._fetch_available_versions()
except Exception as e:
@@ -169,19 +170,19 @@ class BaseReader(object):
self.base_path, e)
versions_available = []
- search_versions = [version] + list(OS_VERSIONS)
+ # openstack.OS_VERSIONS is stored in chronological order, so
+ # reverse it to check newest first.
+ supported = [v for v in reversed(list(OS_VERSIONS))]
selected_version = OS_LATEST
- for potential_version in search_versions:
+
+ for potential_version in supported:
if potential_version not in versions_available:
continue
selected_version = potential_version
break
- if selected_version != version:
- LOG.warn("Version '%s' not available, attempting to use "
- "version '%s' instead", version, selected_version)
- else:
- LOG.debug("Version '%s' was available.", version)
+ LOG.debug("Selected version '%s' from %s", selected_version,
+ versions_available)
return selected_version
def _read_content_path(self, item):
@@ -193,7 +194,7 @@ class BaseReader(object):
path = self._path_join(self.base_path, "openstack", *path_pieces)
return self._path_read(path)
- def read_v2(self, version=None):
+ def read_v2(self):
"""Reads a version 2 formatted location.
Return a dict with metadata, userdata, ec2-metadata, dsmode,
@@ -224,12 +225,11 @@ class BaseReader(object):
)
return files
- version = self._find_working_version(version)
results = {
'userdata': '',
'version': 2,
}
- data = datafiles(version)
+ data = datafiles(self._find_working_version())
for (name, (path, required, translator)) in data.iteritems():
path = self._path_join(self.base_path, path)
data = None
@@ -433,7 +433,6 @@ class MetadataReader(BaseReader):
self._versions = found
return self._versions
-
def _path_read(self, path):
def should_retry_cb(_request_args, cause):