]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat API : DescribeStacks return all when no stack name specified
authorSteven Hardy <shardy@redhat.com>
Mon, 25 Jun 2012 15:38:51 +0000 (16:38 +0100)
committerSteven Hardy <shardy@redhat.com>
Fri, 29 Jun 2012 08:34:30 +0000 (09:34 +0100)
The AWS DescribeStacks API documentation says if no stack name specified,
we should return results for all stacks created.
fixes #142

Change-Id: I3d17fef7f1b660bf399e8ff82ff39ca2b2d6f046
Signed-off-by: Steven Hardy <shardy@redhat.com>
bin/heat
heat/api/v1/stacks.py
heat/engine/manager.py

index 48e8c19b50d657897749eacdba6bfa8922d45096..99ca84be0c41151b92b9ba344f55c8eabc7719a7 100755 (executable)
--- a/bin/heat
+++ b/bin/heat
@@ -270,9 +270,7 @@ def stack_describe(options, arguments):
     try:
         parameters['StackName'] = arguments.pop(0)
     except IndexError:
-        logging.error("Please specify the stack name you wish to describe")
-        logging.error("as the first argument")
-        return utils.FAILURE
+        logging.info("No stack name passed, getting results for ALL stacks")
 
     c = get_client(options)
     result = c.describe_stacks(**parameters)
index eed301b7cd45e7b0f713f295b05e3675698304e8..cf948039047cfab537e4fbe2fb14b5d15a71db12 100644 (file)
@@ -86,10 +86,17 @@ class StackController(object):
         con = req.context
         parms = dict(req.params)
 
+        # If no StackName parameter is passed, we pass None into the engine
+        # this returns results for all stacks (visible to this user), which
+        # is the behavior described in the AWS DescribeStacks API docs
+        stack_name = None
+        if 'StackName' in req.params:
+            stack_name = req.params['StackName']
+
         try:
             stack_list = rpc.call(con, 'engine',
                               {'method': 'show_stack',
-                               'args': {'stack_name': req.params['StackName'],
+                               'args': {'stack_name': stack_name,
                                 'params': parms}})
 
         except rpc_common.RemoteError as ex:
index 3ade183eca77b2c6032baa4081a0c31b530661bc..e839b9e16cfc82990d916d3f8fd22693c277cc06 100644 (file)
@@ -123,34 +123,47 @@ class EngineManager(manager.Manager):
         """
         The show_stack method returns the attributes of one stack.
         arg1 -> RPC context.
-        arg2 -> Name of the stack you want to see.
+        arg2 -> Name of the stack you want to see, or None to see all
         arg3 -> Dict of http request parameters passed in from API side.
         """
         auth.authenticate(context)
 
         res = {'stacks': []}
-        s = db_api.stack_get_by_name(context, stack_name)
-        if s:
-            ps = parser.Stack(context, s.name,
-                              s.raw_template.parsed_template.template,
-                              s.id, _extract_user_params(params))
-            mem = {}
-            mem['StackId'] = "/".join([s.name, str(s.id)])
-            mem['StackName'] = s.name
-            mem['CreationTime'] = heat_utils.strtime(s.created_at)
-            mem['LastUpdatedTimestamp'] = heat_utils.strtime(s.updated_at)
-            mem['NotificationARNs'] = 'TODO'
-            mem['Parameters'] = ps.t['Parameters']
-            mem['Description'] = ps.t.get('Description',
-                                          'No description')
-            mem['StackStatus'] = s.status
-            mem['StackStatusReason'] = s.status_reason
+        stacks = []
+        if not stack_name:
+            stacks = [s.name for s in db_api.stack_get_by_user(context)]
+            logging.debug("No stack name passed, got %s" % stacks)
+        else:
+            stacks = [stack_name]
 
-            # only show the outputs on a completely created stack
-            if s.status == ps.CREATE_COMPLETE:
-                mem['Outputs'] = ps.get_outputs()
+        if not stacks:
+            logging.debug("No stacks found to process")
+            return res
 
-            res['stacks'].append(mem)
+        for stack in stacks:
+            logging.debug("Processing show_stack for %s" % stack)
+            s = db_api.stack_get_by_name(context, stack)
+            if s:
+                ps = parser.Stack(context, s.name,
+                                  s.raw_template.parsed_template.template,
+                                  s.id, _extract_user_params(params))
+                mem = {}
+                mem['StackId'] = "/".join([s.name, str(s.id)])
+                mem['StackName'] = s.name
+                mem['CreationTime'] = heat_utils.strtime(s.created_at)
+                mem['LastUpdatedTimestamp'] = heat_utils.strtime(s.updated_at)
+                mem['NotificationARNs'] = 'TODO'
+                mem['Parameters'] = ps.t['Parameters']
+                mem['Description'] = ps.t.get('Description',
+                                              'No description')
+                mem['StackStatus'] = s.status
+                mem['StackStatusReason'] = s.status_reason
+
+                # only show the outputs on a completely created stack
+                if s.status == ps.CREATE_COMPLETE:
+                    mem['Outputs'] = ps.get_outputs()
+
+                res['stacks'].append(mem)
 
         return res