diff options
author | Xiaohua Zhang <xiaohua.zhang@windriver.com> | 2019-04-09 10:30:44 +0000 |
---|---|---|
committer | Xiaohua Zhang <xiaohua.zhang@windriver.com> | 2019-04-09 10:30:44 +0000 |
commit | 14132a2c06bc6b6431f5be90cecf303132d94103 (patch) | |
tree | 1c914fa84e52cde8937e356156f16be9e14744c1 /share/newton_base | |
parent | 5dc8f722d834229c27aab4ae2e8a609db09edb0d (diff) |
Fix bugs for infra_workload APIs
Change-Id: Ieda8b2f7f68911bc348613cf7b18b40ea800b1e2
Issue-ID: MULTICLOUD-541
Signed-off-by: Xiaohua Zhang <xiaohua.zhang@windriver.com>
Diffstat (limited to 'share/newton_base')
-rw-r--r-- | share/newton_base/registration/registration.py | 5 | ||||
-rw-r--r-- | share/newton_base/resource/infra_workload.py | 6 | ||||
-rw-r--r-- | share/newton_base/resource/infra_workload_helper.py | 56 |
3 files changed, 59 insertions, 8 deletions
diff --git a/share/newton_base/registration/registration.py b/share/newton_base/registration/registration.py index 550c394e..a875cd84 100644 --- a/share/newton_base/registration/registration.py +++ b/share/newton_base/registration/registration.py @@ -64,8 +64,7 @@ class Registry(APIView): backlog_item = { "id": vimid, "worker": self.register_helper.registryV0, - "payload": (self.register_helper, - vimid, specified_project_idorname), + "payload": (vimid, specified_project_idorname), "repeat": 0, "status": (1, "The registration process waits to" @@ -120,7 +119,7 @@ class Registry(APIView): backlog_item = { "id": vimid, "worker": self.register_helper.unregistryV0, - "payload": (self.register_helper, vimid), + "payload": (vimid), "repeat": 0, "status": (1, "The registration process waits" " to be scheduled to run") 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/<stack id>/<nexturi> + :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 |