aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFu Jinhua <fu.jinhua@zte.com.cn>2019-04-01 01:55:30 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-01 01:55:30 +0000
commit2c914088688a6a87f60370b0c696bfd7480d26e9 (patch)
treefd7d83e9c1dab4f485486c2f08e6e4a797d11dde
parent9927c57a44df673b973cff35f66f4da803c4126a (diff)
parent91c8b462cce3ef38f2f182445d9be79adeca8858 (diff)
Merge "Split the vim_id in LCM"
-rw-r--r--lcm/ns/biz/ns_instant.py52
-rw-r--r--lcm/ns/biz/ns_lcm_op_occ.py3
-rw-r--r--lcm/ns/biz/query_ns_lcm_op_occ.py1
-rw-r--r--lcm/ns/serializers/sol/affected_nss.py5
-rw-r--r--lcm/ns/serializers/sol/affected_pnfs.py14
-rw-r--r--lcm/ns/tests/test_ns_instant.py4
-rw-r--r--lcm/ns/tests/test_sol_ns_heal_api.py7
-rw-r--r--lcm/ns/tests/test_sol_ns_instantiate_api.py41
-rw-r--r--lcm/ns/tests/test_sol_ns_scale_api.py2
-rw-r--r--lcm/ns/tests/test_sol_ns_terminate_api.py4
-rw-r--r--lcm/ns_vls/biz/create_vls.py7
-rw-r--r--lcm/ns_vls/biz/delete_vls.py5
-rw-r--r--lcm/ns_vls/tests/tests.py2
-rw-r--r--lcm/ns_vnfs/biz/create_vnfs.py13
-rw-r--r--lcm/ns_vnfs/tests/tests.py11
-rw-r--r--lcm/ns_vnfs/urls.py3
-rw-r--r--lcm/ns_vnfs/views/views.py10
-rw-r--r--lcm/pub/msapi/extsys.py22
-rw-r--r--lcm/pub/nfvi/vim/api/multivim/api.py15
19 files changed, 142 insertions, 79 deletions
diff --git a/lcm/ns/biz/ns_instant.py b/lcm/ns/biz/ns_instant.py
index 9a3fb1d3..706ff3f7 100644
--- a/lcm/ns/biz/ns_instant.py
+++ b/lcm/ns/biz/ns_instant.py
@@ -62,14 +62,27 @@ class InstantNSService(object):
logger.debug('ns-instant(%s) workflow starting...' % self.ns_inst_id)
logger.debug('req_data=%s' % self.req_data)
ns_inst = NSInstModel.objects.get(id=self.ns_inst_id)
- vim_id = ''
-
+ vim_id = {}
+
+ # input_parameters = []
+ # if 'additionalParamForNs' in self.req_data:
+ # for key, val in self.req_data['additionalParamForNs'].items():
+ # input_parameters.append({"key": key, "value": val})
+ # if 'location' in self.req_data['additionalParamForNs']:
+ # vim_id = self.req_data['additionalParamForNs']['location']
+ # params_json = json.JSONEncoder().encode(self.req_data["additionalParamForNs"])
+ # else:
+ # params_json = json.JSONEncoder().encode({})
input_parameters = []
if 'additionalParamForNs' in self.req_data:
for key, val in self.req_data['additionalParamForNs'].items():
input_parameters.append({"key": key, "value": val})
+
if 'location' in self.req_data['additionalParamForNs']:
- vim_id = self.req_data['additionalParamForNs']['location']
+ cloud_owner = self.req_data['additionalParamForNs']['location'].split('_')[0]
+ cloud_regionid = self.req_data["additionalParamForNs"]["location"].split('_')[1]
+ vim_id = {"cloud_owner": cloud_owner, "cloud_regionid": cloud_regionid}
+ logger.info('vim_id::::::::::::%s', type(vim_id))
params_json = json.JSONEncoder().encode(self.req_data["additionalParamForNs"])
else:
params_json = json.JSONEncoder().encode({})
@@ -217,11 +230,27 @@ class InstantNSService(object):
run_ns_instantiate(plan_input, occ_id)
return dict(data={'jobId': job_id}, status=status.HTTP_200_OK, occ_id=occ_id)
+ # @staticmethod
+ # def get_vnf_vim_id(vim_id, location_constraints, vnfdid):
+ # for location in location_constraints:
+ # if "vnfProfileId" in location and vnfdid == location["vnfProfileId"]:
+ # return location["locationConstraints"]["vimId"]
+ # if vim_id:
+ # return vim_id
+ # raise NSLCMException("No Vim info is found for vnf(%s)." % vnfdid)
@staticmethod
def get_vnf_vim_id(vim_id, location_constraints, vnfdid):
for location in location_constraints:
if "vnfProfileId" in location and vnfdid == location["vnfProfileId"]:
- return location["locationConstraints"]["vimId"]
+ if 'vimId' in location['locationConstraints']:
+ cloud_owner = location['locationConstraints']["vimId"].split('_')[0]
+ cloud_regionid = location['locationConstraints']["vimId"].split('_')[1]
+ vim_id = {"cloud_owner": cloud_owner, "cloud_regionid": cloud_regionid}
+ else:
+ cloud_owner = location['locationConstraints']["cloudOwner"]
+ cloud_regionid = location['locationConstraints']["cloudRegionId"]
+ vim_id = {"cloud_owner": cloud_owner, "cloud_regionid": cloud_regionid}
+ return vim_id
if vim_id:
return vim_id
raise NSLCMException("No Vim info is found for vnf(%s)." % vnfdid)
@@ -237,10 +266,23 @@ class InstantNSService(object):
for depend in vnf["dependencies"]:
vl_vnf[depend["vl_id"]] = vnf['properties']['id']
vnf_vim = {}
+ # for location in location_constraints:
+ # if "vnfProfileId" in location:
+ # vnfd_id = location["vnfProfileId"]
+ # vnf_vim[vnfd_id] = location["locationConstraints"]["vimId"]
for location in location_constraints:
if "vnfProfileId" in location:
vnfd_id = location["vnfProfileId"]
- vnf_vim[vnfd_id] = location["locationConstraints"]["vimId"]
+ if 'vimId' in location["locationConstraints"]:
+ cloud_owner = location["locationConstraints"]["vimId"].split('_')[0]
+ cloud_regionid = location["locationConstraints"]["vimId"].split('_')[1]
+ vim_id = {"cloud_owner": cloud_owner, "cloud_regionid": cloud_regionid}
+ vnf_vim[vnfd_id] = vim_id
+ else:
+ cloud_owner = location["locationConstraints"]["cloudOwner"]
+ cloud_regionid = location["locationConstraints"]["cloudRegionId"]
+ vim_id = {"cloud_owner": cloud_owner, "cloud_regionid": cloud_regionid}
+ vnf_vim[vnfd_id] = vim_id
for vl in plan_dict["vls"]:
vnfdid = ignore_case_get(vl_vnf, vl["vl_id"])
vimid = ignore_case_get(vnf_vim, vnfdid)
diff --git a/lcm/ns/biz/ns_lcm_op_occ.py b/lcm/ns/biz/ns_lcm_op_occ.py
index 247a48e3..f808cd2d 100644
--- a/lcm/ns/biz/ns_lcm_op_occ.py
+++ b/lcm/ns/biz/ns_lcm_op_occ.py
@@ -15,7 +15,6 @@
import logging
import datetime
import uuid
-import json
from lcm.pub.database.models import NSLcmOpOccModel
from lcm.pub.utils.values import update_value
@@ -37,7 +36,7 @@ class NsLcmOpOcc(object):
ns_instance_id=nsInstanceId,
operation=lcmOperationType,
is_automatic_invocation=isAutomaticInvocation,
- operation_params=json.dumps(operationParams),
+ operation_params=operationParams,
is_cancel_pending=False
)
logger.debug("lcm_op_occ(%s) create successfully." % lcm_op_occ.id)
diff --git a/lcm/ns/biz/query_ns_lcm_op_occ.py b/lcm/ns/biz/query_ns_lcm_op_occ.py
index b2c96dba..1c8741e3 100644
--- a/lcm/ns/biz/query_ns_lcm_op_occ.py
+++ b/lcm/ns/biz/query_ns_lcm_op_occ.py
@@ -1,5 +1,4 @@
# Copyright (c) 2019, CMCC Technologies Co., Ltd.
-# Copyright (c) 2019, ZTE Corporation.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
diff --git a/lcm/ns/serializers/sol/affected_nss.py b/lcm/ns/serializers/sol/affected_nss.py
index c734ea77..e6a3f6e6 100644
--- a/lcm/ns/serializers/sol/affected_nss.py
+++ b/lcm/ns/serializers/sol/affected_nss.py
@@ -1,5 +1,4 @@
# Copyright (c) 2019, CMCC Technologies Co., Ltd.
-# Copyright 2019 ZTE Corporation.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -47,12 +46,12 @@ class AffectedNssSerializer(serializers.Serializer):
required=True
)
changeType = serializers.ChoiceField(
- help_text="Signals the type of lifecycle change.",
+ help_text="Signals the type of change",
required=True,
choices=CHANGE_TYPE
)
changeResult = serializers.ChoiceField(
- help_text="Signals the result of change identified by the changeType attribute.",
+ help_text="Signals the type of change",
required=True,
choices=CHANGE_RESULT
)
diff --git a/lcm/ns/serializers/sol/affected_pnfs.py b/lcm/ns/serializers/sol/affected_pnfs.py
index 0eb04c77..4b01f6d7 100644
--- a/lcm/ns/serializers/sol/affected_pnfs.py
+++ b/lcm/ns/serializers/sol/affected_pnfs.py
@@ -1,5 +1,4 @@
# Copyright (c) 2019, CMCC Technologies Co., Ltd.
-# Copyright 2019 ZTE Corporation.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -35,24 +34,23 @@ class AffectedPnfsSerializer(serializers.Serializer):
required=True
)
pnfProfileId = serializers.UUIDField(
- help_text="Identifier of the PNF profile of the NSD.",
+ help_text="Identifier of the VNF profile of the NSD.",
required=True
)
pnfName = serializers.CharField(
help_text="Name of the PNF.",
required=True)
- cpInstanceId = serializers.ListField(
- help_text="Identifier of the CP in the scope of the PNF.",
- required=True,
- child=serializers.UUIDField()
+ cpInstanceId = serializers.UUIDField(
+ help_text="Identifier of the NS profile of the NSD.",
+ required=True
)
changeType = serializers.ChoiceField(
- help_text="Signals the type of change.",
+ help_text="Signals the type of change",
required=True,
choices=CHANGE_TYPE
)
changeResult = serializers.ChoiceField(
- help_text="Signals the result of change identified by the changeType attribute.",
+ help_text="Signals the type of change",
required=True,
choices=CHANGE_RESULT
)
diff --git a/lcm/ns/tests/test_ns_instant.py b/lcm/ns/tests/test_ns_instant.py
index 1ccced10..9629da21 100644
--- a/lcm/ns/tests/test_ns_instant.py
+++ b/lcm/ns/tests/test_ns_instant.py
@@ -162,11 +162,11 @@ class TestNsInstant(TestCase):
},
"locationConstraints": [{
"vnfProfileId": "zte_ran_cucp_0001",
- "locationConstraints": {"vimId": "3"}
+ "locationConstraints": {"vimId": '{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}'}
},
{
"vnfProfileId": "zte_ran_cuup_0001",
- "locationConstraints": {"vimId": "3"}
+ "locationConstraints": {"vimId": '{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}'}
}
],
"addpnfData": [{
diff --git a/lcm/ns/tests/test_sol_ns_heal_api.py b/lcm/ns/tests/test_sol_ns_heal_api.py
index adb8c1ec..8ff4ced5 100644
--- a/lcm/ns/tests/test_sol_ns_heal_api.py
+++ b/lcm/ns/tests/test_sol_ns_heal_api.py
@@ -13,7 +13,6 @@
# limitations under the License.
import json
-import uuid
import mock
from django.test import Client
@@ -29,7 +28,7 @@ from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
class TestHealNsApi(TestCase):
def setUp(self):
self.url = "/api/nslcm/v1/ns_instances/%s/heal"
- self.ns_inst_id = str(uuid.uuid4())
+ self.ns_inst_id = '1'
self.nf_inst_id = '1'
self.nf_uuid = '1-1-1'
@@ -94,8 +93,6 @@ class TestHealNsApi(TestCase):
self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.data)
self.assertIsNotNone(response.data)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
# add healNsData
@@ -120,8 +117,6 @@ class TestHealNsApi(TestCase):
response = self.client.post(self.url % self.ns_inst_id, data=data)
self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.data)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
@mock.patch.object(NSHealService, "start")
def test_heal_vnf_non_existing_ns(self, mock_start):
diff --git a/lcm/ns/tests/test_sol_ns_instantiate_api.py b/lcm/ns/tests/test_sol_ns_instantiate_api.py
index 2fdfb025..16d5efaf 100644
--- a/lcm/ns/tests/test_sol_ns_instantiate_api.py
+++ b/lcm/ns/tests/test_sol_ns_instantiate_api.py
@@ -14,7 +14,6 @@
import json
import mock
-import uuid
from mock import MagicMock
from django.test import TestCase
from rest_framework import status
@@ -233,14 +232,14 @@ class TestInstantiateNsApi(TestCase):
self.url = "/api/nslcm/v1/ns_instances/%s/instantiate"
self.req_data = {
"additionalParamForNs": {
- "location": "2"
+ "location": "CPE-DC_RegionOne"
},
"nsFlavourId": 'default',
"localizationLanguage": [{
"vnfProfileId": "vnfd1",
"locationConstraints": {
"countryCode": "countryCode",
- "vimId": "3",
+ # "vimId": "3",
"civicAddressElement": [
{"caType": "type1",
"caValue": 1
@@ -291,8 +290,7 @@ class TestInstantiateNsApi(TestCase):
}]
}
})
- self.nsInstanceId = str(uuid.uuid4())
- NSInstModel(id=self.nsInstanceId, nspackage_id="7", nsd_id="2", status="active").save()
+ NSInstModel(id="2", nspackage_id="7", nsd_id="2", status="active").save()
def tearDown(self):
pass
@@ -307,22 +305,20 @@ class TestInstantiateNsApi(TestCase):
[0, self.vnfms, '200'],
[0, self.vnfm, '200']
]
- response = self.client.post(self.url % self.nsInstanceId, data=self.req_data, format='json')
+ response = self.client.post(self.url % '2', data=self.req_data, format='json')
self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
@mock.patch.object(InstantNSService, 'do_biz')
def test_ns_instantiate_normal(self, mock_do_biz):
mock_do_biz.return_value = {'occ_id': "1"}
- response = self.client.post(self.url % self.nsInstanceId, data=self.req_data, format='json')
- self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+ resp = self.client.post(self.url % '2', data=self.req_data, format='json')
+ self.failUnlessEqual(status.HTTP_202_ACCEPTED, resp.status_code)
@mock.patch.object(restcall, 'call_req')
def test_ns_instantiate_when_fail_to_parse_nsd(self, mock_call_req):
mock_call_req.return_value = [1, "Failed to parse nsd", '500']
- resp = self.client.post(self.url % self.nsInstanceId, data=self.req_data, format='json')
+ resp = self.client.post(self.url % '2', data=self.req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
@mock.patch('lcm.ns.biz.ns_instantiate_flow.post_deal')
@@ -332,8 +328,7 @@ class TestInstantiateNsApi(TestCase):
@mock.patch('lcm.pub.msapi.extsys.select_vnfm', MagicMock(return_value=vnfminfo))
def test_ns_instantiate_with_pnf(self, mock_updata_job, mock_call_req, mock_post_deal):
config.WORKFLOW_OPTION = "grapflow"
- nsInstanceId = str(uuid.uuid4())
- NSInstModel(id=nsInstanceId, name="test_ns", nspackage_id="1", status="created").save()
+ NSInstModel(id="1", name="test_ns", nspackage_id="1", status="created").save()
ret = [0, json.JSONEncoder().encode({'jobId': "1", "responseDescriptor": {"progress": 100}}), '200']
mock_call_req.side_effect = [ret for i in range(1, 20)]
data = {
@@ -344,11 +339,11 @@ class TestInstantiateNsApi(TestCase):
"additionalParamsForVnf": [
{
"vnfProfileId": "zte_ran_cucp_0001",
- "additionalParams": {"vimId": "3"}
+ "additionalParams": {"vimId": '{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}'}
},
{
"vnfProfileId": "zte_ran_cuup_0001",
- "additionalParams": {"vimId": "3"}
+ "additionalParams": {"vimId": '{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}'}
}
],
"addpnfData": [{
@@ -358,20 +353,18 @@ class TestInstantiateNsApi(TestCase):
"pnfProfileId": "du"
}]
}
- response = self.client.post(self.url % nsInstanceId, data=data, format='json')
+ response = self.client.post(self.url % '1', data=data, format='json')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_method_not_allowed(self):
- response = self.client.put(self.url % self.nsInstanceId, data=self.req_data, format='json')
+ response = self.client.put(self.url % '1', data=self.req_data, format='json')
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.client.patch(self.url % self.nsInstanceId, data=self.req_data, format='json')
+ response = self.client.patch(self.url % '1', data=self.req_data, format='json')
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.client.delete(self.url % self.nsInstanceId, data=self.req_data, format='json')
+ response = self.client.delete(self.url % '1', data=self.req_data, format='json')
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.client.get(self.url % self.nsInstanceId, data=self.req_data, format='json')
+ response = self.client.get(self.url % '1', data=self.req_data, format='json')
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
@mock.patch.object(restcall, 'call_req')
@@ -487,8 +480,6 @@ class TestInstantiateNsApi(TestCase):
}
]
}
- response = self.client.post(self.url % self.nsInstanceId, data=req_data, format='json')
+ response = self.client.post(self.url % '2', data=req_data, format='json')
self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
diff --git a/lcm/ns/tests/test_sol_ns_scale_api.py b/lcm/ns/tests/test_sol_ns_scale_api.py
index 9d4ed938..c484a88d 100644
--- a/lcm/ns/tests/test_sol_ns_scale_api.py
+++ b/lcm/ns/tests/test_sol_ns_scale_api.py
@@ -198,8 +198,6 @@ class TestScaleNsApi(TestCase):
response = self.client.post(self.url % self.ns_inst_id, data=data)
self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
@mock.patch.object(NSManualScaleService, 'start')
def test_ns_manual_scale_empty_data(self, mock_start):
diff --git a/lcm/ns/tests/test_sol_ns_terminate_api.py b/lcm/ns/tests/test_sol_ns_terminate_api.py
index 3aa9dc69..44de00e7 100644
--- a/lcm/ns/tests/test_sol_ns_terminate_api.py
+++ b/lcm/ns/tests/test_sol_ns_terminate_api.py
@@ -25,7 +25,7 @@ class TestTerminateNsApi(TestCase):
def setUp(self):
self.client = Client()
self.url = "/api/nslcm/v1/ns_instances/%s/terminate"
- self.ns_inst_id = str(uuid.uuid4())
+ self.ns_inst_id = '1'
self.nf_inst_id = '1'
self.vnffg_id = str(uuid.uuid4())
self.vim_id = str(uuid.uuid4())
@@ -62,8 +62,6 @@ class TestTerminateNsApi(TestCase):
response = self.client.post(self.url % self.ns_inst_id, data=req_data)
self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
self.assertIsNotNone(response['Location'])
- response = self.client.get(response['Location'], format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_method_not_allowed(self):
response = self.client.put(self.url % '1', data={}, format='json')
diff --git a/lcm/ns_vls/biz/create_vls.py b/lcm/ns_vls/biz/create_vls.py
index 3e941d1b..7678a787 100644
--- a/lcm/ns_vls/biz/create_vls.py
+++ b/lcm/ns_vls/biz/create_vls.py
@@ -139,13 +139,15 @@ class CreateVls(object):
return vl_ret[1]
def create_vl_to_resmgr(self):
+ self.vim_id = json.JSONDecoder().decode(self.vim_id) if isinstance(self.vim_id, (str, unicode)) else self.vim_id
+ vim_id = self.vim_id['cloud_owner'] + self.vim_id['cloud_regionid']
req_param = {
"vlInstanceId": self.vl_inst_id,
"name": self.vl_profile.get("networkName", ""),
"backendId": str(self.related_network_id),
"isPublic": "True",
"dcName": "",
- "vimId": str(self.vim_id),
+ "vimId": str(vim_id),
"vimName": self.vim_name,
"physicialNet": self.vl_profile.get("physicalNetwork", ""),
"nsId": self.owner_id,
@@ -190,9 +192,10 @@ class CreateVls(object):
vllist=vl_inst_id_str)
def save_vl_to_db(self):
+ vim_id = json.JSONEncoder().encode(self.vim_id)
VLInstModel(vlinstanceid=self.vl_inst_id, vldid=self.vld_id, vlinstancename=self.vl_inst_name,
ownertype=self.owner_type, ownerid=self.owner_id, relatednetworkid=self.related_network_id,
- relatedsubnetworkid=self.related_subnetwork_id, vimid=self.vim_id, tenant=self.tenant).save()
+ relatedsubnetworkid=self.related_subnetwork_id, vimid=vim_id, tenant=self.tenant).save()
# do_biz_with_share_lock("create-vllist-in-vnffg-%s" % self.owner_id, self.create_vl_inst_id_in_vnffg)
self.create_vl_inst_id_in_vnffg()
diff --git a/lcm/ns_vls/biz/delete_vls.py b/lcm/ns_vls/biz/delete_vls.py
index 9948b7d5..57dc562e 100644
--- a/lcm/ns_vls/biz/delete_vls.py
+++ b/lcm/ns_vls/biz/delete_vls.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import json
import logging
import traceback
@@ -37,7 +38,9 @@ class DeleteVls(object):
logger.info("vl inst id(%s) is not exist or has been already deleted" % self.vl_inst_id)
return {"result": 0, "detail": "vl is not exist or has been already deleted"}
self.ns_inst_id = vl_inst_info[0].ownerid
- vim_id = vl_inst_info[0].vimid
+ # vim_id = vl_inst_info[0].vimid
+ vim_id = json.JSONDecoder().decode(vl_inst_info[0].vimid) if isinstance(vl_inst_info[0].vimid, (str, unicode)) \
+ else vl_inst_info[0].vimid
subnetwork_id_list = vl_inst_info[0].relatedsubnetworkid.split(",")
network_id = vl_inst_info[0].relatednetworkid
self.delete_vl_from_vim(vim_id, subnetwork_id_list, network_id)
diff --git a/lcm/ns_vls/tests/tests.py b/lcm/ns_vls/tests/tests.py
index 0e07fdcd..07eaf18b 100644
--- a/lcm/ns_vls/tests/tests.py
+++ b/lcm/ns_vls/tests/tests.py
@@ -117,7 +117,7 @@ class TestVlDetailViews(TestCase):
self.ns_inst_id = str(uuid.uuid4())
VLInstModel(vlinstanceid=self.vl_inst_id, vldid="", vlinstancename=self.vl_name, ownertype=1,
ownerid=self.ns_inst_id, relatednetworkid="network1", relatedsubnetworkid="subnet1,subnet2",
- vimid="",
+ vimid='{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}',
tenant="").save()
VNFFGInstModel(vnffgdid="", vnffginstid="", nsinstid=self.ns_inst_id,
vllist="test1," + self.vl_inst_id + ",test2,test3", endpointnumber=0, cplist="", vnflist="",
diff --git a/lcm/ns_vnfs/biz/create_vnfs.py b/lcm/ns_vnfs/biz/create_vnfs.py
index e4773920..42bacbd5 100644
--- a/lcm/ns_vnfs/biz/create_vnfs.py
+++ b/lcm/ns_vnfs/biz/create_vnfs.py
@@ -161,13 +161,15 @@ class CreateVnfs(Thread):
'subnetwork_name': subnet_name,
'vl_instance_id': vl_instance_id
})
+ vim_id = json.JSONDecoder().decode(vl_instance.vimid) if isinstance(vl_instance.vimid, (str, unicode)) \
+ else vl_instance.vimid
ext_virtual_link.append({
"vlInstanceId": vl_instance_id,
"resourceId": vl_instance.relatednetworkid,
"resourceSubnetId": vl_instance.relatedsubnetworkid,
"cpdId": self.get_cpd_id_of_vl(network_info['key_name']),
"vim": {
- "vimid": vl_instance.vimid
+ "vimid": vim_id
},
# SOL 003 align
"id": vl_instance_id,
@@ -250,10 +252,13 @@ class CreateVnfs(Thread):
}
if self.vim_id:
- vim_info = self.vim_id.split("_")
+ # vim_info = self.vim_id.split("_")
+ # identifiers = list()
+ # identifiers.append(vim_info[1])
+ # cloudOwner = vim_info[0]
identifiers = list()
- identifiers.append(vim_info[1])
- cloudOwner = vim_info[0]
+ identifiers.append(self.vim_id['cloud_regionid'])
+ cloudOwner = self.vim_id['cloud_owner']
required_candidate = [
{
"identifierType": "vimId",
diff --git a/lcm/ns_vnfs/tests/tests.py b/lcm/ns_vnfs/tests/tests.py
index f0ecc8f4..e2e2f922 100644
--- a/lcm/ns_vnfs/tests/tests.py
+++ b/lcm/ns_vnfs/tests/tests.py
@@ -74,7 +74,8 @@ class TestCreateVnfViews(TestCase):
"vnf_param2": "22"
}),
"vnfminstanceid": "1",
- "vimId": "zte_test"
+ # "vimId": "zte_test"
+ "vimId": '{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}'
}
}
],
@@ -239,7 +240,8 @@ class TestTerminateVnfViews(TestCase):
package_id='pkg1',
vnfd_model=self.vnfd_model)
VmInstModel.objects.create(vmid="1",
- vimid="zte_test",
+ # vimid="zte_test",
+ vimid='{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}',
resouceid="1",
insttype=INST_TYPE.VNF,
instid=self.nf_inst_id,
@@ -694,7 +696,7 @@ class TestGetVnfmInfoViews(TestCase):
class TestGetVimInfoViews(TestCase):
def setUp(self):
self.client = Client()
- self.vim_id = "zte_test"
+ self.vim_id = {"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}
def tearDown(self):
pass
@@ -720,7 +722,8 @@ class TestGetVimInfoViews(TestCase):
"createTime": ""
}
- response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
+ # response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
+ response = self.client.get("/api/nslcm/v1/vims/%s/%s" % (self.vim_id['cloud_owner'], self.vim_id['cloud_regionid']))
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
context = json.loads(response.content)
self.assertEqual(expect_data["url"], context["url"])
diff --git a/lcm/ns_vnfs/urls.py b/lcm/ns_vnfs/urls.py
index 49b4d14e..de1ae6e8 100644
--- a/lcm/ns_vnfs/urls.py
+++ b/lcm/ns_vnfs/urls.py
@@ -29,7 +29,8 @@ urlpatterns = [
url(r'^api/nslcm/v1/ns/ns_vnfs/(?P<vnfinstid>[0-9a-zA-Z_-]+)/scaling$', NfScaleView.as_view()),
url(r'^api/nslcm/v1/vnfonboarding$', NfVerifyView.as_view()),
url(r'^api/nslcm/v1/vnfms/(?P<vnfmid>[0-9a-zA-Z_-]+)', NfVnfmInfoView.as_view()),
- url(r'^api/nslcm/v1/vims/(?P<vimid>[0-9a-zA-Z_-]+)', NfVimInfoView.as_view()),
+ # url(r'^api/nslcm/v1/vims/(?P<vimid>[0-9a-zA-Z_-]+)', NfVimInfoView.as_view()),
+ url(r'^api/nslcm/v1/vims/(?P<cloudowner>[0-9a-zA-Z_-]+)/(?P<cloudregionid>[0-9a-zA-Z_-]+)', NfVimInfoView.as_view()),
# move form v2
url(r'^api/nslcm/v2/grants$', VnfGrantView.as_view()),
diff --git a/lcm/ns_vnfs/views/views.py b/lcm/ns_vnfs/views/views.py
index 5756b8d9..fea09a9e 100644
--- a/lcm/ns_vnfs/views/views.py
+++ b/lcm/ns_vnfs/views/views.py
@@ -21,7 +21,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi.extsys import get_vnfm_by_id, get_vim_by_id
+from lcm.pub.msapi.extsys import get_vnfm_by_id, get_vim_by_id_vim_info
from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
@@ -318,10 +318,12 @@ class NfVimInfoView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
- def get(self, request, vimid):
- logger.debug("NfVimInfoView--get::> %s" % vimid)
+ # def get(self, request, vimid):
+ def get(self, request, cloudowner, cloudregionid):
+ logger.debug("NfVimInfoView--get::> %s,%s" % (cloudowner, cloudregionid))
try:
- vim_info = get_vim_by_id(vimid)
+ # vim_info = get_vim_by_id(vimid)
+ vim_info = get_vim_by_id_vim_info(cloudowner, cloudregionid)
resp_serializer = VimInfoRespSerializer(data=vim_info)
if not resp_serializer.is_valid():
diff --git a/lcm/pub/msapi/extsys.py b/lcm/pub/msapi/extsys.py
index 019f0825..fcb48553 100644
--- a/lcm/pub/msapi/extsys.py
+++ b/lcm/pub/msapi/extsys.py
@@ -38,10 +38,28 @@ def get_vims():
return vims_info
+def get_vim_by_id_vim_info(cloudowner, cloudregionid):
+ cloud_owner = cloudowner
+ cloud_regionid = cloudregionid
+ ret = call_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s?depth=all"
+ % (cloud_owner, cloud_regionid), "GET")
+ if ret[0] != 0:
+ logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+ raise NSLCMException("Failed to query vim(%s__%s) from extsys." % (cloudowner, cloudregionid))
+ # convert vim_info_aai to internal vim_info
+ vim_info_aai = json.JSONDecoder().decode(ret[1])
+ vim_info = convert_vim_info(vim_info_aai)
+ logger.debug("cloud_owner=%s, cloud_regionid=%s, vim_info=%s", cloudowner, cloudregionid, vim_info)
+ return vim_info
+
+
def get_vim_by_id(vim_id):
- cloud_owner, cloud_region = split_vim_to_owner_region(vim_id)
+ # cloud_owner, cloud_region = split_vim_to_owner_region(vim_id)
+ vim_id = json.JSONDecoder().decode(vim_id) if isinstance(vim_id, (str, unicode)) else vim_id
+ cloud_owner = vim_id['cloud_owner']
+ cloud_regionid = vim_id['cloud_regionid']
ret = call_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s?depth=all"
- % (cloud_owner, cloud_region), "GET")
+ % (cloud_owner, cloud_regionid), "GET")
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NSLCMException("Failed to query vim(%s) from extsys." % vim_id)
diff --git a/lcm/pub/nfvi/vim/api/multivim/api.py b/lcm/pub/nfvi/vim/api/multivim/api.py
index 3b73a0f4..7556e9e3 100644
--- a/lcm/pub/nfvi/vim/api/multivim/api.py
+++ b/lcm/pub/nfvi/vim/api/multivim/api.py
@@ -26,10 +26,19 @@ VIM_DRIVER_BASE_URL = "api/multicloud/v0"
def call(vim_id, tenant_id, res, method, data=''):
if data and not isinstance(data, (str, unicode)):
data = json.JSONEncoder().encode(data)
- url = "{base_url}/{vim_id}{tenant_id}/{res}".format(
+ vim_id = json.JSONDecoder().decode(vim_id) if isinstance(vim_id, (str, unicode)) else vim_id
+ cloud_owner = vim_id['cloud_owner']
+ cloud_regionid = vim_id['cloud_regionid']
+ # url = "{base_url}/{vim_id}{tenant_id}/{res}".format(
+ # base_url=VIM_DRIVER_BASE_URL,
+ # vim_id=vim_id,
+ # tenant_id="/" + tenant_id if tenant_id else "",
+ # res=res)
+ url = "{base_url}/{cloud_owner}/{cloud_regionid}/{tenant_id}/{res}".format(
base_url=VIM_DRIVER_BASE_URL,
- vim_id=vim_id,
- tenant_id="/" + tenant_id if tenant_id else "",
+ cloud_owner=cloud_owner,
+ cloud_regionid=cloud_regionid,
+ tenant_id=tenant_id if tenant_id else "",
res=res)
ret = req_by_msb(url, method, data)
if ret[0] > 0: