diff options
| author | Scott Moser <smoser@ubuntu.com> | 2012-06-22 16:25:20 -0400 |
|---|---|---|
| committer | Scott Moser <smoser@ubuntu.com> | 2012-06-22 16:31:24 -0400 |
| commit | a5130faf80d29b1a6ed80d03b2b167a54c209911 (patch) | |
| tree | feb4d62c12dcb9079d3708b407f33b632166052a /nova/api | |
| parent | 3252371afca71f57c171569676d5de70439d5384 (diff) | |
metadata: cleanup pubkey representation
The previous code provided a '_name' entry in a dict to represent
this, but then appended "=_name" to the key rather than populating
_name with the full value to be rendered.
This just changes the value in '_name' for public key to be
'0=keyname' rather than 'keyname'. It makes the rendering simpler by
just using the
_name.
It also adds a test for this strange behavior of the metadata service.
Change-Id: I3ef67d85354bf7ac8abaaf900ddfdd2e945aa9af
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/metadata/base.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index 379643954..cff80bc42 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -136,10 +136,18 @@ class InstanceMetadata(): if self.userdata_b64 != None: data['user-data'] = self.userdata_b64 - # public-keys should be in meta-data only if user specified one + # public keys are strangely rendered in ec2 metadata service + # meta-data/public-keys/ returns '0=keyname' (with no trailing /) + # and only if there is a public key given. + # '0=keyname' means there is a normally rendered dict at + # meta-data/public-keys/0 + # + # meta-data/public-keys/ : '0=%s' % keyname + # meta-data/public-keys/0/ : 'openssh-key' + # meta-data/public-keys/0/openssh-key : '%s' % publickey if self.instance['key_name']: data['meta-data']['public-keys'] = { - '0': {'_name': self.instance['key_name'], + '0': {'_name': "0=" + self.instance['key_name'], 'openssh-key': self.instance['key_data']}} if False: # TODO(vish): store ancestor ids @@ -241,12 +249,14 @@ def ec2_md_print(data): for key in sorted(data.keys()): if key == '_name': continue - output += key if isinstance(data[key], dict): if '_name' in data[key]: - output += '=' + str(data[key]['_name']) + output += str(data[key]['_name']) else: - output += '/' + output += key + '/' + else: + output += key + output += '\n' return output[:-1] elif isinstance(data, list): |
