diff options
author | Bin Yang <bin.yang@windriver.com> | 2018-08-14 10:51:47 +0000 |
---|---|---|
committer | Bin Yang <bin.yang@windriver.com> | 2018-08-14 10:51:47 +0000 |
commit | 8eacf7b7496a7864313595dcf3780d83b423c338 (patch) | |
tree | 95d011aa7142858af182ac8b936d41bd44c0cad6 | |
parent | 39d394d0a5c02fbe122f0b78f4a5a47bf5ec4bae (diff) |
API upgrading for catalog
Change-Id: I26301b701ca7fb915112ad8d35454d0488a91fd1
Issue-ID: MULTICLOUD-297
Signed-off-by: Bin Yang <bin.yang@windriver.com>
-rw-r--r-- | share/newton_base/proxy/proxy_utils.py | 58 | ||||
-rw-r--r-- | windriver/titanium_cloud/extensions/urlsV1.py | 24 | ||||
-rw-r--r-- | windriver/titanium_cloud/extensions/views/extensions.py | 15 | ||||
-rw-r--r-- | windriver/titanium_cloud/proxy/views/identityV3.py | 4 | ||||
-rw-r--r-- | windriver/titanium_cloud/registration/views/registration.py | 2 | ||||
-rw-r--r-- | windriver/titanium_cloud/settings.py | 3 | ||||
-rw-r--r-- | windriver/titanium_cloud/urls.py | 4 |
7 files changed, 89 insertions, 21 deletions
diff --git a/share/newton_base/proxy/proxy_utils.py b/share/newton_base/proxy/proxy_utils.py index 5f3dd08a..28f5f3af 100644 --- a/share/newton_base/proxy/proxy_utils.py +++ b/share/newton_base/proxy/proxy_utils.py @@ -20,6 +20,7 @@ import uuid from rest_framework import status from common.exceptions import VimDriverNewtonException +from common.msapi import extsys logger = logging.getLogger(__name__) @@ -103,9 +104,14 @@ class ProxyUtils(object): # populate metadata_catalog one_catalog['prefix'] = real_prefix one_catalog['suffix'] = real_suffix if real_suffix else '' - one_catalog['proxy_prefix'] = multicould_namespace + "/%s" % vimid - endpoint_url = multicould_namespace + "/%s" % vimid + if (multicould_namespace[-3:] == "/v0"): + one_catalog['proxy_prefix'] = multicould_namespace + "/%s" % vimid + endpoint_url = multicould_namespace + "/%s" % vimid + else:#api v1 or future + cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) + one_catalog['proxy_prefix'] = multicould_namespace + "/%s/%s" % (cloud_owner, cloud_region_id) + endpoint_url = multicould_namespace + "/%s/%s" % (cloud_owner, cloud_region_id) tmp_pattern = re.compile(item["type"]) if not real_suffix or not re.match(tmp_pattern, real_suffix): @@ -116,7 +122,11 @@ class ProxyUtils(object): endpoint_url += "/" + real_suffix if item["type"] == "identity": - endpoint_url = multicould_namespace + "/%s/identity/v3" % vimid + if (multicould_namespace[-3:] == "/v0"): + endpoint_url = multicould_namespace + "/%s/identity/v3" % vimid + else:#api v1 or future + cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) + endpoint_url = multicould_namespace + "/%s/%s/identity/v3" % (cloud_owner, cloud_region_id) else: #something wrong @@ -153,20 +163,36 @@ class ProxyUtils(object): or not cloud_dns_delegate_info.get("cloud-region-id"): #DNSaaS deleget was not configured yet return catalog - - dns_catalog = { - "name":"dns-delegate", - "type":"dns", - "id": str(uuid.uuid1()), - "endpoints": [{ - "interface": "public", - "region": cloud_dns_delegate_info.get("cloud-region-id"), - "region_id": cloud_dns_delegate_info.get("cloud-region-id"), + if (multicould_namespace[-3:] == "/v0"): + dns_catalog = { + "name":"dns-delegate", + "type":"dns", + "id": str(uuid.uuid1()), + "endpoints": [{ + "interface": "public", + "region": cloud_dns_delegate_info.get("cloud-region-id"), + "region_id": cloud_dns_delegate_info.get("cloud-region-id"), + "id": str(uuid.uuid1()), + "url": multicould_namespace + "/%s/dns-delegate" % vimid, + }] + } + catalog.append(dns_catalog) + else: # api v1 or future + cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) + dns_catalog = { + "name":"dns-delegate", + "type":"dns", "id": str(uuid.uuid1()), - "url": multicould_namespace + "/%s/dns-delegate" % vimid, - }] - } - catalog.append(dns_catalog) + "endpoints": [{ + "interface": "public", + "region": cloud_dns_delegate_info.get("cloud-region-id"), + "region_id": cloud_dns_delegate_info.get("cloud-region-id"), + "id": str(uuid.uuid1()), + "url": multicould_namespace + "/%s/%s/dns-delegate" % (cloud_owner, cloud_region_id), + }] + } + catalog.append(dns_catalog) + return catalog diff --git a/windriver/titanium_cloud/extensions/urlsV1.py b/windriver/titanium_cloud/extensions/urlsV1.py new file mode 100644 index 00000000..f6398ef6 --- /dev/null +++ b/windriver/titanium_cloud/extensions/urlsV1.py @@ -0,0 +1,24 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.conf.urls import url +from rest_framework.urlpatterns import format_suffix_patterns + +from titanium_cloud.extensions.views import extensions + +urlpatterns = [ + url(r'^sions/?$', extensions.APIv1Extensions.as_view()), +] + +urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/windriver/titanium_cloud/extensions/views/extensions.py b/windriver/titanium_cloud/extensions/views/extensions.py index cfdc2517..5b857303 100644 --- a/windriver/titanium_cloud/extensions/views/extensions.py +++ b/windriver/titanium_cloud/extensions/views/extensions.py @@ -70,3 +70,18 @@ class Extensions(newton_extensions.Extensions): logger.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + + +class APIv1Extensions(Extensions): + + def __init__(self): + self._logger = logger + self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX + + + def get(self, request, cloud_owner="", cloud_region_id=""): + self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner,cloud_region_id)) + + vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) + return super(APIv1Extensions,self).get(request, vimid) diff --git a/windriver/titanium_cloud/proxy/views/identityV3.py b/windriver/titanium_cloud/proxy/views/identityV3.py index cae0e834..e6dc16a7 100644 --- a/windriver/titanium_cloud/proxy/views/identityV3.py +++ b/windriver/titanium_cloud/proxy/views/identityV3.py @@ -37,7 +37,7 @@ class TokensV2(newton_identityV3.TokensV2): class APIv1Tokens(Tokens): def __init__(self): - self.proxy_prefix = settings.MULTICLOUD_PREFIX + self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX self._logger = logger @@ -61,7 +61,7 @@ class APIv1Tokens(Tokens): class APIv1TokensV2(TokensV2): def __init__(self): - self.proxy_prefix = settings.MULTICLOUD_PREFIX + self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX self._logger = logger diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py index 56f77ba7..b54772e3 100644 --- a/windriver/titanium_cloud/registration/views/registration.py +++ b/windriver/titanium_cloud/registration/views/registration.py @@ -367,7 +367,7 @@ class Registry(newton_registration.Registry): class RegistryV1(Registry): def __init__(self): - self.proxy_prefix = settings.MULTICLOUD_PREFIX + self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX self.aai_base_url = settings.AAI_BASE_URL self._logger = logger diff --git a/windriver/titanium_cloud/settings.py b/windriver/titanium_cloud/settings.py index 296d8e75..adfa4930 100644 --- a/windriver/titanium_cloud/settings.py +++ b/windriver/titanium_cloud/settings.py @@ -100,6 +100,9 @@ MSB_SERVICE_PORT = os.environ.get('MSB_PORT', "80") MULTICLOUD_PREFIX = "http://%s:%s/api/multicloud-titanium_cloud/v0" % ( MSB_SERVICE_ADDR, MSB_SERVICE_PORT) +MULTICLOUD_API_V1_PREFIX = "http://%s:%s/api/multicloud-titanium_cloud/v1" % ( + MSB_SERVICE_ADDR, MSB_SERVICE_PORT) + # [A&AI] AAI_ADDR = os.environ.get('AAI_ADDR', "aai.api.simpledemo.openecomp.org") AAI_PORT = os.environ.get('AAI_PORT', "8443") diff --git a/windriver/titanium_cloud/urls.py b/windriver/titanium_cloud/urls.py index e8ec9f02..5a4e64b0 100644 --- a/windriver/titanium_cloud/urls.py +++ b/windriver/titanium_cloud/urls.py @@ -49,8 +49,8 @@ urlpatterns = [ registration.RegistryV1.as_view()), url(r'^api/multicloud-titanium_cloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/?$', registration.RegistryV1.as_view()), -# url(r'^api/multicloud-titanium_cloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/exten', -# include('titanium_cloud.extensions.urls')), + url(r'^api/multicloud-titanium_cloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/exten', + include('titanium_cloud.extensions.urlsV1')), url(r'^api/multicloud-titanium_cloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/', include('titanium_cloud.proxy.urlsV1')), # url(r'^api/multicloud-titanium_cloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/tenants/?$', |