From a5ea8a4c558d38592d1ef93857485e4fb1cef884 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 15 Mar 2012 21:22:05 +1100 Subject: [PATCH] Add support for getting the template via url else we get RequestUriTooLong The nutty cloudforms api passes the template in via parameters. TemplateUrl is better. try: ./bin/heat create my_stack --template-url=https://raw.github.com/asalkeld/heat/master/templates/WordPress_Single_Instance.template Signed-off-by: Angus Salkeld --- heat/api/v1/__init__.py | 2 +- heat/api/v1/stacks.py | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/heat/api/v1/__init__.py b/heat/api/v1/__init__.py index d39dd5ae14..8ad3026bd9 100644 --- a/heat/api/v1/__init__.py +++ b/heat/api/v1/__init__.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -SUPPORTED_PARAMS = ('StackName', 'TemplateBody', 'NotificationARNs', 'Parameters', +SUPPORTED_PARAMS = ('StackName', 'TemplateBody', 'TemplateUrl','NotificationARNs', 'Parameters', 'Version', 'SignatureVersion', 'Timestamp', 'AWSAccessKeyId', 'Signature') diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 5145e718b5..3841a8300d 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -21,6 +21,7 @@ import httplib import json import logging import sys +import urlparse import webob from webob.exc import (HTTPNotFound, @@ -91,10 +92,24 @@ class StackController(object): def _get_template(self, req): if req.params.has_key('TemplateBody'): + logger.info('TemplateBody ...') return req.params['TemplateBody'] elif req.params.has_key('TemplateUrl'): - # TODO _do_request() ... - pass + logger.info('TemplateUrl %s' % req.params['TemplateUrl']) + url = urlparse.urlparse(req.params['TemplateUrl']) + if url.scheme == 'https': + conn = httplib.HTTPSConnection(url.netloc) + else: + conn = httplib.HTTPConnection(url.netloc) + conn.request("GET", url.path) + r1 = conn.getresponse() + logger.info('status %d' % r1.status) + if r1.status == 200: + data = r1.read() + conn.close() + else: + data = None + return data return None @@ -111,12 +126,12 @@ class StackController(object): """ if stack_db.has_key(req.params['StackName']): msg = _("Stack already exists with that name.") - return exc.HTTPConflict(msg) + return webob.exc.HTTPConflict(msg) templ = self._get_template(req) if templ is None: msg = _("TemplateBody or TemplateUrl were not given.") - return exc.HTTPBadRequest(explanation=msg) + return webob.exc.HTTPBadRequest(explanation=msg) stack = json.loads(templ) my_id = '%s-%d' % (req.params['StackName'], self.stack_id) @@ -136,7 +151,7 @@ class StackController(object): """ if not stack_db.has_key(req.params['StackName']): msg = _("Stack does not exist with that name.") - return exc.HTTPNotFound(msg) + return webob.exc.HTTPNotFound(msg) stack = stack_db[req.params['StackName']] my_id = stack['StackId']