From b7eee6c64eb88a10b5a3e43985c8c05ceb3fa8ea Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 25 Jun 2012 16:38:51 +0100 Subject: [PATCH] heat API : DescribeStacks return all when no stack name specified 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 --- bin/heat | 4 +-- heat/api/v1/stacks.py | 9 ++++++- heat/engine/manager.py | 55 ++++++++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/bin/heat b/bin/heat index 48e8c19b50..99ca84be0c 100755 --- 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) diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index eed301b7cd..cf94803904 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -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: diff --git a/heat/engine/manager.py b/heat/engine/manager.py index 3ade183eca..e839b9e16c 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -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