]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add a list_stacks RPC call.
authorSteve Baker <sbaker@redhat.com>
Thu, 8 Nov 2012 19:43:23 +0000 (08:43 +1300)
committerSteve Baker <sbaker@redhat.com>
Thu, 8 Nov 2012 20:49:35 +0000 (09:49 +1300)
This differs from the old show_stack(None) by not resolving stack data.

heat list does not display any of the resolved stack data. Resolving outputs
can be especially slow since FnGetAtt may block while it calls out
to another service (such as with the quantum resources).

Without this change, running heat list on a single Quantum.template takes 1.8s
vs 0.7s.

In the future, list_stacks can be made to support paging of results.

Change-Id: Iae30338b66912d660f1cf48119893b1ab593b67a

heat/api/cfn/v1/stacks.py
heat/api/openstack/v1/stacks.py
heat/engine/parser.py
heat/engine/rpcapi.py
heat/engine/service.py

index 7c18f541815536299d098352b0e12db1980dbb22..42f33173805a8400f480c9b0153bda0f7118b20d 100644 (file)
@@ -125,9 +125,7 @@ class StackController(object):
         parms = dict(req.params)
 
         try:
-            # Note show_stack returns details for all stacks when called with
-            # no stack_name, we only use a subset of the result here though
-            stack_list = self.engine_rpcapi.show_stack(con, None)
+            stack_list = self.engine_rpcapi.list_stacks(con)
         except rpc_common.RemoteError as ex:
             return exception.map_remote_error(ex)
 
index d32ccf83e54aca7ed32425037617bd64069adf3b..7091a6d7208b97f2190ff87f9fb9832c2ea5f27d 100644 (file)
@@ -229,9 +229,7 @@ class StackController(object):
         """
 
         try:
-            # Note show_stack returns details for all stacks when called with
-            # no stack_name, we only use a subset of the result here though
-            stack_list = self.engine_rpcapi.show_stack(req.context, None)
+            stack_list = self.engine_rpcapi.list_stacks(req.context)
         except rpc_common.RemoteError as ex:
             return self._remote_error(ex, True)
 
index fc40a032a4e42f6458786975dcee049c1f2183ac..c0ea0008f83d1a7b4bcbcdbafcf543f02dc9ff6c 100644 (file)
@@ -54,7 +54,7 @@ class Stack(object):
 
     def __init__(self, context, stack_name, tmpl, parameters=None,
                  stack_id=None, state=None, state_description='',
-                 timeout_mins=60):
+                 timeout_mins=60, resolve_data=True):
         '''
         Initialise from a context, name, Template object and (optionally)
         Parameters object. The database ID may also be initialised, if the
@@ -73,7 +73,10 @@ class Stack(object):
             parameters = Parameters(self.name, self.t)
         self.parameters = parameters
 
-        self.outputs = self.resolve_static_data(self.t[template.OUTPUTS])
+        if resolve_data:
+            self.outputs = self.resolve_static_data(self.t[template.OUTPUTS])
+        else:
+            self.outputs = {}
 
         template_resources = self.t[template.RESOURCES]
         self.resources = dict((name,
@@ -92,7 +95,7 @@ class Stack(object):
         return deps
 
     @classmethod
-    def load(cls, context, stack_id):
+    def load(cls, context, stack_id, resolve_data=True):
         '''Retrieve a Stack from the database'''
         s = db_api.stack_get(context, stack_id)
         if s is None:
@@ -102,7 +105,8 @@ class Stack(object):
         template = Template.load(context, s.raw_template_id)
         params = Parameters(s.name, template, s.parameters)
         stack = cls(context, s.name, template, params,
-                    stack_id, s.status, s.status_reason, s.timeout)
+                    stack_id, s.status, s.status_reason, s.timeout,
+                    resolve_data)
 
         return stack
 
index ce409f4cd2dc1ff9b55ba838ebe7d210381ebd6e..873aef811e6f7cfb64968b20718331d910ed5d57 100644 (file)
@@ -70,6 +70,15 @@ class EngineAPI(heat.openstack.common.rpc.proxy.RpcProxy):
                                              stack_name=stack_name),
                          topic=_engine_topic(self.topic, ctxt, None))
 
+    def list_stacks(self, ctxt):
+        """
+        The list_stacks method returns the attributes of all stacks.
+
+        :param ctxt: RPC context.
+        """
+        return self.call(ctxt, self.make_msg('list_stacks'),
+                         topic=_engine_topic(self.topic, ctxt, None))
+
     def show_stack(self, ctxt, stack_identity):
         """
         The show_stack method returns the attributes of one stack.
@@ -77,7 +86,6 @@ class EngineAPI(heat.openstack.common.rpc.proxy.RpcProxy):
         :param ctxt: RPC context.
         :param stack_identity: Name of the stack you want to see,
                            or None to see all
-        :param params: Dict of http request parameters passed in from API side.
         """
         return self.call(ctxt, self.make_msg('show_stack',
                                              stack_identity=stack_identity),
index 36872edb74999de0cc8a572f50c2c10e773d61bc..b7d754602f33003dc7da7c0a289ec686ba403eef 100644 (file)
@@ -94,12 +94,12 @@ class EngineService(service.Service):
         """
         The show_stack method returns the attributes of one stack.
         arg1 -> RPC context.
-        arg2 -> Name of the stack you want to see, or None to see all
+        arg2 -> Name of the stack you want to see
         """
-        if stack_identity is not None:
-            stacks = [self._get_stack(context, stack_identity)]
-        else:
-            stacks = db_api.stack_get_by_tenant(context) or []
+        if stack_identity is None:
+            raise AttributeError('No stack_identity provided')
+
+        stacks = [self._get_stack(context, stack_identity)]
 
         def format_stack_detail(s):
             stack = parser.Stack.load(context, s.id)
@@ -107,6 +107,19 @@ class EngineService(service.Service):
 
         return {'stacks': [format_stack_detail(s) for s in stacks]}
 
+    def list_stacks(self, context):
+        """
+        The list_stacks method returns attributes of all stacks.
+        arg1 -> RPC context.
+        """
+        stacks = db_api.stack_get_by_tenant(context) or []
+
+        def format_stack_detail(s):
+            stack = parser.Stack.load(context, s.id, resolve_data=False)
+            return api.format_stack(stack)
+
+        return {'stacks': [format_stack_detail(s) for s in stacks]}
+
     def create_stack(self, context, stack_name, template, params, args):
         """
         The create_stack method creates a new stack using the template