diff options
-rw-r--r-- | newton/newton/pub/msapi/extsys.py | 10 | ||||
-rw-r--r-- | newton/newton/pub/tests/test_extsys.py | 14 | ||||
-rw-r--r-- | newton/newton/registration/views/registration.py | 31 |
3 files changed, 40 insertions, 15 deletions
diff --git a/newton/newton/pub/msapi/extsys.py b/newton/newton/pub/msapi/extsys.py index 0f08adb4..bd8b1e4e 100644 --- a/newton/newton/pub/msapi/extsys.py +++ b/newton/newton/pub/msapi/extsys.py @@ -51,6 +51,7 @@ def get_vim_by_id(vim_id): 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') @@ -73,9 +74,14 @@ def get_vim_by_id(vim_id): 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" - % ( cloud_owner, cloud_region_id), "DELETE") + 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( diff --git a/newton/newton/pub/tests/test_extsys.py b/newton/newton/pub/tests/test_extsys.py index 533910f9..9e67dcc0 100644 --- a/newton/newton/pub/tests/test_extsys.py +++ b/newton/newton/pub/tests/test_extsys.py @@ -31,10 +31,12 @@ MOCK_ESR_SYSTEM_INFO = { "service-url": "http://localhost", "default-tenant": "demo", "ssl-cacert": None, - "ssl-insecure": None + "ssl-insecure": None, + "resource-version":"1978882" } MOCK_VIM_INFO = { + "resource-version":"1978883", "cloud-type": "openstack", "complex-name": "complex", "cloud-region-version": "Regionv1", @@ -49,6 +51,7 @@ MOCK_VIM_INFO = { } + def returnList(items): def func(): for item in items: @@ -111,7 +114,12 @@ class TestEpaCaps(unittest.TestCase): self.assertEquals(MOCK_ESR_SYSTEM_INFO['ssl-insecure'], viminfo['insecure']) def test_delete_vim_by_id(self): - values = [(1, "test_content", 500),(0, None, None)] + values = [ + (0, json.dumps(MOCK_VIM_INFO), None), + (1, "test_content", 500), + (0, json.dumps(MOCK_VIM_INFO), None), + (0, None, None) + ] restcall.req_to_aai = mock.Mock(side_effect=returnList(values)) self.assertRaises(VimDriverNewtonException, extsys.delete_vim_by_id, self.vim_id) @@ -120,4 +128,4 @@ class TestEpaCaps(unittest.TestCase): def test_decode_vim_id_successfuly(self): owner, region_id = extsys.decode_vim_id(self.vim_id) self.assertEquals(self.cloud_onwer, owner) - self.assertEquals(self.cloud_region_id, region_id)
\ No newline at end of file + self.assertEquals(self.cloud_region_id, region_id) diff --git a/newton/newton/registration/views/registration.py b/newton/newton/registration/views/registration.py index 95769a66..883f0d68 100644 --- a/newton/newton/registration/views/registration.py +++ b/newton/newton/registration/views/registration.py @@ -55,16 +55,19 @@ class Registry(APIView): def _update_resoure(self, cloud_owner, cloud_region_id, resoure_id, resource_info, resource_type): if cloud_owner and cloud_region_id: + #get the resource first + + #add resource + #then update the resource retcode, content, status_code = \ restcall.req_to_aai( ("/cloud-infrastructure/cloud-regions/" "cloud-region/%(cloud_owner)s/%(cloud_region_id)s/" - "%(resource_type)s/%(resource_type)ss/%(resoure_id)s" + "%(resource_type)ss/%(resource_type)s/%(resoure_id)s" % { "cloud_owner": cloud_owner, "cloud_region_id": cloud_region_id, "resoure_id": resoure_id, - "resource_info": resource_info, "resource_type": resource_type, }) , "PUT", content=resource_info) @@ -441,7 +444,7 @@ class Registry(APIView): self._logger.debug("failed to populate EPA CAPs info into AAI: %s, ret:%s" % (vimid, ret)) - def _update_proxy_identity_endpoint(self, cloud_owner, cloud_region_id, url): + def _update_proxy_identity_endpoint(self, viminfo): ''' update cloud_region's identity url :param cloud_owner: @@ -449,13 +452,17 @@ class Registry(APIView): :param url: :return: ''' + + vimid = viminfo['vimId'] + cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) if cloud_owner and cloud_region_id: + viminfo['identity-url'] = self.proxy_prefix + "/%s/identity/v3" % vimid retcode, content, status_code = \ restcall.req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s" - % (cloud_owner, cloud_region_id), "PUT", content={'identity-url': url}) + % (cloud_owner, cloud_region_id), "PUT", content=viminfo) - self._logger.debug("update_proxy_identity_endpoint,vimid:%s_%s req_to_aai: %s, return %s, %s, %s" - % (cloud_owner,cloud_region_id, url, retcode, content, status_code)) + self._logger.debug("update_proxy_identity_endpoint,vimid:%s req_to_aai: %s, return %s, %s, %s" + % (vimid, viminfo['identity-url'], retcode, content, status_code)) def post(self, request, vimid=""): self._logger.debug("Registration--post::data> %s" % request.data) @@ -463,16 +470,20 @@ class Registry(APIView): try: # populate proxy identity url - cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) - self._update_proxy_identity_endpoint(cloud_owner, cloud_region_id, - self.proxy_prefix + "/%s/identity/v3" % vimid) + viminfo = VimDriverUtils.get_vim_info(vimid) + if not viminfo: + raise VimDriverNewtonException( + "There is no cloud-region with {cloud-owner}_{cloud-region-id}=%s in AAI" % vimid) + + #cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) + self._update_proxy_identity_endpoint(viminfo) # prepare request resource to vim instance # get token: viminfo = VimDriverUtils.get_vim_info(vimid) # set the default tenant since there is no tenant info in the VIM yet sess = VimDriverUtils.get_session( - viminfo, tenantname=request.data['defaultTenant']) + viminfo, tenantname=viminfo['tenant']) # step 1. discover all projects and populate into AAI self._discover_tenants(vimid, sess, viminfo) |