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=["GET"]))
+ action="validate_template", conditions=dict(method=["POST"]))
super(API, self).__init__(mapper)
return res
- def _get_template(self, req):
- if req.params.has_key('TemplateBody'):
+ def _get_template(self, body):
+ if body.has_key('TemplateBody'):
logger.info('TemplateBody ...')
- return req.params['TemplateBody']
- elif req.params.has_key('TemplateUrl'):
- logger.info('TemplateUrl %s' % req.params['TemplateUrl'])
- url = urlparse.urlparse(req.params['TemplateUrl'])
+ return body['TemplateBody']
+ elif body.has_key('TemplateUrl'):
+ logger.info('TemplateUrl %s' % body['TemplateUrl'])
+ url = urlparse.urlparse(body['TemplateUrl'])
if url.scheme == 'https':
conn = httplib.HTTPSConnection(url.netloc)
else:
return None
- def create(self, req):
+ def create(self, req, body):
"""
Returns the following information for all stacks:
"""
c = engine.get_engine_client(req.context)
try:
- templ = self._get_template(req)
+ templ = self._get_template(body)
except socket.gaierror:
msg = _('Invalid Template URL')
return webob.exc.HTTPBadRequest(explanation=msg)
except ValueError:
msg = _("The Template must be a JSON document.")
return webob.exc.HTTPBadRequest(explanation=msg)
- stack['StackName'] = req.params['StackName']
+ stack['StackName'] = body['StackName']
return c.create_stack(stack, **req.params)
- def validate_template(self, req):
+ def validate_template(self, req, body):
client = engine.get_engine_client(req.context)
try:
- templ = self._get_template(req)
+ templ = self._get_template(body)
except socket.gaierror:
msg = _('Invalid Template URL')
return webob.exc.HTTPBadRequest(explanation=msg)
return data
def create_stack(self, **kwargs):
-
- params = self._extract_params(kwargs, SUPPORTED_PARAMS)
+ body = self._extract_params(kwargs, SUPPORTED_PARAMS)
+ params = {}
self._insert_common_parameters(params)
- res = self.do_request("POST", "/CreateStack", params=params)
+ res = self.do_request("POST", "/CreateStack", params=params, body=body)
data = json.loads(res.read())
return data
def update_stack(self, **kwargs):
- params = self._extract_params(kwargs, SUPPORTED_PARAMS)
+ body = self._extract_params(kwargs, SUPPORTED_PARAMS)
+ 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
return data
def validate_template(self, **kwargs):
- params = self._extract_params(kwargs, SUPPORTED_PARAMS)
+ body = self._extract_params(kwargs, SUPPORTED_PARAMS)
+ params = {}
self._insert_common_parameters(params)
-
- res = self.do_request("GET", "/ValidateTemplate", params=params)
+
+ res = self.do_request("POST", "/ValidateTemplate", params=params,
+ body=body)
data = json.loads(res.read())
return data
import errno
import functools
import httplib
+import json
import logging
import os
import urllib
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)
"""
Validate the template
"""
- headers = {
- 'Content-Type': 'application/json',
- }
-
logger.info(template)
- res = self.do_request("POST", "/validate_template", body=json.dumps(template),
- headers=headers, params=kwargs)
+ res = self.do_request("POST", "/validate_template", template,
+ params=kwargs)
data = json.loads(res.read())
logger.info(data)
return data
"""
Tells engine about an stack's metadata
"""
- headers = {
- 'Content-Type': 'application/json',
- }
-
- res = self.do_request("POST", "/stacks", json.dumps(template),
- headers=headers, params=kwargs)
+ res = self.do_request("POST", "/stacks", template, params=kwargs)
data = json.loads(res.read())
return data
"""
Updates Engine's information about an stack
"""
- headers = {
- 'Content-Type': 'application/json',
- }
-
- res = self.do_request("PUT", "/stacks/%s" % (stack_id), json.dumps(template), headers)
+ res = self.do_request("PUT", "/stacks/%s" % (stack_id), template)
data = json.loads(res.read())
stack = data['stack']
return stack