Fix registration limitation on tenant discovery 77/50077/1
authorYun Huang <yun.huang@windriver.com>
Mon, 4 Jun 2018 01:57:45 +0000 (09:57 +0800)
committerYun Huang <yun.huang@windriver.com>
Mon, 4 Jun 2018 02:02:40 +0000 (10:02 +0800)
Populate the tenant information from token response

Change-Id: I52092d2c3021f54b4b6915373f14e4f45547f6d5
Issue-ID: MULTICLOUD-168
Signed-off-by: Yun Huang <yun.huang@windriver.com>
share/newton_base/registration/registration.py

index 6700439..4e536b8 100644 (file)
@@ -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())