summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-08-16 04:32:18 +0000
committerBin Yang <bin.yang@windriver.com>2018-08-17 06:21:56 +0000
commit591cdc9da7149fa4e68eac0de2efa8efd25281d6 (patch)
treefa75681ece5154f4215d78f104661fa99419b504
parent400e1b7c35a1db4cdcf20f4453631bc0888a330f (diff)
multi-region discovery
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>
-rw-r--r--newton/newton/resource/views/capacity.py15
-rw-r--r--newton/newton/resource/views/events.py11
-rw-r--r--ocata/ocata/resource/views/capacity.py11
-rw-r--r--ocata/ocata/resource/views/events.py11
-rw-r--r--share/common/msapi/extsys.py3
-rw-r--r--share/newton_base/openoapi/flavor.py13
-rw-r--r--share/newton_base/openoapi/hosts.py4
-rwxr-xr-xshare/newton_base/openoapi/hypervisor.py6
-rw-r--r--share/newton_base/openoapi/image.py16
-rw-r--r--share/newton_base/openoapi/limits.py15
-rw-r--r--share/newton_base/openoapi/network.py13
-rw-r--r--share/newton_base/openoapi/server.py31
-rw-r--r--share/newton_base/openoapi/subnet.py15
-rw-r--r--share/newton_base/openoapi/tenants.py5
-rw-r--r--share/newton_base/openoapi/volume.py15
-rw-r--r--share/newton_base/openoapi/vport.py10
-rw-r--r--share/newton_base/proxy/dnsaasdelegate.py5
-rw-r--r--share/newton_base/proxy/services.py11
-rw-r--r--share/newton_base/registration/registration.py21
-rw-r--r--windriver/titanium_cloud/registration/views/registration.py138
-rw-r--r--windriver/titanium_cloud/resource/views/capacity.py13
-rw-r--r--windriver/titanium_cloud/resource/views/events.py13
22 files changed, 358 insertions, 37 deletions
diff --git a/newton/newton/resource/views/capacity.py b/newton/newton/resource/views/capacity.py
index 973bc980..c9d465e2 100644
--- a/newton/newton/resource/views/capacity.py
+++ b/newton/newton/resource/views/capacity.py
@@ -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"
diff --git a/newton/newton/resource/views/events.py b/newton/newton/resource/views/events.py
index bf7de344..1f06c785 100644
--- a/newton/newton/resource/views/events.py
+++ b/newton/newton/resource/views/events.py
@@ -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"
diff --git a/ocata/ocata/resource/views/capacity.py b/ocata/ocata/resource/views/capacity.py
index 37c920e4..b1f31913 100644
--- a/ocata/ocata/resource/views/capacity.py
+++ b/ocata/ocata/resource/views/capacity.py
@@ -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"
diff --git a/ocata/ocata/resource/views/events.py b/ocata/ocata/resource/views/events.py
index 3cfdad4a..4b477a75 100644
--- a/ocata/ocata/resource/views/events.py
+++ b/ocata/ocata/resource/views/events.py
@@ -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"
diff --git a/share/common/msapi/extsys.py b/share/common/msapi/extsys.py
index c0cc7f27..e1534523 100644
--- a/share/common/msapi/extsys.py
+++ b/share/common/msapi/extsys.py
@@ -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
diff --git a/share/newton_base/openoapi/flavor.py b/share/newton_base/openoapi/flavor.py
index af811f67..18a13987 100644
--- a/share/newton_base/openoapi/flavor.py
+++ b/share/newton_base/openoapi/flavor.py
@@ -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)
diff --git a/share/newton_base/openoapi/hosts.py b/share/newton_base/openoapi/hosts.py
index d93336a4..7a311b38 100644
--- a/share/newton_base/openoapi/hosts.py
+++ b/share/newton_base/openoapi/hosts.py
@@ -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)
diff --git a/share/newton_base/openoapi/hypervisor.py b/share/newton_base/openoapi/hypervisor.py
index eb0debd4..bfde0f51 100755
--- a/share/newton_base/openoapi/hypervisor.py
+++ b/share/newton_base/openoapi/hypervisor.py
@@ -72,7 +72,11 @@ class Hypervisors(APIView):
vim["domain"] = "Default"
sess = VimDriverUtils.get_session(vim, tenantid)
- logger.info("making request with URI:%s" % req_resource)
+ 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_resource, endpoint_filter = self.service)
diff --git a/share/newton_base/openoapi/image.py b/share/newton_base/openoapi/image.py
index e27d0190..85615275 100644
--- a/share/newton_base/openoapi/image.py
+++ b/share/newton_base/openoapi/image.py
@@ -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)
diff --git a/share/newton_base/openoapi/limits.py b/share/newton_base/openoapi/limits.py
index fad710f3..d260ab76 100644
--- a/share/newton_base/openoapi/limits.py
+++ b/share/newton_base/openoapi/limits.py
@@ -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)
diff --git a/share/newton_base/openoapi/network.py b/share/newton_base/openoapi/network.py
index 9ad7a83f..9475ee2c 100644
--- a/share/newton_base/openoapi/network.py
+++ b/share/newton_base/openoapi/network.py
@@ -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)
diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py
index c5011f15..3e90bf84 100644
--- a/share/newton_base/openoapi/server.py
+++ b/share/newton_base/openoapi/server.py
@@ -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)
diff --git a/share/newton_base/openoapi/subnet.py b/share/newton_base/openoapi/subnet.py
index 9ff61f2a..1d4f761b 100644
--- a/share/newton_base/openoapi/subnet.py
+++ b/share/newton_base/openoapi/subnet.py
@@ -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)
diff --git a/share/newton_base/openoapi/tenants.py b/share/newton_base/openoapi/tenants.py
index 76fd2137..a8b97464 100644
--- a/share/newton_base/openoapi/tenants.py
+++ b/share/newton_base/openoapi/tenants.py
@@ -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)
diff --git a/share/newton_base/openoapi/volume.py b/share/newton_base/openoapi/volume.py
index 827baea9..100d2392 100644
--- a/share/newton_base/openoapi/volume.py
+++ b/share/newton_base/openoapi/volume.py
@@ -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)
diff --git a/share/newton_base/openoapi/vport.py b/share/newton_base/openoapi/vport.py
index 648ec02b..195b820b 100644
--- a/share/newton_base/openoapi/vport.py
+++ b/share/newton_base/openoapi/vport.py
@@ -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)
diff --git a/share/newton_base/proxy/dnsaasdelegate.py b/share/newton_base/proxy/dnsaasdelegate.py
index 4ffe29f8..07ba1b51 100644
--- a/share/newton_base/proxy/dnsaasdelegate.py
+++ b/share/newton_base/proxy/dnsaasdelegate.py
@@ -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:
diff --git a/share/newton_base/proxy/services.py b/share/newton_base/proxy/services.py
index a6076bb7..6aa1bbce 100644
--- a/share/newton_base/proxy/services.py
+++ b/share/newton_base/proxy/services.py
@@ -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)
diff --git a/share/newton_base/registration/registration.py b/share/newton_base/registration/registration.py
index c3aaec24..41fe5733 100644
--- a/share/newton_base/registration/registration.py
+++ b/share/newton_base/registration/registration.py
@@ -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"
diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py
index 5bf3f1c5..4225ff3b 100644
--- a/windriver/titanium_cloud/registration/views/registration.py
+++ b/windriver/titanium_cloud/registration/views/registration.py
@@ -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))
diff --git a/windriver/titanium_cloud/resource/views/capacity.py b/windriver/titanium_cloud/resource/views/capacity.py
index 74470ca2..1b4566c3 100644
--- a/windriver/titanium_cloud/resource/views/capacity.py
+++ b/windriver/titanium_cloud/resource/views/capacity.py
@@ -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"
diff --git a/windriver/titanium_cloud/resource/views/events.py b/windriver/titanium_cloud/resource/views/events.py
index 0c413e57..c65a188f 100644
--- a/windriver/titanium_cloud/resource/views/events.py
+++ b/windriver/titanium_cloud/resource/views/events.py
@@ -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"