From c68b2c53150adebff91d8df650f60e3c50ab63c9 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 3 Jul 2012 15:04:39 +0200 Subject: [PATCH] Add Metadata to detailed Resource output Change-Id: I492b9a0a190a905ca5c8597c7236ad1d130a5b77 Signed-off-by: Zane Bitter --- heat/common/wsgi.py | 13 ++++++++----- heat/engine/manager.py | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index 83db2216fa..f2e68f4828 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -438,6 +438,11 @@ class JSONResponseSerializer(object): response.body = self.to_json(result) +# Escape XML serialization for these keys, as the AWS API defines them as +# JSON inside XML when the response format is XML. +JSON_ONLY_KEYS = ('TemplateBody', 'Metadata') + + class XMLResponseSerializer(object): def object_to_element(self, obj, element): @@ -448,11 +453,9 @@ class XMLResponseSerializer(object): elif isinstance(obj, dict): for key, value in obj.items(): subelement = etree.SubElement(element, key) - if key == "TemplateBody": - # Escape serialization for TemplateBody key, as - # AWS api defines JSON-template-inside-XML format - # ref to GetTemplate AWS CFN API docs - subelement.text = str(value) + if key in JSON_ONLY_KEYS: + if value: + subelement.text = str(value) else: self.object_to_element(value, subelement) else: diff --git a/heat/engine/manager.py b/heat/engine/manager.py index f96b98789d..bd9d250697 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -368,6 +368,7 @@ class EngineManager(manager.Manager): # this API call uses Timestamp instead of LastUpdatedTimestamp formatted['Timestamp'] = formatted['LastUpdatedTimestamp'] del formatted['LastUpdatedTimestamp'] + del formatted['Metadata'] resources.append(formatted) return resources @@ -525,6 +526,7 @@ def format_stack_resource(resource): 'PhysicalResourceId': resource.instance_id or '', 'ResourceType': resource.t['Type'], 'LastUpdatedTimestamp': heat_utils.strtime(last_updated_time), + 'Metadata': rs.rsrc_metadata, 'ResourceStatus': rs.state, 'ResourceStatusReason': rs.state_description, }