summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceGCE.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-02-25 19:40:33 -0500
committerScott Moser <smoser@ubuntu.com>2015-02-25 19:40:33 -0500
commit8cd5d7b143f882d80d45b1c04bdde1949846d4f1 (patch)
tree066a65a504d1409f9caa5d1298e07caa337064e8 /cloudinit/sources/DataSourceGCE.py
parente2fea567772f3d178072607aee617c3792185db0 (diff)
downloadvyos-cloud-init-8cd5d7b143f882d80d45b1c04bdde1949846d4f1.tar.gz
vyos-cloud-init-8cd5d7b143f882d80d45b1c04bdde1949846d4f1.zip
move towards user-data being binary
UrlResponse: biggest change... make readurl return bytes, making user know what to do with it. util: add load_tfile_or_url for loading text file or url as read_file_or_url now returns bytes ec2_utils: all meta-data is text, remove non-obvious string translations DigitalOcean: adjust for ec2_utils DataSourceGCE, DataSourceMAAS: user-data is binary other fields are text. openstack.py: read paths without decoding to text. This is ok as paths other than user-data are json, and load_json will handle load_file still returns text, and that is what most things use.
Diffstat (limited to 'cloudinit/sources/DataSourceGCE.py')
-rw-r--r--cloudinit/sources/DataSourceGCE.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py
index 6936c74e..608c07f1 100644
--- a/cloudinit/sources/DataSourceGCE.py
+++ b/cloudinit/sources/DataSourceGCE.py
@@ -53,15 +53,15 @@ class DataSourceGCE(sources.DataSource):
# GCE metadata server requires a custom header since v1
headers = {'X-Google-Metadata-Request': True}
- # url_map: (our-key, path, required)
+ # url_map: (our-key, path, required, is_text)
url_map = [
- ('instance-id', 'instance/id', True),
- ('availability-zone', 'instance/zone', True),
- ('local-hostname', 'instance/hostname', True),
- ('public-keys', 'project/attributes/sshKeys', False),
- ('user-data', 'instance/attributes/user-data', False),
+ ('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),
+ False, True),
]
# if we cannot resolve the metadata server, then no point in trying
@@ -71,13 +71,16 @@ class DataSourceGCE(sources.DataSource):
# iterate over url_map keys to get metadata items
found = False
- for (mkey, path, required) in url_map:
+ for (mkey, path, required, is_text) in url_map:
try:
resp = url_helper.readurl(url=self.metadata_address + path,
headers=headers)
if resp.code == 200:
found = True
- self.metadata[mkey] = resp.contents
+ if is_text:
+ self.metadata[mkey] = util.decode_binary(resp.contents)
+ else:
+ self.metadata[mkey] = resp.contents
else:
if required:
msg = "required url %s returned code %s. not GCE"