diff --git a/heat/api/v1/__init__.py b/heat/api/v1/__init__.py index 550e3a66be..8ce18894d6 100644 --- a/heat/api/v1/__init__.py +++ b/heat/api/v1/__init__.py @@ -49,6 +49,6 @@ class API(wsgi.Router): mapper.connect("/DescribeStackEvents", controller=stacks_resource, action="events_list", conditions=dict(method=["GET"])) mapper.connect("/ValidateTemplate", controller=stacks_resource, - action="validate_template", conditions=dict(method=["POST"])) + action="validate_template", conditions=dict(method=["GET"])) super(API, self).__init__(mapper) diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 6943a57860..d1b9bd4aa6 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -75,13 +75,13 @@ class StackController(object): return res - def _get_template(self, body): - if body.has_key('TemplateBody'): + def _get_template(self, req): + if req.params.has_key('TemplateBody'): logger.info('TemplateBody ...') - return body['TemplateBody'] - elif body.has_key('TemplateUrl'): - logger.info('TemplateUrl %s' % body['TemplateUrl']) - url = urlparse.urlparse(body['TemplateUrl']) + return req.params['TemplateBody'] + elif req.params.has_key('TemplateUrl'): + logger.info('TemplateUrl %s' % req.params['TemplateUrl']) + url = urlparse.urlparse(req.params['TemplateUrl']) if url.scheme == 'https': conn = httplib.HTTPSConnection(url.netloc) else: @@ -99,14 +99,14 @@ class StackController(object): return None - def create(self, req, body): + def create(self, req): """ Returns the following information for all stacks: """ c = engine.get_engine_client(req.context) try: - templ = self._get_template(body) + templ = self._get_template(req) except socket.gaierror: msg = _('Invalid Template URL') return webob.exc.HTTPBadRequest(explanation=msg) @@ -119,16 +119,16 @@ class StackController(object): except ValueError: msg = _("The Template must be a JSON document.") return webob.exc.HTTPBadRequest(explanation=msg) - stack['StackName'] = body['StackName'] + stack['StackName'] = req.params['StackName'] return c.create_stack(stack, **req.params) - def validate_template(self, req, body): + def validate_template(self, req): client = engine.get_engine_client(req.context) try: - templ = self._get_template(body) + templ = self._get_template(req) except socket.gaierror: msg = _('Invalid Template URL') return webob.exc.HTTPBadRequest(explanation=msg) diff --git a/heat/client.py b/heat/client.py index a830a69717..ed73b7c382 100644 --- a/heat/client.py +++ b/heat/client.py @@ -58,27 +58,25 @@ class V1Client(base_client.BaseClient): return data def create_stack(self, **kwargs): - body = self._extract_params(kwargs, SUPPORTED_PARAMS) - params = {} - self._insert_common_parameters(params) - res = self.do_request("POST", "/CreateStack", params=params, body=body) + params = self._extract_params(kwargs, SUPPORTED_PARAMS) + self._insert_common_parameters(params) + res = self.do_request("POST", "/CreateStack", params=params) + data = json.loads(res.read()) return data def update_stack(self, **kwargs): - body = self._extract_params(kwargs, SUPPORTED_PARAMS) - params = {} + params = self._extract_params(kwargs, SUPPORTED_PARAMS) self._insert_common_parameters(params) + res = self.do_request("PUT", "/UpdateStack", params=params) - res = self.do_request("PUT", "/UpdateStack", params=params, body=body) data = json.loads(res.read()) return data def delete_stack(self, **kwargs): params = self._extract_params(kwargs, SUPPORTED_PARAMS) self._insert_common_parameters(params) - res = self.do_request("DELETE", "/DeleteStack", params=params) data = json.loads(res.read()) return data @@ -92,12 +90,10 @@ class V1Client(base_client.BaseClient): return data def validate_template(self, **kwargs): - body = self._extract_params(kwargs, SUPPORTED_PARAMS) - params = {} + params = self._extract_params(kwargs, SUPPORTED_PARAMS) self._insert_common_parameters(params) - - res = self.do_request("POST", "/ValidateTemplate", params=params, - body=body) + + res = self.do_request("GET", "/ValidateTemplate", params=params) data = json.loads(res.read()) return data diff --git a/heat/common/client.py b/heat/common/client.py index b9a1d3ba9e..a3a49d347f 100644 --- a/heat/common/client.py +++ b/heat/common/client.py @@ -21,7 +21,6 @@ import collections import errno import functools import httplib -import json import logging import os import urllib @@ -415,10 +414,6 @@ class BaseClient(object): self._authenticate() url = self._construct_url(action, params) - headers = headers or {} - if body and not isinstance(body, basestring): - body = json.dumps(body) - headers['Content-Type'] = 'application/json' return self._do_request(method=method, url=url, body=body, headers=headers) diff --git a/heat/engine/client.py b/heat/engine/client.py index d82245e0c8..2bae31dbfd 100644 --- a/heat/engine/client.py +++ b/heat/engine/client.py @@ -91,9 +91,13 @@ class EngineClient(BaseClient): """ Validate the template """ + headers = { + 'Content-Type': 'application/json', + } + logger.info(template) - res = self.do_request("POST", "/validate_template", template, - params=kwargs) + res = self.do_request("POST", "/validate_template", body=json.dumps(template), + headers=headers, params=kwargs) data = json.loads(res.read()) logger.info(data) return data @@ -102,7 +106,12 @@ class EngineClient(BaseClient): """ Tells engine about an stack's metadata """ - res = self.do_request("POST", "/stacks", template, params=kwargs) + headers = { + 'Content-Type': 'application/json', + } + + res = self.do_request("POST", "/stacks", json.dumps(template), + headers=headers, params=kwargs) data = json.loads(res.read()) return data @@ -110,7 +119,11 @@ class EngineClient(BaseClient): """ Updates Engine's information about an stack """ - res = self.do_request("PUT", "/stacks/%s" % (stack_id), template) + headers = { + 'Content-Type': 'application/json', + } + + res = self.do_request("PUT", "/stacks/%s" % (stack_id), json.dumps(template), headers) data = json.loads(res.read()) stack = data['stack'] return stack