diff options
author | Angus Salkeld <asalkeld@redhat.com> | 2013-07-31 10:58:20 +1000 |
---|---|---|
committer | Angus Salkeld <asalkeld@redhat.com> | 2013-07-31 10:58:20 +1000 |
commit | b97fb83dc070cee1d12ea23b1cd7a99da42a6243 (patch) | |
tree | 79d82fb85eb8eee1dcd9cc6a576d9b1a7cda2cbe /heat_cfntools/cfntools | |
parent | 73cebadc073c4dd32d90f2254e325fcd1084b5f4 (diff) | |
download | heat-cfntools-b97fb83dc070cee1d12ea23b1cd7a99da42a6243.tar.gz |
Add a get_tags() method to the Metadata class
Tags are not properly implemented in nova so we pass the tags
to nova as metadata. So we now [w]get the nova metadata.
Since this is called repeatedly we cache the metadata.
We also add the nova instance id (uuid) as a guest tag.
Change-Id: I599f22fd5166e88cb3d21a71ead5f48c5c5a9269
Diffstat (limited to 'heat_cfntools/cfntools')
-rw-r--r-- | heat_cfntools/cfntools/cfn_helper.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/heat_cfntools/cfntools/cfn_helper.py b/heat_cfntools/cfntools/cfn_helper.py index 371e990..54f3f87 100644 --- a/heat_cfntools/cfntools/cfn_helper.py +++ b/heat_cfntools/cfntools/cfn_helper.py @@ -1059,6 +1059,36 @@ class Metadata(object): 'DescribeStackResourceResult']['StackResourceDetail'] return resource_detail['Metadata'] + def get_nova_meta(self, + cache_path='/var/lib/heat-cfntools/nova_meta.json'): + """Get nova's meta_data.json and cache it. + + Since this is called repeatedly return the cached metadata, + if we have it. + """ + + url = 'http://169.254.169.254/openstack/2012-08-10/meta_data.json' + if not os.path.exists(cache_path): + CommandRunner('wget -O %s %s' % (cache_path, url)).run() + try: + with open(cache_path) as fd: + try: + return json.load(fd) + except ValueError: + pass + except IOError: + pass + return None + + def get_tags(self): + """Get the tags for this server.""" + tags = {} + md = self.get_nova_meta() + if md is not None: + tags.update(md.get('meta', {})) + tags['InstanceId'] = md['uuid'] + return tags + def retrieve( self, meta_str=None, |