heat API : Align response StackId with AWS spec

Revise response format for CreateStack, ListStacks and DescribeStacks
so the StackId element is formatted in a similar way to the AWS spec

Change-Id: I0dd34a6dae2e30c63619449ebbf89643ccc9d364
Signed-off-by: Steven Hardy <shardy@redhat.com>
This commit is contained in:
Steven Hardy 2012-06-18 17:49:31 +01:00
parent d09bad5bef
commit a4090bfb12
2 changed files with 17 additions and 7 deletions

View File

@ -49,6 +49,15 @@ class StackController(object):
def __init__(self, options): def __init__(self, options):
self.options = options self.options = options
# On valid non-error response, we add a host:port:stack prefix
# This formats the StackId in the response more like the AWS spec
def _stackid_addprefix(self, resp):
if 'StackId' in resp:
hostportprefix = ":".join([socket.gethostname(),
str(self.options.bind_port), "stack"])
resp['StackId'] = "/".join([hostportprefix, resp['StackId']])
return resp
def list(self, req): def list(self, req):
""" """
Returns the following information for all stacks: Returns the following information for all stacks:
@ -66,7 +75,7 @@ class StackController(object):
summaries = results['StackSummaries'] summaries = results['StackSummaries']
if stack_list is not None: if stack_list is not None:
for s in stack_list['stacks']: for s in stack_list['stacks']:
summaries.append(s) summaries.append(self._stackid_addprefix(s))
return res return res
@ -89,7 +98,7 @@ class StackController(object):
res = {'DescribeStacksResult': {'Stacks': []}} res = {'DescribeStacksResult': {'Stacks': []}}
stacks = res['DescribeStacksResult']['Stacks'] stacks = res['DescribeStacksResult']['Stacks']
for s in stack_list['stacks']: for s in stack_list['stacks']:
stacks.append(s) stacks.append(self._stackid_addprefix(s))
return res return res
@ -142,7 +151,7 @@ class StackController(object):
stack['Timeout'] = req.params['Timeout'] stack['Timeout'] = req.params['Timeout']
try: try:
return rpc.call(con, 'engine', res = rpc.call(con, 'engine',
{'method': 'create_stack', {'method': 'create_stack',
'args': {'stack_name': req.params['StackName'], 'args': {'stack_name': req.params['StackName'],
'template': stack, 'template': stack,
@ -150,6 +159,8 @@ class StackController(object):
except rpc_common.RemoteError as ex: except rpc_common.RemoteError as ex:
return webob.exc.HTTPBadRequest(str(ex)) return webob.exc.HTTPBadRequest(str(ex))
return {'CreateStackResult': self._stackid_addprefix(res)}
def get_template(self, req): def get_template(self, req):
con = req.context con = req.context

View File

@ -149,7 +149,7 @@ class EngineManager(manager.Manager):
s.raw_template.parsed_template.template, s.raw_template.parsed_template.template,
s.id, _extract_user_params(params)) s.id, _extract_user_params(params))
mem = {} mem = {}
mem['StackId'] = s.id mem['StackId'] = "/".join([s.name, str(s.id)])
mem['StackName'] = s.name mem['StackName'] = s.name
mem['CreationTime'] = heat_utils.strtime(s.created_at) mem['CreationTime'] = heat_utils.strtime(s.created_at)
mem['TemplateDescription'] = ps.t.get('Description', mem['TemplateDescription'] = ps.t.get('Description',
@ -175,7 +175,7 @@ class EngineManager(manager.Manager):
s.raw_template.parsed_template.template, s.raw_template.parsed_template.template,
s.id, _extract_user_params(params)) s.id, _extract_user_params(params))
mem = {} mem = {}
mem['StackId'] = s.id mem['StackId'] = "/".join([s.name, str(s.id)])
mem['StackName'] = s.name mem['StackName'] = s.name
mem['CreationTime'] = heat_utils.strtime(s.created_at) mem['CreationTime'] = heat_utils.strtime(s.created_at)
mem['LastUpdatedTimestamp'] = heat_utils.strtime(s.updated_at) mem['LastUpdatedTimestamp'] = heat_utils.strtime(s.updated_at)
@ -255,8 +255,7 @@ class EngineManager(manager.Manager):
stack.parsed_template_id = new_pt.id stack.parsed_template_id = new_pt.id
greenpool.spawn_n(stack.create) greenpool.spawn_n(stack.create)
return {'stack': {'id': new_s.id, 'name': new_s.name, return {'StackId': "/".join([new_s.name, str(new_s.id)])}
'CreationTime': heat_utils.strtime(new_s.created_at)}}
def validate_template(self, context, template, params): def validate_template(self, context, template, params):
""" """