multi-region discovery 15/60715/4
authorBin Yang <bin.yang@windriver.com>
Thu, 16 Aug 2018 04:32:18 +0000 (04:32 +0000)
committerBin Yang <bin.yang@windriver.com>
Fri, 17 Aug 2018 06:21:56 +0000 (06:21 +0000)
Decouple the openstack region id from cloud-region-id

Change-Id: If4bfacf05d87ca4bc97a485d4153f4f379ad451a
Issue-ID: MULTICLOUD-311
Signed-off-by: Bin Yang <bin.yang@windriver.com>
22 files changed:
newton/newton/resource/views/capacity.py
newton/newton/resource/views/events.py
ocata/ocata/resource/views/capacity.py
ocata/ocata/resource/views/events.py
share/common/msapi/extsys.py
share/newton_base/openoapi/flavor.py
share/newton_base/openoapi/hosts.py
share/newton_base/openoapi/hypervisor.py
share/newton_base/openoapi/image.py
share/newton_base/openoapi/limits.py
share/newton_base/openoapi/network.py
share/newton_base/openoapi/server.py
share/newton_base/openoapi/subnet.py
share/newton_base/openoapi/tenants.py
share/newton_base/openoapi/volume.py
share/newton_base/openoapi/vport.py
share/newton_base/proxy/dnsaasdelegate.py
share/newton_base/proxy/services.py
share/newton_base/registration/registration.py
windriver/titanium_cloud/registration/views/registration.py
windriver/titanium_cloud/resource/views/capacity.py
windriver/titanium_cloud/resource/views/events.py

index 973bc98..c9d465e 100644 (file)
@@ -45,23 +45,26 @@ class CapacityCheck(APIView):
         try :
             resource_demand = request.data
 
+            tenant_name = None
+            vim = VimDriverUtils.get_vim_info(vimid)
+            sess = VimDriverUtils.get_session(vim, tenant_name)
+
             #get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
-                       'region_id': regionid}
-
-            tenant_name = None
-            vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenant_name)
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']
+                       }
 
             #get limit for this tenant
             req_resouce = "/limits"
             resp = sess.get(req_resouce, endpoint_filter=service)
             content = resp.json()
             compute_limits = content['limits']['absolute']
-        
             #get total resource of this cloud region
             try:
                 req_resouce = "/os-hypervisors/statistics"
index bf7de34..1f06c78 100644 (file)
@@ -44,16 +44,19 @@ class EventsCheck(APIView):
         try :
             resource_demand = request.data
 
+            tenant_name = None
+            vim = VimDriverUtils.get_vim_info(vimid)
+            sess = VimDriverUtils.get_session(vim, tenant_name)
+
             # get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
-                       'region_id': regionid}
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']}
 
-            tenant_name = None
-            vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenant_name)
 
             # get servers detail info
             req_resouce = "/servers/detail"
index 37c920e..b1f3191 100644 (file)
@@ -45,16 +45,19 @@ class CapacityCheck(APIView):
         try :
             resource_demand = request.data
 
+            tenant_name = None
+            vim = VimDriverUtils.get_vim_info(vimid)
+            sess = VimDriverUtils.get_session(vim, tenant_name)
+
             #get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
-                       'region_id': regionid}
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']}
 
-            tenant_name = None
-            vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenant_name)
 
             #get limit for this tenant
             req_resouce = "/limits"
index 3cfdad4..4b477a7 100644 (file)
@@ -44,16 +44,19 @@ class EventsCheck(APIView):
         try :
             resource_demand = request.data
 
+            tenant_name = None
+            vim = VimDriverUtils.get_vim_info(vimid)
+            sess = VimDriverUtils.get_session(vim, tenant_name)
+
             # get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
-                       'region_id': regionid}
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']}
 
-            tenant_name = None
-            vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenant_name)
 
             # get servers detail info
             req_resouce = "/servers/detail"
