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/proxy | |
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/proxy')
-rw-r--r-- | share/newton_base/proxy/identityV3.py | 28 | ||||
-rw-r--r-- | share/newton_base/proxy/services.py | 29 |
2 files changed, 53 insertions, 4 deletions
diff --git a/share/newton_base/proxy/identityV3.py b/share/newton_base/proxy/identityV3.py index 302c5b07..5d502831 100644 --- a/share/newton_base/proxy/identityV3.py +++ b/share/newton_base/proxy/identityV3.py @@ -90,11 +90,35 @@ class Tokens(APIView): else: tenant_id = request.data["auth"]["scope"]["project"].get("id") - + # Get the specified tenant id + specified_project_idorname = request.META.get("Project", None) # prepare request resource to vim instance vim = VimDriverUtils.get_vim_info(vimid) - sess = VimDriverUtils.get_session(vim, tenant_name = tenant_name, tenant_id=tenant_id) + sess = None + if specified_project_idorname: + try: + # check if specified with tenant id + sess = VimDriverUtils.get_session( + vim, tenant_name=None, + tenant_id=specified_project_idorname + ) + except Exception as e: + pass + + if not sess: + try: + # check if specified with tenant name + sess = VimDriverUtils.get_session( + vim, tenant_name=specified_project_idorname, + tenant_id=None + ) + except Exception as e: + pass + + if not sess: + sess = VimDriverUtils.get_session( + vim, tenant_name=tenant_name, tenant_id=tenant_id) #tmp_auth_state = VimDriverUtils.get_auth_state(vim, sess) tmp_auth_state = VimDriverUtils.get_auth_state(sess) diff --git a/share/newton_base/proxy/services.py b/share/newton_base/proxy/services.py index 631ee359..343750c6 100644 --- a/share/newton_base/proxy/services.py +++ b/share/newton_base/proxy/services.py @@ -268,9 +268,34 @@ class GetTenants(Services): return Response(headers={'X-Subject-Token': tmp_auth_token}, data={'tenants': content['projects'],'tenants_links':[]}, status=resp.status_code) else: + # Get the specified tenant id + specified_project_idorname = request.META.get("Project", None) + viminfo = VimDriverUtils.get_vim_info(vimid) - session = VimDriverUtils.get_session( - viminfo, tenant_name=viminfo['tenant']) + session = None + if specified_project_idorname: + try: + # check if specified with tenant id + session = VimDriverUtils.get_session( + viminfo, tenant_name=None, + tenant_id=specified_project_idorname + ) + except Exception as e: + pass + + if not sess: + try: + # check if specified with tenant name + session = VimDriverUtils.get_session( + viminfo, tenant_name=specified_project_idorname, + tenant_id=None + ) + except Exception as e: + pass + + if not session: + session = VimDriverUtils.get_session( + viminfo, tenant_name=viminfo['tenant']) tmp_auth_state = VimDriverUtils.get_auth_state(session) tmp_auth_info = json.loads(tmp_auth_state) tmp_auth_data = tmp_auth_info['body'] |