summaryrefslogtreecommitdiffstats
path: root/windriver
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-12-21 09:39:30 +0000
committerBin Yang <bin.yang@windriver.com>2018-12-21 09:39:30 +0000
commit7994c7757b13e052bffc2c3774b70f0a5ad7da79 (patch)
treee7ebdde0c89c933ed01472e68c6f6faf919fe163 /windriver
parentd76c9be3e8d91675630d8b7772051030e992bf3e (diff)
Workaround region list failure
keystone api v2.0 does not support region list workaround this by using user input parameters Change-Id: I1df695308eda470ed281bc43abbd43e60d3d5713 Issue-ID: MULTICLOUD-429 Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'windriver')
-rw-r--r--windriver/titanium_cloud/registration/views/registration.py69
1 files changed, 42 insertions, 27 deletions
diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py
index 5c29ccb0..17992af7 100644
--- a/windriver/titanium_cloud/registration/views/registration.py
+++ b/windriver/titanium_cloud/registration/views/registration.py
@@ -168,13 +168,15 @@ class APIv1Registry(newton_registration.Registry):
restcall.req_to_aai(resource_url, "GET")
if retcode2 == 0 and content2:
content2 = json.JSONDecoder().decode(content2)
- if content2.get("identity-url", None) == resource_info.get("identity-url", None):
+ if content2.get("identity-url", None)\
+ == resource_info.get("identity-url", None):
break
return retcode
return 1 # unknown cloud owner,region_id
- def _discover_regions(self, cloud_owner="", cloud_region_id="", session=None, viminfo=None):
+ def _discover_regions(self, cloud_owner="", cloud_region_id="",
+ session=None, viminfo=None):
try:
regions = []
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
@@ -202,14 +204,16 @@ class APIv1Registry(newton_registration.Registry):
return regions
except HttpError as e:
- self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
- return
+ self._logger.error("HttpError: status:%s, response:%s"
+ % (e.http_status, e.response.json()))
+ return []
except Exception:
self._logger.error(traceback.format_exc())
- return
+ return []
def post(self, request, cloud_owner="", cloud_region_id=""):
- self._logger.info("registration with : %s, %s" % (cloud_owner, cloud_region_id))
+ self._logger.info("registration with : %s, %s"
+ % (cloud_owner, cloud_region_id))
try:
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
@@ -218,27 +222,27 @@ class APIv1Registry(newton_registration.Registry):
cloud_extra_info_str = viminfo['cloud_extra_info']
cloud_extra_info = None
try:
- cloud_extra_info = json.loads(cloud_extra_info_str) if cloud_extra_info_str else None
+ cloud_extra_info = json.loads(cloud_extra_info_str)\
+ if cloud_extra_info_str else None
except Exception as ex:
logger.error("Can not convert cloud extra info %s %s" % (
str(ex), cloud_extra_info_str))
pass
- region_specified = cloud_extra_info.get("openstack-region-id", None) if cloud_extra_info else None
- multi_region_discovery = cloud_extra_info.get("multi-region-discovery", None) if cloud_extra_info else None
+ region_specified = cloud_extra_info.get(
+ "openstack-region-id", None) if cloud_extra_info else None
+ multi_region_discovery = cloud_extra_info.get(
+ "multi-region-discovery", None) if cloud_extra_info else None
# set the default tenant since there is no tenant info in the VIM yet
sess = VimDriverUtils.get_session(
viminfo, tenant_name=viminfo['tenant'])
- # discover the regions
+ # discover the regions, expect it always returns a list (even empty list)
region_ids = self._discover_regions(cloud_owner, cloud_region_id, sess, viminfo)
if len(region_ids) == 0:
- self._logger.error("_discover_regions, return regions:%s" % (region_ids))
- return Response(
- data={'error': "no region found for cloud region: %s,%s" % (cloud_owner, cloud_region_id)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self._logger.warn("failed to get region id")
# compare the regions with region_specified and then cloud_region_id
if region_specified in region_ids:
@@ -247,31 +251,39 @@ class APIv1Registry(newton_registration.Registry):
region_specified = cloud_region_id
pass
else:
- # assume the first region be the primary region since we have no other way to determine it.
+ # assume the first region be the primary region
+ # since we have no other way to determine it.
region_specified = region_ids.pop(0)
# update cloud region and discover/register resource
if multi_region_discovery:
- # no input for specified cloud region, so discover all cloud region?
+ # no input for specified cloud region,
+ # so discover all cloud region
for regionid in region_ids:
# do not update the specified region here
if region_specified == regionid:
continue
- # create cloud region with composed AAI cloud_region_id except for the one onboarded externally (e.g. ESR)
+ # create cloud region with composed AAI cloud_region_id
+ # except for the one onboarded externally (e.g. ESR)
gen_cloud_region_id = cloud_region_id + "_" + regionid
- self._logger.info("create a cloud region: %s,%s,%s" % (cloud_owner, gen_cloud_region_id, regionid))
+ self._logger.info("create a cloud region: %s,%s,%s"
+ % (cloud_owner, gen_cloud_region_id, regionid))
- self._update_cloud_region(cloud_owner, gen_cloud_region_id, regionid, viminfo)
- new_vimid = extsys.encode_vim_id(cloud_owner, gen_cloud_region_id)
+ self._update_cloud_region(
+ cloud_owner, gen_cloud_region_id, regionid, viminfo)
+ new_vimid = extsys.encode_vim_id(
+ cloud_owner, gen_cloud_region_id)
super(APIv1Registry, self).post(request, new_vimid)
# update the specified region
- self._update_cloud_region(cloud_owner, cloud_region_id, region_specified, viminfo)
+ self._update_cloud_region(cloud_owner, cloud_region_id,
+ region_specified, viminfo)
return super(APIv1Registry, self).post(request, vimid)
except HttpError as e:
- self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
+ self._logger.error("HttpError: status:%s, response:%s"
+ % (e.http_status, e.response.json()))
return Response(data=e.response.json(), status=e.http_status)
except Exception as e:
self._logger.error(traceback.format_exc())
@@ -280,7 +292,8 @@ class APIv1Registry(newton_registration.Registry):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, cloud_owner="", cloud_region_id=""):
- self._logger.debug("unregister cloud region: %s, %s" % (cloud_owner, cloud_region_id))
+ self._logger.debug("unregister cloud region: %s, %s"
+ % (cloud_owner, cloud_region_id))
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1Registry, self).delete(request, vimid)
@@ -295,13 +308,15 @@ class APIv0Registry(APIv1Registry):
# self._logger = logger
def post(self, request, vimid=""):
- self._logger.info("registration with : %s" % (vimid))
+ self._logger.info("registration with : %s" % vimid)
cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
- return super(APIv0Registry, self).post(request, cloud_owner, cloud_region_id)
+ return super(APIv0Registry, self).post(
+ request, cloud_owner, cloud_region_id)
def delete(self, request, vimid=""):
- self._logger.debug("unregister cloud region: %s" % (vimid))
+ self._logger.debug("unregister cloud region: %s" % vimid)
cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
- return super(APIv0Registry, self).delete(request, cloud_owner, cloud_region_id)
+ return super(APIv0Registry, self).delete(
+ request, cloud_owner, cloud_region_id)