index c0cc7f2..e153452 100644 (file)
@@ -70,6 +70,9 @@ def get_vim_by_id(vim_id):
             viminfo['tenant'] = tmp_authinfo.get('default-tenant')
             viminfo['cacert'] = tmp_authinfo.get('ssl-cacert')
             viminfo['insecure'] = tmp_authinfo.get('ssl-insecure')
+            viminfo["complex-name"] = tmp_viminfo.get("complex-name")
+            viminfo['openstack_region_id'] = tmp_viminfo.get("cloud-epa-caps") \
+                if tmp_viminfo.get("cloud-epa-caps") else cloud_region_id
 
             return viminfo
     return None
index af811f6..18a1398 100644 (file)
@@ -63,6 +63,11 @@ class Flavors(APIView):
 
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             resp = self._get_flavor(sess, request, flavorid)
             content = resp.json()
 
@@ -187,6 +192,10 @@ class Flavors(APIView):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             #check if the flavor is already created: name or id
             tmpresp = self._get_flavor(sess, request)
             content = tmpresp.json()
@@ -329,6 +338,10 @@ class Flavors(APIView):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             #delete extra specs one by one
             resp = self._delete_flavor_extra_specs(sess, flavorid)
 
index d93336a..7a311b3 100644 (file)
@@ -52,6 +52,10 @@ class Hosts(APIView):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.get(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index eb0debd..bfde0f5 100755 (executable)
@@ -72,7 +72,11 @@ class Hypervisors(APIView):
         vim["domain"] = "Default"\r
         sess = VimDriverUtils.get_session(vim, tenantid)\r
 \r
-        logger.info("making request with URI:%s" % req_resource)\r
+        self.service['region_id'] = vim['openstack_region_id'] \\r
+            if vim.get('openstack_region_id') \\r
+            else vim['cloud_region_id']\r
+\r
+        logger.info("making request with URI:%s" % req_resouce)\r
 \r
         resp = sess.get(req_resource, endpoint_filter = self.service)\r
 \r
index e27d019..8561527 100644 (file)
@@ -58,6 +58,10 @@ class imageThread (threading.Thread):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id']\
+                           if vim.get('openstack_region_id')\
+                           else vim['cloud_region_id']
+
             #open imageurl
             logger.info("making image put request with URI:%s" % req_resouce)
             resp = sess.put(req_resouce, endpoint_filter=self.service, data=imagefd.read(),
@@ -113,6 +117,10 @@ class Images(APIView):
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
 
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         logger.info("making request with URI:%s" % req_resouce)
         resp = sess.get(req_resouce, endpoint_filter=self.service)
         logger.info("request returns with status %s" % resp.status_code)
@@ -186,6 +194,10 @@ class Images(APIView):
             #req_body = json.JSONEncoder().encode({"image": image})
             req_body = json.JSONEncoder().encode(image)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             logger.debug("with data:%s" % req_body)
             resp = sess.post(req_resouce, data=req_body,
@@ -239,6 +251,10 @@ class Images(APIView):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.delete(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index fad710f..d260ab7 100644 (file)
@@ -48,6 +48,11 @@ class Limits(APIView):
             req_resouce = "/limits"
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.get(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
@@ -66,6 +71,11 @@ class Limits(APIView):
             #now get quota
             # prepare request resource to vim instance
             req_resouce = "/v2.0/quotas/%s" % tenantid
+
+            self.service_network['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.get(req_resouce, endpoint_filter=self.service_network)
             logger.info("request returns with status %s" % resp.status_code)
@@ -75,6 +85,11 @@ class Limits(APIView):
             #now get volume limits
             # prepare request resource to vim instance
             req_resouce = "/limits"
+
+            self.service_volume['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.get(req_resouce, endpoint_filter=self.service_volume)
             logger.info("request returns with status %s" % resp.status_code)
index 9ad7a83..9475ee2 100644 (file)
@@ -73,6 +73,11 @@ class Networks(APIView):
 
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
+
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         logger.info("making request with URI:%s" % req_resouce)
         resp = sess.get(req_resouce, endpoint_filter=self.service)
         logger.info("request returns with status %s" % resp.status_code)
@@ -135,6 +140,10 @@ class Networks(APIView):
                                                   self.keys_mapping, True)
             req_body = json.JSONEncoder().encode({"network": network})
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             logger.debug("with data:%s" % req_body)
             resp = sess.post(req_resouce, data=req_body,
@@ -178,6 +187,10 @@ class Networks(APIView):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making delete request with URI:%s" % req_resouce)
             resp = sess.delete(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index c5011f1..3e90bf8 100644 (file)
@@ -63,6 +63,10 @@ class ServerVolumeAttachThread (threading.Thread):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             #check if server is ready to attach
             logger.debug("Servers--attach_volume, wait for server to be ACTIVE::>%s" % serverid)
             req_resouce = "servers/%s" % serverid
@@ -109,6 +113,10 @@ class ServerVolumeAttachThread (threading.Thread):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             #wait server to be ready to detach volume
 
             # assume attachment id is the same as volume id
@@ -159,6 +167,10 @@ class Servers(APIView):
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
 
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         for volumeid in volumeIds:
             req_resouce = "servers/%s/os-volume_attachments/%s" % (serverId, volumeid)
             logger.debug("Servers--dettachVolume::>%s" % (req_resouce))
@@ -234,6 +246,11 @@ class Servers(APIView):
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
         req_resouce = "servers/%s/os-interface" % serverid
+
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         logger.info("making request with URI:%s" % req_resouce)
         resp = sess.get(req_resouce, endpoint_filter=self.service)
         logger.info("request returns with status %s" % resp.status_code)
@@ -258,6 +275,11 @@ class Servers(APIView):
 
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
+
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         logger.info("making request with URI:%s" % req_resouce)
         resp = sess.get(req_resouce, endpoint_filter=self.service)
         logger.info("request returns with status %s" % resp.status_code)
@@ -392,6 +414,11 @@ class Servers(APIView):
 
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.post(req_resouce, data=req_body,
                              endpoint_filter=self.service,
@@ -450,6 +477,10 @@ class Servers(APIView):
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
 
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             #check and dettach them if volumes attached to server
             server, status_code = self._get_servers("", vimid, tenantid, serverid)
             volumearray = server.pop("volumeArray", None)
index 9ff61f2..1d4f761 100644 (file)
@@ -75,6 +75,11 @@ class Subnets(APIView):
 
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
+
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         logger.info("making request with URI:%s" % req_resouce)
         resp = sess.get(req_resouce, endpoint_filter=self.service)
         logger.info("request returns with status %s" % resp.status_code)
@@ -136,6 +141,11 @@ class Subnets(APIView):
             VimDriverUtils.replace_key_by_mapping(subnet,
                                                   self.keys_mapping, True)
             req_body = json.JSONEncoder().encode({"subnet": subnet})
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             logger.debug("with data:%s" % req_body)
             resp = sess.post(req_resouce, data=req_body,
@@ -180,6 +190,11 @@ class Subnets(APIView):
 
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.delete(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index 76fd213..a8b9746 100644 (file)
@@ -52,6 +52,11 @@ class Tenants(APIView):
                 req_resouce = "/v2.0/tenants"
 
             sess = VimDriverUtils.get_session(vim)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.get(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index 827baea..100d239 100644 (file)
@@ -76,6 +76,11 @@ class Volumes(APIView):
 
         vim = VimDriverUtils.get_vim_info(vimid)
         sess = VimDriverUtils.get_session(vim, tenantid)
+
+        self.service['region_id'] = vim['openstack_region_id'] \
+            if vim.get('openstack_region_id') \
+            else vim['cloud_region_id']
+
         logger.info("making request with URI:%s" % req_resouce)
         resp = sess.get(req_resouce, endpoint_filter=self.service)
         logger.info("request returns with status %s" % resp.status_code)
@@ -137,6 +142,11 @@ class Volumes(APIView):
             VimDriverUtils.replace_key_by_mapping(volume,
                                                   self.keys_mapping, True)
             req_body = json.JSONEncoder().encode({"volume": volume})
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             logger.debug("with data:%s" % req_body)
             resp = sess.post(req_resouce, data=req_body,
@@ -179,6 +189,11 @@ class Volumes(APIView):
 
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.delete(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index 648ec02..195b820 100644 (file)
@@ -77,6 +77,11 @@ class Vports(APIView):
 
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.get(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
@@ -213,6 +218,11 @@ class Vports(APIView):
 
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenantid)
+
+            self.service['region_id'] = vim['openstack_region_id'] \
+                if vim.get('openstack_region_id') \
+                else vim['cloud_region_id']
+
             logger.info("making request with URI:%s" % req_resouce)
             resp = sess.delete(req_resouce, endpoint_filter=self.service)
             logger.info("request returns with status %s" % resp.status_code)
index 4ffe29f..07ba1b5 100644 (file)
@@ -128,9 +128,12 @@ class DnsaasDelegate(Services):
             service = {
                 'service_type': servicetype,
                 'interface': interface,
-                'region_id': regionid
+                'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']
             }
 
+
             req_resource = requri
             querystr = VimDriverUtils.get_query_part(request)
             if querystr:
index a6076bb..6aa1bbc 100644 (file)
@@ -103,9 +103,12 @@ class Services(APIView):
             service = {
                 'service_type': servicetype,
                 'interface': interface,
-                       'region_id': regionid
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']
             }
 
+
             querystr = VimDriverUtils.get_query_part(request)
             if querystr:
                 req_resource += "?" + querystr
@@ -183,7 +186,11 @@ class Services(APIView):
             interface = 'public'
             service = {'service_type': servicetype,
                        'interface': interface,
-                       'region_id': regionid}
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']
+                       }
+
 
             self._logger.info("service head request with uri %s" % (req_resource))
             resp = sess.head(req_resource, endpoint_filter=service)
index c3aaec2..41fe573 100644 (file)
@@ -41,7 +41,10 @@ class Registry(APIView):
             vimid, content_key):
         service = {'service_type': service_type,
                    'interface': 'public',
-                   'region_id': viminfo['cloud_region_id']}
+                   'region_id': viminfo['openstack_region_id']
+                       if viminfo.get('openstack_region_id')
+                       else viminfo['cloud_region_id']}
+
         self._logger.info("making request with URI:%s" % resource_url)
         resp = session.get(resource_url, endpoint_filter=service)
         self._logger.info("request returns with status %s" % resp.status_code)
@@ -248,7 +251,11 @@ class Registry(APIView):
                     req_resource = schema
                     service = {'service_type': "image",
                                'interface': 'public',
-                               'region_id': viminfo['cloud_region_id']}
+                               'region_id': viminfo['openstack_region_id']
+                               if viminfo.get('openstack_region_id')
+                               else viminfo['cloud_region_id']
+                               }
+
                     self._logger.info("making request with URI:%s" % req_resource)
                     resp = session.get(req_resource, endpoint_filter=service)
                     self._logger.info("request returns with status %s" % resp.status_code)
@@ -291,7 +298,11 @@ class Registry(APIView):
                         req_resource = "/os-hypervisors/detail?hypervisor_hostname_pattern=%s" % k
                         service = {'service_type': "compute",
                                    'interface': 'public',
-                                   'region_id': viminfo['cloud_region_id']}
+                                   'region_id': viminfo['openstack_region_id']
+                                   if viminfo.get('openstack_region_id')
+                                   else viminfo['cloud_region_id']
+                                   }
+
                         self._logger.info("making request with URI:%s" % req_resource)
                         resp = session.get(req_resource, endpoint_filter=service)
                         self._logger.info("request returns with status %s" % resp.status_code)
@@ -558,7 +569,9 @@ class Registry(APIView):
                 # add resource-version to url
                 if retcode == 0 and content:
                     viminfo = json.JSONDecoder().decode(content)
-                    viminfo['identity-url'] = self.proxy_prefix + "/%s/identity/v2.0" % vimid
+                    viminfo['identity-url'] = self.proxy_prefix + "/%s/identity/v2.0" % vimid \
+                        if self.proxy_prefix[-3:] == "/v0" else \
+                        self.proxy_prefix + "/%s/%s/identity/v2.0" % extsys.decode_vim_id(vimid)
 
                     retcode, content, status_code = \
                         restcall.req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s"
index 5bf3f1c..4225ff3 100644 (file)
@@ -23,6 +23,8 @@ from newton_base.registration import registration as newton_registration
 from common.exceptions import VimDriverNewtonException
 from common.msapi import extsys
 from keystoneauth1.exceptions import HttpError
+from newton_base.util import VimDriverUtils
+from common.utils import restcall
 
 logger = logging.getLogger(__name__)
 
@@ -372,11 +374,145 @@ class APIv1Registry(Registry):
         self.aai_base_url = settings.AAI_BASE_URL
         self._logger = logger
 
+
+    def _update_cloud_region(self, cloud_owner, cloud_region_id, openstack_region_id, viminfo, session=None):
+        if cloud_owner and cloud_region_id:
+            self._logger.debug(
+                ("_update_cloud_region, %(cloud_owner)s"
+                 "_%(cloud_region_id)s ")
+                % {
+                    "cloud_owner": cloud_owner,
+                    "cloud_region_id": cloud_region_id
+                })
+
+            #Note1: The intent is to populate the openstack region id into property: cloud-region.esr-system-info.openstackRegionId
+            #Note2: As temp solution: the openstack region id was put into AAI cloud-region["cloud-epa-caps"]
+
+            resource_info = {
+                "cloud-owner": cloud_owner,
+                "cloud-region-id": cloud_region_id,
+                "cloud-type": viminfo["type"],
+                "cloud-region-version": viminfo["version"],
+                "identity-url": self.proxy_prefix + "/%s/%s/identity/v2.0" % (cloud_owner, cloud_region_id),
+                "complex-name": viminfo["complex-name"],
+                "cloud-extra-info": viminfo["cloud_extra_info"],
+                "cloud-epa-caps":openstack_region_id,
+                "esr-system-info-list":{
+                    "esr-system-info":[
+                        {
+                            "esr-system-info-id": str(uuid.uuid4()),
+                            "service-url": viminfo["url"],
+                            "user-name": viminfo["userName"],
+                            "password": viminfo["password"],
+                            "system-type":"VIM",
+                            "ssl-cacert":viminfo["cacert"],
+                            "ssl-insecure": viminfo["insecure"],
+                            "cloud-domain": viminfo["domain"],
+                            "default-tenant": viminfo["tenant"]
+
+                        }
+                    ]
+                }
+            }
+
+            #get the resource first
+            resource_url = ("/cloud-infrastructure/cloud-regions/"
+                     "cloud-region/%(cloud_owner)s/%(cloud_region_id)s"
+                     % {
+                         "cloud_owner": cloud_owner,
+                         "cloud_region_id": cloud_region_id
+                     })
+
+            # get cloud-region
+            retcode, content, status_code = \
+                restcall.req_to_aai(resource_url, "GET")
+
+            # add resource-version
+            if retcode == 0 and content:
+                content = json.JSONDecoder().decode(content)
+                #resource_info["resource-version"] = content["resource-version"]
+                content.update(resource_info)
+                resource_info = content
+
+            #then update the resource
+            retcode, content, status_code = \
+                restcall.req_to_aai(resource_url, "PUT", content=resource_info)
+
+            self._logger.debug(
+                ("_update_cloud_region,%(cloud_owner)s"
+                 "_%(cloud_region_id)s , "
+                 "return %(retcode)s, %(content)s, %(status_code)s")
+                % {
+                    "cloud_owner": cloud_owner,
+                    "cloud_region_id": cloud_region_id,
+                    "retcode": retcode,
+                    "content": content,
+                    "status_code": status_code,
+                })
+            return retcode
+        return 1  # unknown cloud owner,region_id
+
+    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)
+            for region in self._get_list_resources(
+                    "/regions", "identity", session, viminfo, vimid,
+                    "regions"):
+                if (region['id'] == 'SystemController'):
+                    continue
+                elif (region['id'] == 'RegionOne'):
+                    continue
+                else:
+                    regions.append(region['id'])
+
+
+            return regions
+
+        except HttpError as e:
+            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())
+            return
+
     def post(self, request, cloud_owner="", cloud_region_id=""):
         self._logger.info("registration with : %s, %s" % (cloud_owner, cloud_region_id))
 
         vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
-        return super(APIv1Registry, self).post(request, vimid)
+
+        viminfo = VimDriverUtils.get_vim_info(vimid)
+        cloud_extra_info = viminfo['cloud_extra_info']
+        region_specified = cloud_extra_info["openstack-region-id"] if cloud_extra_info else None
+        multi_region_discovery = cloud_extra_info["multi-region-discovery"] if cloud_extra_info else None
+
+        # discover the regions
+        region_ids = self._discover_regions(cloud_owner, cloud_region_id, None, viminfo)
+
+        # compare the regions with region_specified and then cloud_region_id
+        if (region_specified in region_ids):
+            pass
+        elif (cloud_region_id in region_ids):
+            region_specified = cloud_region_id
+            pass
+        else:
+            # assume the first region be the primary region since we have no other way to determine it.
+            region_specified = region_ids[0]
+
+        # update cloud region and discover/register resource
+        if (multi_region_discovery and multi_region_discovery.upper() == "TRUE"):
+            # no input for specified cloud region, so discover all cloud region?
+            for regionid in region_ids:
+                #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 if region_specified != regionid else cloud_region_id
+                self._update_cloud_region(cloud_owner, gen_cloud_region_id, regionid, viminfo)
+                return super(RegistryV1, self).post(request, vimid)
+        else:
+            self._update_cloud_region(cloud_owner, cloud_region_id, region_specified, viminfo)
+            return super(RegistryV1, self).post(request, vimid)
+
+
+
 
     def delete(self, request, cloud_owner="", cloud_region_id=""):
         self._logger.debug("unregister cloud region: %s, %s" % (cloud_owner, cloud_region_id))
index 74470ca..1b4566c 100644 (file)
@@ -45,16 +45,19 @@ class CapacityCheck(APIView):
         try :
             resource_demand = request.data
 
+            tenant_name = None
+            vim = VimDriverUtils.get_vim_info(vimid)
+            sess = VimDriverUtils.get_session(vim, tenant_name)
+
             #get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
-                       'region_id': regionid}
-
-            tenant_name = None
-            vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenant_name)
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']
+                       }
 
             #get limit for this tenant
             req_resouce = "/limits"
index 0c413e5..c65a188 100644 (file)
@@ -44,16 +44,19 @@ class EventsCheck(APIView):
         try :
             resource_demand = request.data
 
+            tenant_name = None
+            vim = VimDriverUtils.get_vim_info(vimid)
+            sess = VimDriverUtils.get_session(vim, tenant_name)
+
             # get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
-                       'region_id': regionid}
-
-            tenant_name = None
-            vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenant_name)
+                       'region_id': vim['openstack_region_id']
+                           if vim.get('openstack_region_id')
+                           else vim['cloud_region_id']
+                       }
 
             # get servers detail info
             req_resouce = "/servers/detail"