From 64856d7f245cc329a11b263c4eef8bf76bdee0e6 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 13 Feb 2014 10:58:08 -0500 Subject: add 'user-data' support. This just adds user-data in 'instance/attributes/user-data'. Also turns retries to 0 on all other things. --- cloudinit/sources/DataSourceGCE.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'cloudinit/sources/DataSourceGCE.py') diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index 6eb3da4d..95a410ba 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__) BUILTIN_DS_CONFIG = { 'metadata_url': 'http://metadata.google.internal./computeMetadata/v1/' } +REQUIRED_FIELDS = ('instance-id', 'availability-zone', 'local-hostname') class DataSourceGCE(sources.DataSource): @@ -55,6 +56,7 @@ class DataSourceGCE(sources.DataSource): 'availability-zone': self.metadata_address + 'instance/zone', 'public-keys': self.metadata_address + 'project/attributes/sshKeys', 'local-hostname': self.metadata_address + 'instance/hostname', + 'user-data': self.metadata_address + 'instance/attributes/user-data', } # if we cannot resolve the metadata server, then no point in trying @@ -64,7 +66,8 @@ class DataSourceGCE(sources.DataSource): for mkey in url_map.iterkeys(): try: - resp = url_helper.readurl(url=url_map[mkey], headers=headers) + resp = url_helper.readurl(url=url_map[mkey], headers=headers, + retries=0) except IOError: return False if resp.ok(): @@ -74,8 +77,15 @@ class DataSourceGCE(sources.DataSource): else: self.metadata[mkey] = resp.contents else: + if mkey in REQUIRED_FIELDS: + LOG.warn("required metadata '%s' not found in metadata", + url_map[mkey]) + return False + self.metadata[mkey] = None return False + + self.user_data_raw = self.metadata['user-data'] return True @property @@ -92,9 +102,6 @@ class DataSourceGCE(sources.DataSource): def get_hostname(self, fqdn=False): return self.metadata['local-hostname'] - def get_userdata_raw(self): - return None - @property def availability_zone(self): return self.metadata['instance-zone'] -- cgit v1.2.3