Move extsys from newton to common 53/33353/3
authorHuang Haibin <haibin.huang@intel.com>
Tue, 27 Feb 2018 19:44:35 +0000 (03:44 +0800)
committerHuang Haibin <haibin.huang@intel.com>
Wed, 28 Feb 2018 18:39:05 +0000 (02:39 +0800)
Change-Id: I30ad2ed3a43bcb0ef569bb25d3e51a9ab49ea48a
Issue-ID: MULTICLOUD-138
Signed-off-by: Huang Haibin <haibin.huang@intel.com>
29 files changed:
ocata/ocata/extensions/tests/test_epacaps.py
ocata/ocata/proxy/tests/test_identity_proxy.py
ocata/ocata/proxy/tests/test_service_proxy.py
ocata/ocata/registration/tests/test_registration.py
ocata/ocata/settings.py
ocata/vagrant/test/Dockerfile
ocata/vagrant/test/extsys.py
share/common/msapi/__init__.py [new file with mode: 0644]
share/common/msapi/extsys.py [new file with mode: 0644]
share/newton_base/extensions/epacaps.py
share/newton_base/extensions/extensions.py
share/newton_base/openoapi/flavor.py
share/newton_base/openoapi/hosts.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/identityV3.py
share/newton_base/proxy/proxy_utils.py
share/newton_base/proxy/services.py
share/newton_base/registration/registration.py
share/newton_base/swagger/__init__.py
share/newton_base/swagger/views.py
share/newton_base/util.py

index a78e4c2..34a4e8e 100644 (file)
@@ -19,7 +19,7 @@ from django.test import Client
 from rest_framework import status
 import unittest
 
-from newton.requests.views.util import VimDriverUtils
+from newton_base.util import VimDriverUtils
 
 MOCK_VIM_INFO = {
     "createTime": "2017-04-01 02:22:27",
@@ -64,4 +64,4 @@ class TestEpaCaps(unittest.TestCase):
         self.assertEquals(cloud_region_id, json_content["cloud-region-id"])
         self.assertEquals(vimid, json_content["vimid"])
         self.assertEquals(json.loads(MOCK_VIM_INFO['cloud_epa_caps']),
-                          json_content["cloud-epa-caps"])
\ No newline at end of file
+                          json_content["cloud-epa-caps"])
index a77592f..d5fb22e 100644 (file)
@@ -22,7 +22,7 @@ from rest_framework import status
 from keystoneauth1 import session
 from keystoneauth1.exceptions import HttpError
 
