summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-02-13 10:58:08 -0500
committerScott Moser <smoser@ubuntu.com>2014-02-13 10:58:08 -0500
commit64856d7f245cc329a11b263c4eef8bf76bdee0e6 (patch)
tree0c522f6e5c9f547c73d94357fc3cbd11acd421f4 /cloudinit
parent065287bd56fe7f63a8dc41fa1457be4439f20efd (diff)
downloadvyos-cloud-init-64856d7f245cc329a11b263c4eef8bf76bdee0e6.tar.gz
vyos-cloud-init-64856d7f245cc329a11b263c4eef8bf76bdee0e6.zip
add 'user-data' support.
This just adds user-data in 'instance/attributes/user-data'. Also turns retries to 0 on all other things.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceGCE.py15
1 files changed, 11 insertions, 4 deletions
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']