Browse Source

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 <shardy@redhat.com>
changes/61/261/2
Steven Hardy 10 years ago
parent
commit
b7eee6c64e
  1. 4
      bin/heat
  2. 9
      heat/api/v1/stacks.py
  3. 55
      heat/engine/manager.py

4
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)

9
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:

55
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

Loading…
Cancel
Save