-from newton.requests.views.util import VimDriverUtils
+from newton_base.util import VimDriverUtils
 from ocata.proxy.views.identityV3 import Tokens
 
 mock_viminfo = {
index f916e33..aa461d3 100644 (file)
@@ -21,7 +21,7 @@ from rest_framework import status
 import unittest
 
 
-from newton.requests.views.util import VimDriverUtils
+from newton_base.util import VimDriverUtils
 
 MOCK_VIM_INFO = {
     "createTime": "2017-04-01 02:22:27",
index e3fe352..694a143 100644 (file)
@@ -16,10 +16,10 @@ import mock
 
 from rest_framework import status
 
-from newton.pub.utils import restcall
+from common.utils import restcall
 from newton.requests.tests import mock_info
 from newton.requests.tests import test_base
-from newton.requests.views.util import VimDriverUtils
+from newton_base.util import VimDriverUtils
 
 MOCK_GET_TENANT_RESPONSE = {
     "projects":[
index 6021aa7..5567a06 100644 (file)
@@ -12,6 +12,8 @@
 import os
 import sys
 
+CACHE_EXPIRATION_TIME = 3600
+
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
index 2d9eda5..cc7d2b5 100644 (file)
@@ -19,7 +19,7 @@ RUN apt-get update && \
     rm -f multicloud-openstack-ocata.zip && \
     pip install -r /opt/ocata/requirements.txt
 
-ADD extsys.py /opt/ocata/lib/newton/newton/pub/msapi/extsys.py
+ADD extsys.py /opt/ocata/lib/share/common/msapi/extsys.py
 
 WORKDIR /opt/ocata
 CMD /bin/sh -c /opt/ocata/run.sh
index 59cf7a7..8377891 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Wind River Systems, Inc.
+# 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.
@@ -14,8 +14,8 @@ import logging
 import re
 
 from rest_framework import status
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.pub.utils.restcall import req_by_msb,req_to_aai
+from common.exceptions import VimDriverNewtonException
+from common.utils.restcall import req_by_msb,req_to_aai
 
 
 logger = logging.getLogger(__name__)
diff --git a/share/common/msapi/__init__.py b/share/common/msapi/__init__.py
new file mode 100644 (file)
index 0000000..387c54c
--- /dev/null
@@ -0,0 +1,10 @@
+# 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.
diff --git a/share/common/msapi/extsys.py b/share/common/msapi/extsys.py
new file mode 100644 (file)
index 0000000..99824ef
--- /dev/null
@@ -0,0 +1,98 @@
+# 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.
+
+import json
+import logging
+import re
+
+from common.exceptions import VimDriverNewtonException
+from common.utils import restcall
+
+
+logger = logging.getLogger(__name__)
+
+def get_vim_by_id(vim_id):
+
+    cloud_owner,cloud_region_id = decode_vim_id(vim_id)
+
+    if cloud_owner and cloud_region_id:
+        retcode, content, status_code = \
+            restcall.req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s?depth=1"
+                       % (cloud_owner,cloud_region_id),"GET")
+        if retcode != 0:
+            logger.error("Status code is %s, detail is %s.", status_code, content)
+            raise VimDriverNewtonException(
+                "Failed to query VIM with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id),
+                status_code, content)
+        tmp_viminfo = json.JSONDecoder().decode(content)
+
+        #assume esr-system-info-id is composed by {cloud-owner} _ {cloud-region-id}
+#        retcode2,content2,status_code2 = \
+#            restcall.req_to_aai(("/cloud-infrastructure/cloud-regions/cloud-region/%(owner)s/%(region)s"
+#                                 "/esr-system-info-list/esr-system-info/%(owner)s_%(region)s" % {
+#                "owner": cloud_owner, "region": cloud_region_id}), "GET")
+#        if retcode2 != 0:
+#            logger.error("Status code is %s, detail is %s.", status_code, content)
+#            raise VimDriverNewtonException(
+#                "Failed to query ESR system with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id),
+#                status_code2, content2)
+#        tmp_authinfo = json.JSONDecoder().decode(content2)
+        tmp_authinfo = tmp_viminfo['esr-system-info-list']['esr-system-info'][0] if tmp_viminfo else None
+
+        #convert vim information
+        if tmp_viminfo and tmp_authinfo:
+            viminfo = {}
+            viminfo['vimId'] = vim_id
+            viminfo['resource-version'] = tmp_viminfo.get('resource-version')
+            viminfo['cloud_owner'] = cloud_owner
+            viminfo['cloud_region_id'] = cloud_region_id
+            viminfo['type'] = tmp_viminfo.get('cloud-type')
+            viminfo['name'] = tmp_viminfo.get('complex-name')
+            viminfo['version'] = tmp_viminfo.get('cloud-region-version')
+            viminfo['cloud_extra_info'] = tmp_viminfo.get('cloud-extra-info')
+            viminfo['cloud_epa_caps'] = tmp_viminfo.get('cloud-epa-caps')
+
+            viminfo['userName'] = tmp_authinfo['user-name']
+            viminfo['password'] = tmp_authinfo['password']
+            viminfo['domain'] = tmp_authinfo.get('cloud-domain')
+            viminfo['url'] = tmp_authinfo.get('service-url')
+            viminfo['tenant'] = tmp_authinfo.get('default-tenant')
+            viminfo['cacert'] = tmp_authinfo.get('ssl-cacert')
+            viminfo['insecure'] = tmp_authinfo.get('ssl-insecure')
+
+            return viminfo
+    return None
+
+def delete_vim_by_id(vim_id):
+    cloud_owner, cloud_region_id = decode_vim_id(vim_id)
+    if cloud_owner and cloud_region_id:
+        #get the vim info
+        viminfo = get_vim_by_id(vim_id)
+        if not viminfo or not viminfo['resource-version']:
+            return 0
+
+        retcode, content, status_code = \
+            restcall.req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s?resource-version=%s"
+                       % ( cloud_owner, cloud_region_id, viminfo['resource-version']), "DELETE")
+        if retcode != 0:
+            logger.error("Status code is %s, detail is %s.", status_code, content)
+            raise VimDriverNewtonException(
+                "Failed to delete VIM in AAI with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id),
+                status_code, content)
+        return 0
+    # return non zero if failed to decode cloud owner and region id
+    return 1
+
+def decode_vim_id(vim_id):
+    m = re.search(r'^([0-9a-zA-Z-]+)_([0-9a-zA-Z_-]+)$', vim_id)
+    cloud_owner, cloud_region_id = m.group(1), m.group(2)
+    return cloud_owner, cloud_region_id
+
index d8878e2..cc5420e 100644 (file)
@@ -21,9 +21,9 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.requests.views.util import VimDriverUtils
-from newton.pub.msapi import extsys
+from common.exceptions import VimDriverNewtonException
+from newton_base.util import VimDriverUtils
+from common.msapi import extsys
 
 logger = logging.getLogger(__name__)
 
index fb6455b..6b3ecb5 100644 (file)
@@ -24,9 +24,9 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.requests.views.util import VimDriverUtils
-from newton.pub.msapi import extsys
+from common.exceptions import VimDriverNewtonException
+from newton_base.util import VimDriverUtils
+from common.msapi import extsys
 
 logger = logging.getLogger(__name__)
 
index 27bbb82..d50b194 100644 (file)
@@ -20,7 +20,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 from newton_base.util import VimDriverUtils
 
 logger = logging.getLogger(__name__)
index 720ba8e..60debf5 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Wind River Systems, Inc.
+# 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.
@@ -19,7 +19,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index 9ddb5f5..965b2c3 100644 (file)
@@ -21,7 +21,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index 3f62afa..3302fdb 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index a1ac550..253ac89 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Wind River Systems, Inc.
+# 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.
@@ -19,7 +19,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index c53e43e..95eab2b 100644 (file)
@@ -22,7 +22,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 from newton_base.util import VimDriverUtils
 
 logger = logging.getLogger(__name__)
index 1310ab5..a9b423a 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index bcd8f2f..926f72c 100644 (file)
@@ -20,7 +20,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 from newton_base.util import VimDriverUtils
 
 logger = logging.getLogger(__name__)
index a048dda..27bd1ef 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index 8f9b0d6..9656b5c 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 from newton_base.util import VimDriverUtils
 
index 85bcbfd..8a38452 100644 (file)
@@ -25,9 +25,9 @@ from rest_framework.views import APIView
 from newton_base.proxy.services import Services
 
 from newton_base.proxy.proxy_utils import ProxyUtils
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.pub.msapi import extsys
-from newton.requests.views.util import VimDriverUtils
+from common.exceptions import VimDriverNewtonException
+from common.msapi import extsys
+from newton_base.util import VimDriverUtils
 
 
 logger = logging.getLogger(__name__)
index 0c45c23..057bdf3 100644 (file)
@@ -24,8 +24,8 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.requests.views.util import VimDriverUtils
+from common.exceptions import VimDriverNewtonException
+from newton_base.util import VimDriverUtils
 from newton_base.proxy.proxy_utils import ProxyUtils
 
 logger = logging.getLogger(__name__)
@@ -90,9 +90,10 @@ class Tokens(APIView):
 
             # prepare request resource to vim instance
             vim = VimDriverUtils.get_vim_info(vimid)
-            sess = VimDriverUtils.get_session(vim, tenantname = tenant_name, tenantid=tenant_id)
+            sess = VimDriverUtils.get_session(vim, tenant_name = tenant_name, tenant_id=tenant_id)
 
-            tmp_auth_state = VimDriverUtils.get_auth_state(vim, sess)
+            #tmp_auth_state = VimDriverUtils.get_auth_state(vim, sess)
+            tmp_auth_state = VimDriverUtils.get_auth_state(sess)
             tmp_auth_info = json.loads(tmp_auth_state)
             tmp_auth_token = tmp_auth_info['auth_token']
             tmp_auth_data = tmp_auth_info['body']
@@ -104,8 +105,8 @@ class Tokens(APIView):
             tmp_auth_data['token']['catalog'], tmp_metadata_catalog = ProxyUtils.update_catalog(
                 vimid, tmp_auth_data['token']['catalog'], self.proxy_prefix)
 
-            tmp_auth_token = VimDriverUtils.update_token_cache(
-                vim, sess, tmp_auth_token, tmp_auth_state, json.dumps(tmp_metadata_catalog))
+            VimDriverUtils.update_token_cache(
+                tmp_auth_token, tmp_auth_state, json.dumps(tmp_metadata_catalog))
 
             tmp_auth_data['token']['catalog'] = ProxyUtils.update_catalog_dnsaas(
                 vimid,tmp_auth_data['token']['catalog'], self.proxy_prefix, vim)
index 79be422..bad5b60 100644 (file)
@@ -19,7 +19,7 @@ import uuid
 
 from rest_framework import status
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 logger = logging.getLogger(__name__)
 
index e40b58e..fb0cf60 100644 (file)
@@ -23,9 +23,9 @@ from rest_framework import status
 from rest_framework.views import APIView
 
 from newton_base.proxy.proxy_utils import ProxyUtils
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.pub.msapi import extsys
-from newton.requests.views.util import VimDriverUtils
+from common.exceptions import VimDriverNewtonException
+from common.msapi import extsys
+from newton_base.util import VimDriverUtils
 
 logger = logging.getLogger(__name__)
 
index d9ce713..e5a8450 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Wind River Systems, Inc.
+# 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.
@@ -21,11 +21,10 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.config import config
-from newton.pub.exceptions import VimDriverNewtonException
-from newton.pub.msapi import extsys
-from newton.pub.utils import restcall
-from newton.requests.views.util import VimDriverUtils
+from common.exceptions import VimDriverNewtonException
+from common.msapi import extsys
+from common.utils import restcall
+from newton_base.util import VimDriverUtils
 
 logger = logging.getLogger(__name__)
 
index 802f3fb..387c54c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Wind River Systems, Inc.
+# 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.
index 10f3c0c..839abea 100644 (file)
@@ -18,7 +18,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-from newton.pub.exceptions import VimDriverNewtonException
+from common.exceptions import VimDriverNewtonException
 
 logger = logging.getLogger(__name__)
 
index d236325..c708e85 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Wind River Systems, Inc.
+# 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.
@@ -20,7 +20,7 @@ from keystoneauth1.identity import v2 as keystone_v2
 from keystoneauth1.identity import v3 as keystone_v3
 from keystoneauth1 import session
 
-from newton.pub.msapi import extsys
+from common.msapi import extsys
 
 logger = logging.getLogger(__name__)