]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add the GetTemplate API
authorAngus Salkeld <asalkeld@redhat.com>
Fri, 8 Jun 2012 01:35:56 +0000 (11:35 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Fri, 8 Jun 2012 01:37:08 +0000 (11:37 +1000)
see #1

Change-Id: I178a1d9a19570296b62381548434fb4fcf836fee
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
bin/heat
heat/api/v1/__init__.py
heat/api/v1/stacks.py
heat/client.py
heat/engine/manager.py

index daad9c7959e3d599c67ac563762e7143bf8d4592..bb0484098134f549ce661acb5afd37942e6b2df4 100755 (executable)
--- 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')
index cc4d94eac4a7bbf48ee10df0975ee387f44e3101..a8c8727afd5c3b69edccdfc05a4f331b2db7fd0c 100644 (file)
@@ -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):
index 06eeabb81533b0cd8b4c89f832271f02c3c87c0a..15b39bb1ee2f6b0f88f274bc2722434b27a3ed13 100644 (file)
@@ -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
index 9d6847e4aa510dd56d73503ef9e4236d3dfdfdc8..9530f3d5f6f147fb2481d890dc8f804c516ea59f 100644 (file)
@@ -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
 
 
index e220a0fd8643b3e4e8431255c6f26658730274ce..409b37511efe8902c81ace59b0a9e1ceecec45a4 100644 (file)
@@ -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.