diff options
author | Xiaohua Zhang <xiaohua.zhang@windriver.com> | 2019-04-08 07:21:30 +0000 |
---|---|---|
committer | Xiaohua Zhang <xiaohua.zhang@windriver.com> | 2019-04-08 07:21:30 +0000 |
commit | 34fe8cbca786d59ccc2550a1f20b4b7d20b3aae7 (patch) | |
tree | 67731896d13cbea643c681a70a3acf61cafa493c /share/newton_base/resource/capacity.py | |
parent | dfad902004f1ff9b86651f10ae5cc13814d954a0 (diff) |
Update API handler for multi-tenant supports
Change-Id: I5c46a71605ed9f5f9e4dfd04b0383c1d5874f3da
Issue-ID: MULTICLOUD-543
Signed-off-by: Xiaohua Zhang <xiaohua.zhang@windriver.com>
Diffstat (limited to 'share/newton_base/resource/capacity.py')
-rw-r--r-- | share/newton_base/resource/capacity.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/share/newton_base/resource/capacity.py b/share/newton_base/resource/capacity.py index c2fee361..a02aa28f 100644 --- a/share/newton_base/resource/capacity.py +++ b/share/newton_base/resource/capacity.py @@ -36,7 +36,10 @@ class CapacityCheck(APIView): self._logger.debug("META> %s" % request.META) try: - hasEnoughResource = self.get_tenant_cap_info(vimid, request.data) + # Get the specified tenant id + specified_project_idorname = request.META.get("Project", None) + + hasEnoughResource = self.get_tenant_cap_info(vimid, request.data, specified_project_idorname) self._logger.info("RESP with data> result:%s" % hasEnoughResource) return Response(data={'result': hasEnoughResource}, status=status.HTTP_200_OK) except VimDriverNewtonException as e: @@ -54,11 +57,34 @@ class CapacityCheck(APIView): return Response(data={'result': False, 'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - def get_tenant_cap_info(self, vimid, resource_demand): + def get_tenant_cap_info(self, vimid, resource_demand, project_idorname=None): hasEnoughResource = False tenant_name = None vim = VimDriverUtils.get_vim_info(vimid) - sess = VimDriverUtils.get_session(vim, tenant_name) + sess = None + if project_idorname: + try: + # check if specified with tenant id + sess = VimDriverUtils.get_session( + vim, tenant_name=None, + tenant_id=project_idorname + ) + except Exception as e: + pass + + if not sess: + try: + # check if specified with tenant name + sess = VimDriverUtils.get_session( + vim, tenant_name=project_idorname, + tenant_id=None + ) + except Exception as e: + pass + + if not sess: + sess = VimDriverUtils.get_session( + vim, tenant_name=tenant_name, tenant_id=None) # get token: # cloud_owner, regionid = extsys.decode_vim_id(vimid) |