From 38f78f4fdf3874ca780f12ab1816650476013d3a Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Mon, 4 Jun 2018 09:57:45 +0800 Subject: Fix registration limitation on tenant discovery Populate the tenant information from token response Change-Id: I52092d2c3021f54b4b6915373f14e4f45547f6d5 Issue-ID: MULTICLOUD-168 Signed-off-by: Yun Huang --- share/newton_base/registration/registration.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/share/newton_base/registration/registration.py b/share/newton_base/registration/registration.py index 67004390..4e536b8b 100644 --- a/share/newton_base/registration/registration.py +++ b/share/newton_base/registration/registration.py @@ -126,7 +126,27 @@ class Registry(APIView): self._logger.error("VimDriverNewtonException: status:%s, response:%s" % (e.http_status, e.content)) return except HttpError as e: - self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) + if e.http_status == status.HTTP_403_FORBIDDEN: + ### get the tenant information from the token response + try: + ### get tenant info from the session + tmp_auth_state = VimDriverUtils.get_auth_state(session) + tmp_auth_info = json.loads(tmp_auth_state) + tmp_auth_data = tmp_auth_info['body'] + tenant = tmp_auth_data['token']['project'] + tenant_info = { + 'tenant-id': tenant['id'], + 'tenant-name': tenant['name'], + } + + self._update_resoure( + cloud_owner, cloud_region_id, tenant['id'], + tenant_info, "tenant") + + except Exception as ex: + self._logger.error(traceback.format_exc()) + else: + self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return except Exception as e: self._logger.error(traceback.format_exc()) -- cgit 1.2.3-korg