From a4090bfb12e86dac68331ddeb15b1b4a3a3fab38 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 18 Jun 2012 17:49:31 +0100 Subject: [PATCH] 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 --- heat/api/v1/stacks.py | 17 ++++++++++++++--- heat/engine/manager.py | 7 +++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 53c4b7bb00..18deaee534 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -49,6 +49,15 @@ class StackController(object): def __init__(self, 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): """ Returns the following information for all stacks: @@ -66,7 +75,7 @@ class StackController(object): summaries = results['StackSummaries'] if stack_list is not None: for s in stack_list['stacks']: - summaries.append(s) + summaries.append(self._stackid_addprefix(s)) return res @@ -89,7 +98,7 @@ class StackController(object): res = {'DescribeStacksResult': {'Stacks': []}} stacks = res['DescribeStacksResult']['Stacks'] for s in stack_list['stacks']: - stacks.append(s) + stacks.append(self._stackid_addprefix(s)) return res @@ -142,7 +151,7 @@ class StackController(object): stack['Timeout'] = req.params['Timeout'] try: - return rpc.call(con, 'engine', + res = rpc.call(con, 'engine', {'method': 'create_stack', 'args': {'stack_name': req.params['StackName'], 'template': stack, @@ -150,6 +159,8 @@ class StackController(object): except rpc_common.RemoteError as ex: return webob.exc.HTTPBadRequest(str(ex)) + return {'CreateStackResult': self._stackid_addprefix(res)} + def get_template(self, req): con = req.context diff --git a/heat/engine/manager.py b/heat/engine/manager.py index fb5d284a28..e0ac497235 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -149,7 +149,7 @@ class EngineManager(manager.Manager): s.raw_template.parsed_template.template, s.id, _extract_user_params(params)) mem = {} - mem['StackId'] = s.id + mem['StackId'] = "/".join([s.name, str(s.id)]) mem['StackName'] = s.name mem['CreationTime'] = heat_utils.strtime(s.created_at) mem['TemplateDescription'] = ps.t.get('Description', @@ -175,7 +175,7 @@ class EngineManager(manager.Manager): s.raw_template.parsed_template.template, s.id, _extract_user_params(params)) mem = {} - mem['StackId'] = s.id + 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) @@ -255,8 +255,7 @@ class EngineManager(manager.Manager): stack.parsed_template_id = new_pt.id greenpool.spawn_n(stack.create) - return {'stack': {'id': new_s.id, 'name': new_s.name, - 'CreationTime': heat_utils.strtime(new_s.created_at)}} + return {'StackId': "/".join([new_s.name, str(new_s.id)])} def validate_template(self, context, template, params): """