From 3601fb263c1dfa6cfd2e5a3e18e6d6690e5eb62c Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Fri, 8 Jun 2012 11:35:56 +1000 Subject: [PATCH] Add the GetTemplate API see #1 Change-Id: I178a1d9a19570296b62381548434fb4fcf836fee Signed-off-by: Angus Salkeld --- bin/heat | 14 +++++++++++--- heat/api/v1/__init__.py | 1 + heat/api/v1/stacks.py | 19 +++++++++++++++++++ heat/client.py | 3 +++ heat/engine/manager.py | 14 +++++++++++++- 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/bin/heat b/bin/heat index daad9c7959..bb04840981 100755 --- a/bin/heat +++ b/bin/heat @@ -98,10 +98,18 @@ def template_validate(options, arguments): def get_template(options, arguments): ''' Gets an existing stack template. - - NOT YET IMPLEMENTED. ''' - pass + parameters = {} + try: + parameters['StackName'] = arguments.pop(0) + except IndexError: + logging.error("Please specify the stack you wish to get") + logging.error("as the first argument") + return utils.FAILURE + + c = get_client(options) + result = c.get_template(**parameters) + print json.dumps(result, indent=2) @utils.catch_error('create') diff --git a/heat/api/v1/__init__.py b/heat/api/v1/__init__.py index cc4d94eac4..a8c8727afd 100644 --- a/heat/api/v1/__init__.py +++ b/heat/api/v1/__init__.py @@ -123,6 +123,7 @@ class API(wsgi.Router): 'update': 'UpdateStack', 'events_list': 'DescribeStackEvents', 'validate_template': 'ValidateTemplate', + 'get_template': 'GetTemplate', } def __init__(self, conf, **local_conf): diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 06eeabb815..15b39bb1ee 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -150,6 +150,25 @@ class StackController(object): except rpc_common.RemoteError as ex: return webob.exc.HTTPBadRequest(str(ex)) + def get_template(self, req): + + con = req.context + parms = dict(req.params) + + logger.info('get_template') + try: + templ = rpc.call(con, 'engine', + {'method': 'get_template', + 'args': {'stack_name': req.params['StackName'], + 'params': parms}}) + except rpc_common.RemoteError as ex: + return webob.exc.HTTPBadRequest(str(ex)) + + if templ is None: + return webob.exc.HTTPNotFound('stack not found') + + return {'GetTemplateResult': {'TemplateBody': templ}} + def validate_template(self, req): con = req.context diff --git a/heat/client.py b/heat/client.py index 9d6847e4aa..9530f3d5f6 100644 --- a/heat/client.py +++ b/heat/client.py @@ -67,6 +67,9 @@ class V1Client(base_client.BaseClient): def validate_template(self, **kwargs): return self.stack_request("ValidateTemplate", "GET", **kwargs) + def get_template(self, **kwargs): + return self.stack_request("GetTemplate", "GET", **kwargs) + HeatClient = V1Client diff --git a/heat/engine/manager.py b/heat/engine/manager.py index e220a0fd86..409b37511e 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -14,7 +14,6 @@ # under the License. -import contextlib from copy import deepcopy import datetime import logging @@ -218,6 +217,19 @@ class EngineManager(manager.Manager): return res + def get_template(self, context, stack_name, params): + """ + Get the template. + arg1 -> RPC context. + arg2 -> Name of the stack you want to see. + arg3 -> Dict of http request parameters passed in from API side. + """ + self._authenticate(context) + s = db_api.stack_get(None, stack_name) + if s: + return s.raw_template.template + return None + def delete_stack(self, context, stack_name, params): """ The delete_stack method deletes a given stack.