From cd94c31909b98563663d9cf98b8c42a96c3ca188 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Fri, 29 Jun 2012 13:08:47 +0100 Subject: [PATCH] heat API : Make CreateStack work with boto Further API rework to make stack creation work via boto - Use webob.request.params not GET, as boto passes POST parameters in body - Wrap CreateStack response in CreateStackResponse as expected by boto - Add API debug for JSON format responses - (second version in stackforge due to long-line fix) ref #125 Change-Id: I347368ee0395a9019fae69a06e45260379ed7722 Signed-off-by: Steven Hardy --- heat/api/v1/__init__.py | 2 +- heat/api/v1/stacks.py | 6 +++++- heat/common/wsgi.py | 11 +++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/heat/api/v1/__init__.py b/heat/api/v1/__init__.py index 6091665710..8f0efbd4b9 100644 --- a/heat/api/v1/__init__.py +++ b/heat/api/v1/__init__.py @@ -146,7 +146,7 @@ class API(wsgi.Router): def action_match(environ, result): req = Request(environ) - env_action = req.GET.get("Action") + env_action = req.params.get("Action") return env_action == api_action return {'function': action_match} diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index cf94803904..be8cd8407e 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -169,7 +169,11 @@ class StackController(object): except rpc_common.RemoteError as ex: return webob.exc.HTTPBadRequest(str(ex)) - return {'CreateStackResult': self._stackid_addprefix(res)} + # Note boto expects CreateStackResult wrapped in CreateStackResponse + # CreateStackResponse is not mentioned in the aws API docs, so we + # need to check against a real AWS response to ensure this is correct + return {'CreateStackResponse': + {'CreateStackResult': self._stackid_addprefix(res)}} def get_template(self, req): diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index 24d0d0cfce..83db2216fa 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -429,7 +429,9 @@ class JSONResponseSerializer(object): return obj.isoformat() return obj - return json.dumps(data, default=sanitizer) + response = json.dumps(data, default=sanitizer) + logging.debug("JSON response : %s" % response) + return response def default(self, response, result): response.content_type = 'application/json' @@ -462,8 +464,9 @@ class XMLResponseSerializer(object): eltree = etree.Element(root) doc = etree.ElementTree(eltree) self.object_to_element(data.get(root), eltree) - logging.debug("XML response : %s" % etree.tostring(eltree)) - return etree.tostring(eltree) + response = etree.tostring(eltree) + logging.debug("XML response : %s" % response) + return response def default(self, response, result): response.content_type = 'application/xml' @@ -512,7 +515,7 @@ class Resource(object): # would appear that the default response serialization is XML, as # described in the API docs, but passing a query parameter of # ContentType=JSON results in a JSON serialized response... - content_type = request.GET.get("ContentType") + content_type = request.params.get("ContentType") deserialized_request = self.dispatch(self.deserializer, action, request)