summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceGCE.py
diff options
context:
space:
mode:
authorDaniel Watkins <daniel.watkins@canonical.com>2015-04-20 15:24:21 +0100
committerDaniel Watkins <daniel.watkins@canonical.com>2015-04-20 15:24:21 +0100
commit6e84c05d2dc402de8cc4ae414af8657b97317218 (patch)
tree9ea2977b03c75363a0d4f119ec31f1303fa89794 /cloudinit/sources/DataSourceGCE.py
parent47eb1c4b52a2f5f4f8ea657918acd94209668bd7 (diff)
downloadcloud-init-git-6e84c05d2dc402de8cc4ae414af8657b97317218.tar.gz
Support multiple metadata paths for metadata keys in GCE data source.
Diffstat (limited to 'cloudinit/sources/DataSourceGCE.py')
-rw-r--r--cloudinit/sources/DataSourceGCE.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py
index 9cf2f56e..1a133c28 100644
--- a/cloudinit/sources/DataSourceGCE.py
+++ b/cloudinit/sources/DataSourceGCE.py
@@ -77,12 +77,12 @@ class DataSourceGCE(sources.DataSource):
def get_data(self):
# url_map: (our-key, path, required, is_text)
url_map = [
- ('instance-id', 'instance/id', True, True),
- ('availability-zone', 'instance/zone', True, True),
- ('local-hostname', 'instance/hostname', True, True),
- ('public-keys', 'project/attributes/sshKeys', False, True),
- ('user-data', 'instance/attributes/user-data', False, False),
- ('user-data-encoding', 'instance/attributes/user-data-encoding',
+ ('instance-id', ('instance/id',), True, True),
+ ('availability-zone', ('instance/zone',), True, True),
+ ('local-hostname', ('instance/hostname',), True, True),
+ ('public-keys', ('project/attributes/sshKeys',), False, True),
+ ('user-data', ('instance/attributes/user-data',), False, False),
+ ('user-data-encoding', ('instance/attributes/user-data-encoding',),
False, True),
]
@@ -94,16 +94,20 @@ class DataSourceGCE(sources.DataSource):
metadata_fetcher = GoogleMetadataFetcher(self.metadata_address)
# iterate over url_map keys to get metadata items
running_on_gce = False
- for (mkey, path, required, is_text) in url_map:
- value = metadata_fetcher.get_value(path, is_text)
+ for (mkey, paths, required, is_text) in url_map:
+ value = None
+ for path in paths:
+ new_value = metadata_fetcher.get_value(path, is_text)
+ if new_value is not None:
+ value = new_value
if value:
running_on_gce = True
if required and value is None:
- msg = "required url %s returned nothing. not GCE"
+ msg = "required key %s returned nothing. not GCE"
if not running_on_gce:
- LOG.debug(msg, path)
+ LOG.debug(msg, mkey)
else:
- LOG.warn(msg, path)
+ LOG.warn(msg, mkey)
return False
self.metadata[mkey] = value