diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-01-06 12:12:09 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-01-06 12:12:09 -0500 |
commit | 62e9e73e3ed8467fc4d4d95f76ed0443c50f176c (patch) | |
tree | 31c6d16940a24951e64d1a371c4a4f35b2aa08a3 /cloudinit | |
parent | 38c851e58e09c5574661ef4b2d2e66f6e38063d1 (diff) | |
parent | b8eb056fd7fda5f50f07d7c0a0bc65c67d770f5e (diff) | |
download | vyos-cloud-init-62e9e73e3ed8467fc4d4d95f76ed0443c50f176c.tar.gz vyos-cloud-init-62e9e73e3ed8467fc4d4d95f76ed0443c50f176c.zip |
Enable user-data encoding support for GCE.
Enable user-data encoding support for GCE. Extended and updated tests to
support checking the user-data encoding.
User can now pass in user-data encoded in base64 and indicate they've
done so by adding a tag 'user-data-encoding' with value 'base64'.
LP: #1404311
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/sources/DataSourceGCE.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index 7091e3c1..92e5a28e 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -15,6 +15,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +from base64 import b64decode + from cloudinit import log as logging from cloudinit import util from cloudinit import sources @@ -27,7 +29,6 @@ BUILTIN_DS_CONFIG = { } REQUIRED_FIELDS = ('instance-id', 'availability-zone', 'local-hostname') - class DataSourceGCE(sources.DataSource): def __init__(self, sys_cfg, distro, paths): sources.DataSource.__init__(self, sys_cfg, distro, paths) @@ -58,6 +59,7 @@ class DataSourceGCE(sources.DataSource): ('local-hostname', 'instance/hostname', True), ('public-keys', 'project/attributes/sshKeys', False), ('user-data', 'instance/attributes/user-data', False), + ('user-data-encoding', 'instance/attributes/user-data-encoding', False), ] # if we cannot resolve the metadata server, then no point in trying @@ -101,6 +103,13 @@ class DataSourceGCE(sources.DataSource): lines = self.metadata['public-keys'].splitlines() self.metadata['public-keys'] = [self._trim_key(k) for k in lines] + encoding = self.metadata.get('user-data-encoding') + if encoding: + if encoding == 'base64': + self.metadata['user-data'] = b64decode(self.metadata['user-data']) + else: + LOG.warn('unknown user-data-encoding: %s, ignoring', encoding) + return found @property |