From 14132a2c06bc6b6431f5be90cecf303132d94103 Mon Sep 17 00:00:00 2001 From: Xiaohua Zhang Date: Tue, 9 Apr 2019 10:30:44 +0000 Subject: Fix bugs for infra_workload APIs Change-Id: Ieda8b2f7f68911bc348613cf7b18b40ea800b1e2 Issue-ID: MULTICLOUD-541 Signed-off-by: Xiaohua Zhang --- share/newton_base/resource/infra_workload.py | 6 +-- .../newton_base/resource/infra_workload_helper.py | 56 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) (limited to 'share/newton_base/resource') diff --git a/share/newton_base/resource/infra_workload.py b/share/newton_base/resource/infra_workload.py index 7bf07952..db216ce2 100644 --- a/share/newton_base/resource/infra_workload.py +++ b/share/newton_base/resource/infra_workload.py @@ -36,7 +36,7 @@ class InfraWorkload(APIView): def __init__(self): self._logger = logger - def post(self, request, vimid=""): + def post(self, request, vimid="", requri=""): self._logger.info("vimid: %s" % (vimid)) self._logger.info("data: %s" % (request.data)) self._logger.debug("META: %s" % request.META) @@ -529,13 +529,13 @@ class APIv1InfraWorkload(InfraWorkload): super(APIv1InfraWorkload, self).__init__() # self._logger = logger - def post(self, request, cloud_owner="", cloud_region_id=""): + def post(self, request, cloud_owner="", cloud_region_id="", requri=""): # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % # (cloud_owner, cloud_region_id, request.data)) # self._logger.debug("META: %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) - return super(APIv1InfraWorkload, self).post(request, vimid) + return super(APIv1InfraWorkload, self).post(request, vimid, requri) def get(self, request, cloud_owner="", cloud_region_id="", requri=""): # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % diff --git a/share/newton_base/resource/infra_workload_helper.py b/share/newton_base/resource/infra_workload_helper.py index bfc3fc86..ee8291b1 100644 --- a/share/newton_base/resource/infra_workload_helper.py +++ b/share/newton_base/resource/infra_workload_helper.py @@ -420,9 +420,9 @@ class InfraWorkloadHelper(object): # get stack status service_type = "orchestration" - resource_uri = "/stacks?id=%s" % stack_id if stack_id else "/stacks" + resource_uri = "/stacks/id=%s" % stack_id if stack_id else "/stacks" if stack_name: - resource_uri = "/stacks?name=%s" % stack_id if not stack_id else resource_uri + resource_uri = "/stacks?name=%s" % stack_name if not stack_id else resource_uri self._logger.info("retrieve stack resources, URI:%s" % resource_uri) retcode, content, os_status = \ @@ -443,3 +443,55 @@ class InfraWorkloadHelper(object): except Exception as e: self._logger.error(e.message) return 12, "GET_FAILED", e.message + + + def workload_detail(self, vimid, stack_id, nexturi=None, otherinfo=None, project_idorname=None): + ''' + get workload status by either stack id or name + :param vimid: + :param stack_id: + :param nexturi: stacks// + :param otherinfo: + :return: + ''' + try: + # assume the workload_type is heat + cloud_owner, regionid = extsys.decode_vim_id(vimid) + # should go via multicloud proxy so that the selflink is updated by multicloud + retcode, v2_token_resp_json, os_status = \ + helper.MultiCloudIdentityHelper( + settings.MULTICLOUD_API_V1_PREFIX, + cloud_owner, regionid, "/v2.0/tokens", + {"Project": project_idorname}) + + if retcode > 0 or not v2_token_resp_json: + errmsg = "authenticate fails:%s, %s, %s" % \ + (cloud_owner, regionid, v2_token_resp_json) + logger.error(errmsg) + return retcode, "GET_FAILED", errmsg + + # get stack status + service_type = "orchestration" + resource_uri = "/stacks/%s" % stack_id + if nexturi: + resource_uri += "/" + nexturi + + self._logger.info("retrieve stack resources, URI:%s" % resource_uri) + retcode, content, os_status = \ + helper.MultiCloudServiceHelper(cloud_owner, regionid, + v2_token_resp_json, + service_type, resource_uri, + None, "GET") + + if retcode > 0 or not content: + errmsg = "Stack query %s response: %s" % (resource_uri, content) + self._logger.debug(errmsg) + return retcode, "GET_FAILED", errmsg + + stack = content.get('stack', {}) # if retcode == 0 and content else [] + stack_status = stack.get("stack_status", "GET_FAILED") + + return retcode, stack_status, content + except Exception as e: + self._logger.error(e.message) + return 12, "GET_FAILED", e.message -- cgit 1.2.3-korg