summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/lcm/nf/biz/__init__.py0
-rw-r--r--lcm/lcm/nf/biz/create_vnf.py (renamed from lcm/lcm/nf/vnf_create/create_vnf_identifier.py)0
-rw-r--r--lcm/lcm/nf/biz/delete_vnf.py (renamed from lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py)0
-rw-r--r--lcm/lcm/nf/biz/instantiate_vnf.py (renamed from lcm/lcm/nf/vnf_create/inst_vnf.py)4
-rw-r--r--lcm/lcm/nf/biz/query_vnf.py (renamed from lcm/lcm/nf/vnf_query/query_vnf.py)0
-rw-r--r--lcm/lcm/nf/biz/terminate_vnf.py (renamed from lcm/lcm/nf/vnf_cancel/term_vnf.py)4
-rw-r--r--lcm/lcm/nf/serializers/__init__.py0
-rw-r--r--lcm/lcm/nf/serializers/common.py (renamed from lcm/lcm/v2/tests/__init__.py)26
-rw-r--r--lcm/lcm/nf/serializers/serializers.py (renamed from lcm/lcm/nf/serializers.py)163
-rw-r--r--lcm/lcm/nf/tests/test_create_vnf.py (renamed from lcm/lcm/v2/tests/test_vnf_create.py)18
-rw-r--r--lcm/lcm/nf/tests/test_delete_vnf.py110
-rw-r--r--lcm/lcm/nf/tests/test_instantiate_vnf.py (renamed from lcm/lcm/nf/tests/test_vnf_create.py)367
-rw-r--r--lcm/lcm/nf/tests/test_query_vnf.py (renamed from lcm/lcm/nf/tests/test_vnf_query.py)0
-rw-r--r--lcm/lcm/nf/tests/test_terminate_vnf.py (renamed from lcm/lcm/nf/tests/test_vnf_cancel.py)328
-rw-r--r--lcm/lcm/nf/urls.py8
-rw-r--r--lcm/lcm/nf/views/__init__.py0
-rw-r--r--lcm/lcm/nf/views/curd_vnf_views.py (renamed from lcm/lcm/nf/views.py)80
-rw-r--r--lcm/lcm/nf/views/instantiate_vnf_view.py62
-rw-r--r--lcm/lcm/nf/views/terminate_vnf_view.py62
-rw-r--r--lcm/lcm/nf/vnf_cancel/__init__.py13
-rw-r--r--lcm/lcm/nf/vnf_create/__init__.py13
-rw-r--r--lcm/lcm/nf/vnf_query/__init__.py13
-rw-r--r--lcm/lcm/urls.py2
-rw-r--r--lcm/lcm/v2/__init__.py13
-rw-r--r--lcm/lcm/v2/serializers.py177
-rw-r--r--lcm/lcm/v2/urls.py21
-rw-r--r--lcm/lcm/v2/views.py88
-rw-r--r--lcm/lcm/v2/vnf_query/__init__.py13
-rw-r--r--lcm/lcm/v2/vnf_query/query_vnf.py146
29 files changed, 750 insertions, 981 deletions
diff --git a/lcm/lcm/nf/biz/__init__.py b/lcm/lcm/nf/biz/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lcm/lcm/nf/biz/__init__.py
diff --git a/lcm/lcm/nf/vnf_create/create_vnf_identifier.py b/lcm/lcm/nf/biz/create_vnf.py
index 34329a52..34329a52 100644
--- a/lcm/lcm/nf/vnf_create/create_vnf_identifier.py
+++ b/lcm/lcm/nf/biz/create_vnf.py
diff --git a/lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/biz/delete_vnf.py
index c0940303..c0940303 100644
--- a/lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py
+++ b/lcm/lcm/nf/biz/delete_vnf.py
diff --git a/lcm/lcm/nf/vnf_create/inst_vnf.py b/lcm/lcm/nf/biz/instantiate_vnf.py
index b87602c9..f47746db 100644
--- a/lcm/lcm/nf/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/biz/instantiate_vnf.py
@@ -31,9 +31,9 @@ from lcm.pub.vimapi import adaptor
logger = logging.getLogger(__name__)
-class InstVnf(Thread):
+class InstantiateVnf(Thread):
def __init__(self, data, nf_inst_id, job_id):
- super(InstVnf, self).__init__()
+ super(InstantiateVnf, self).__init__()
self.data = data
self.nf_inst_id = nf_inst_id
self.job_id = job_id
diff --git a/lcm/lcm/nf/vnf_query/query_vnf.py b/lcm/lcm/nf/biz/query_vnf.py
index 1a6bdd90..1a6bdd90 100644
--- a/lcm/lcm/nf/vnf_query/query_vnf.py
+++ b/lcm/lcm/nf/biz/query_vnf.py
diff --git a/lcm/lcm/nf/vnf_cancel/term_vnf.py b/lcm/lcm/nf/biz/terminate_vnf.py
index 1dd8067f..5d51512f 100644
--- a/lcm/lcm/nf/vnf_cancel/term_vnf.py
+++ b/lcm/lcm/nf/biz/terminate_vnf.py
@@ -30,9 +30,9 @@ from lcm.pub.vimapi import adaptor
logger = logging.getLogger(__name__)
-class TermVnf(Thread):
+class TerminateVnf(Thread):
def __init__(self, data, nf_inst_id, job_id):
- super(TermVnf, self).__init__()
+ super(TerminateVnf, self).__init__()
self.data = data
self.nf_inst_id = nf_inst_id
self.job_id = job_id
diff --git a/lcm/lcm/nf/serializers/__init__.py b/lcm/lcm/nf/serializers/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lcm/lcm/nf/serializers/__init__.py
diff --git a/lcm/lcm/v2/tests/__init__.py b/lcm/lcm/nf/serializers/common.py
index 342c2a8c..ca9a1945 100644
--- a/lcm/lcm/v2/tests/__init__.py
+++ b/lcm/lcm/nf/serializers/common.py
@@ -1,13 +1,13 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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.
+# Copyright 2018 ZTE Corporation.
+#
+# 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.
diff --git a/lcm/lcm/nf/serializers.py b/lcm/lcm/nf/serializers/serializers.py
index 98f68232..d7555c64 100644
--- a/lcm/lcm/nf/serializers.py
+++ b/lcm/lcm/nf/serializers/serializers.py
@@ -451,3 +451,166 @@ class TerminateVnfRequestSerializer(serializers.Serializer):
help_text="gracefulTerminationTimeout",
default=120,
required=False)
+
+
+class VimInfoSerializer(serializers.Serializer):
+ id = serializers.CharField(
+ help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.",
+ required=False,
+ max_length=255,
+ allow_null=True)
+ vimId = serializers.CharField(
+ help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.",
+ required=False,
+ max_length=255,
+ allow_null=True)
+ vimType = serializers.CharField(
+ help_text="Discriminator for the different types of the VIM information.",
+ required=False,
+ max_length=255,
+ allow_null=True)
+ interfaceInfo = serializers.DictField(
+ help_text="Information about the interface or interfaces to the VIM",
+ child=serializers.CharField(allow_blank=True),
+ required=False,
+ allow_null=True)
+ accessInfo = serializers.DictField(
+ help_text="Authentication credentials for accessing the VIM, and other access-related information",
+ child=serializers.CharField(allow_blank=True),
+ required=False,
+ allow_null=True)
+ extra = serializers.DictField(
+ help_text="VIM type specific additional information.",
+ child=serializers.CharField(allow_blank=True),
+ required=False,
+ allow_null=True)
+
+
+class ScaleInfoSerializer(serializers.Serializer):
+ aspectId = serializers.CharField(
+ help_text="Identifier of the scaling aspect.",
+ required=True,
+ max_length=255,
+ allow_null=True)
+ scaleLevel = serializers.IntegerField(
+ help_text="Indicates the scale level.",
+ required=True)
+
+
+class CpProtocolInfoSerializer(serializers.Serializer):
+ layerProtocol = serializers.ChoiceField(
+ help_text="The identifier of layer(s) and protocol(s) associated to the network address information.",
+ choices=["IP_OVER_ETHERNET"],
+ required=False,
+ allow_null=True)
+ ipOverEthernet = serializers.DictField(
+ help_text="IP addresses over Ethernet to assign to the extCP instance.",
+ child=serializers.CharField(allow_blank=True),
+ required=False,
+ allow_null=True)
+
+
+class ExtCpInfoSerializer(serializers.Serializer):
+ id = serializers.CharField(
+ help_text="Identifier of the external CP instance and the related information instance.",
+ required=False,
+ max_length=255,
+ allow_null=True)
+ cpdId = serializers.CharField(
+ help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
+ required=True,
+ max_length=255,
+ allow_null=True)
+ cpProtocolInfo = CpProtocolInfoSerializer(
+ help_text="Network protocol information for this CP.",
+ required=False,
+ allow_null=True)
+ extLinkPortId = serializers.CharField(
+ help_text="Identifier of the 'extLinkPortInfo' structure inside the 'extVirtualLinkInfo' structure.",
+ required=False,
+ max_length=255,
+ allow_null=True)
+
+
+class instantiatedVnfInfoSerializer(serializers.Serializer):
+ flavourId = serializers.CharField(
+ help_text="Identifier of the VNF deployment flavour applied to this VNF instance.",
+ required=True,
+ max_length=255,
+ allow_null=True)
+ vnfState = serializers.ChoiceField(
+ help_text="State of the VNF instance.",
+ choices=["STARTED", "STOPPED"],
+ required=True,
+ allow_null=True)
+ scaleStatus = ScaleInfoSerializer(
+ help_text="Scale status of the VNF, one entry per aspect.",
+ required=False,
+ many=True)
+ extCpInfo = ExtCpInfoSerializer(
+ help_text="Information about the external CPs exposed by the VNF instance.",
+ required=False,
+ many=True)
+
+
+class VnfInstanceSerializer(serializers.Serializer):
+ id = serializers.CharField(
+ help_text="Identifier of the VNF instance",
+ required=True)
+ vnfInstanceName = serializers.CharField(
+ help_text="Name of the VNF instance.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfInstanceDescription = serializers.CharField(
+ help_text="Human-readable description of the VNF instance.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfdId = serializers.CharField(
+ help_text="Identifier of the VNFD on which the VNF instance is based.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfProvider = serializers.CharField(
+ help_text="Provider of the VNF and the VNFD. The value is copied from the VNFD.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfProductName = serializers.CharField(
+ help_text="Name to identify the VNF Product. The value is copied from the VNFD.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfSoftwareVersion = serializers.CharField(
+ help_text="Software version of the VNF. The value is copied from the VNFD.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfdVersion = serializers.CharField(
+ help_text="Identifies the version of the VNFD. The value is copied from the VNFD.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfPkgId = serializers.CharField(
+ help_text="Identifier of information held by the NFVO about the specific VNF package on which the VNF is based.",
+ required=False,
+ allow_null=True,
+ allow_blank=True)
+ vnfConfigurableProperties = serializers.DictField(
+ help_text="Current values of the configurable properties of the VNF instance.",
+ child=serializers.CharField(allow_blank=True),
+ required=False,
+ allow_null=True)
+ vimConnectionInfo = VimInfoSerializer(
+ help_text="Information about VIM connections to be used for managing the resources for the VNF instance.",
+ required=False,
+ allow_null=True)
+ instantiationState = serializers.ChoiceField(
+ help_text="The instantiation state of the VNF.",
+ choices=["NOT_INSTANTIATED", "INSTANTIATED"],
+ required=False,
+ allow_null=True)
+ instantiatedVnfInfo = instantiatedVnfInfoSerializer(
+ help_text="Information specific to an instantiated VNF instance.",
+ required=False)
diff --git a/lcm/lcm/v2/tests/test_vnf_create.py b/lcm/lcm/nf/tests/test_create_vnf.py
index 154b781a..368b22f7 100644
--- a/lcm/lcm/v2/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/tests/test_create_vnf.py
@@ -1,4 +1,4 @@
-# Copyright 2018 ZTE Corporation.
+# Copyright 2017 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ import mock
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient
-
from lcm.nf.const import vnfpackage_info
from lcm.pub.database.models import NfInstModel, JobStatusModel
from lcm.pub.utils import restcall
@@ -29,12 +28,8 @@ class TestNFInstantiate(TestCase):
def setUp(self):
self.client = APIClient()
self.grant_result = {
- "vim": {
- "vimid": 'vimid_1',
- "accessinfo": {
- "tenant": 'tenantname_1'
- }
- }
+ "vimid": 'vimid_1',
+ "tenant": 'tenantname_1'
}
def tearDown(self):
@@ -63,7 +58,7 @@ class TestNFInstantiate(TestCase):
"vnfInstanceName": "vFW_01",
"vnfInstanceDescription": "vFW in Nanjing TIC Edge"
}
- response = self.client.post("/api/vnflcm/v2/vnf_instances", data=data, format='json')
+ response = self.client.post("/api/vnflcm/v1/vnf_instances", data=data, format='json')
self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
context = json.loads(response.content)
self.assertEqual({'error': 'VNF is already exist.'}, context)
@@ -77,8 +72,7 @@ class TestNFInstantiate(TestCase):
"vnfInstanceName": "vFW_01",
"vnfInstanceDescription": "vFW in Nanjing TIC Edge"
}
- response = self.client.post("/api/vnflcm/v2/vnf_instances", data=data, format='json')
+ response = self.client.post("/api/vnflcm/v1/vnf_instances", data=data, format='json')
self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
context = json.loads(response.content)
- self.assertEqual(context['vnfInstanceName'], "vFW_01")
- self.assertTrue(NfInstModel.objects.filter(nfinstid=context['id']).exists())
+ self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstanceId']).exists())
diff --git a/lcm/lcm/nf/tests/test_delete_vnf.py b/lcm/lcm/nf/tests/test_delete_vnf.py
new file mode 100644
index 00000000..26679231
--- /dev/null
+++ b/lcm/lcm/nf/tests/test_delete_vnf.py
@@ -0,0 +1,110 @@
+# Copyright 2017 ZTE Corporation.
+#
+# 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.test import TestCase, Client
+from rest_framework import status
+
+from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \
+ PortInstModel, FlavourInstModel, StorageInstModel, NfvoRegInfoModel
+from lcm.pub.utils.timeutil import now_time
+
+
+class TestNFTerminate(TestCase):
+ def setUp(self):
+ self.client = Client()
+ StorageInstModel.objects.create(storageid="1",
+ vimid="1",
+ resouceid="11",
+ insttype=0,
+ instid="1111",
+ is_predefined=1)
+ NetworkInstModel.objects.create(networkid='1',
+ vimid='1',
+ resouceid='1',
+ name='pnet_network',
+ is_predefined=1,
+ tenant='admin',
+ insttype=0,
+ instid='1111')
+ SubNetworkInstModel.objects.create(subnetworkid='1',
+ vimid='1',
+ resouceid='1',
+ networkid='1',
+ is_predefined=1,
+ name='sub_pnet',
+ tenant='admin',
+ insttype=0,
+ instid='1111')
+ PortInstModel.objects.create(portid='1',
+ networkid='1',
+ subnetworkid='1',
+ vimid='1',
+ resouceid='1',
+ is_predefined=1,
+ name='aaa_pnet_cp',
+ tenant='admin',
+ insttype=0,
+ instid='1111')
+ FlavourInstModel.objects.create(flavourid="1",
+ vimid="1",
+ resouceid="11",
+ instid="1111",
+ is_predefined=1)
+ VmInstModel.objects.create(vmid="1",
+ vimid="1",
+ resouceid="11",
+ insttype=0,
+ instid="1111",
+ vmname="test_01",
+ is_predefined=1,
+ operationalstate=1)
+ NfvoRegInfoModel.objects.create(nfvoid='1111',
+ vnfminstid='11111',
+ apiurl='1')
+
+ def tearDown(self):
+ VmInstModel.objects.all().delete()
+ NetworkInstModel.objects.all().delete()
+ SubNetworkInstModel.objects.all().delete()
+ PortInstModel.objects.all().delete()
+
+ def assert_job_result(self, job_id, job_progress, job_detail):
+ jobs = JobStatusModel.objects.filter(jobid=job_id,
+ progress=job_progress,
+ descp=job_detail)
+ self.assertEqual(1, len(jobs))
+
+ def test_delete_vnf_identifier(self):
+ NfInstModel.objects.create(nfinstid='1111',
+ nf_name='2222',
+ package_id='todo',
+ version='',
+ vendor='',
+ netype='',
+ vnfd_model='',
+ status='NOT_INSTANTIATED',
+ nf_desc='',
+ vnfdid='',
+ vnfSoftwareVersion='',
+ vnfConfigurableProperties='todo',
+ localizationLanguage='EN_US',
+ create_time=now_time())
+ response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111")
+ self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)
+ self.assertEqual(None, response.data)
+
+ def test_delete_vnf_identifier_when_vnf_not_exist(self):
+ response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111")
+ self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)
diff --git a/lcm/lcm/nf/tests/test_vnf_create.py b/lcm/lcm/nf/tests/test_instantiate_vnf.py
index 5a017499..7cf2646f 100644
--- a/lcm/lcm/nf/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/tests/test_instantiate_vnf.py
@@ -1,201 +1,166 @@
-# Copyright 2017 ZTE Corporation.
-#
-# 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.
-
-import json
-import uuid
-
-import mock
-from django.test import TestCase
-from rest_framework import status
-from rest_framework.test import APIClient
-
-from lcm.nf.const import c1_data_get_tenant_id, c4_data_create_network, c2_data_create_volume, \
- c5_data_create_subnet, c3_data_get_volume, c6_data_create_port, c7_data_create_flavor, c8_data_list_image, \
- c9_data_create_vm, c10_data_get_vm, inst_req_data, vnfpackage_info
-from lcm.nf.vnf_create.inst_vnf import InstVnf
-from lcm.pub.database.models import NfInstModel, JobStatusModel
-from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JobUtil
-from lcm.pub.utils.timeutil import now_time
-from lcm.pub.vimapi import api
-
-
-class TestNFInstantiate(TestCase):
- def setUp(self):
- self.client = APIClient()
- self.grant_result = {
- "vimid": 'vimid_1',
- "tenant": 'tenantname_1'
- }
-
- def tearDown(self):
- pass
-
- def assert_job_result(self, job_id, job_progress, job_detail):
- jobs = JobStatusModel.objects.filter(jobid=job_id,
- progress=job_progress,
- descp=job_detail)
- self.assertEqual(1, len(jobs))
-
- def test_create_vnf_identifier_when_vnf_is_exist(self):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='vFW_01',
- package_id='222',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='NOT_INSTANTIATED',
- nf_desc='vFW in Nanjing TIC Edge',
- vnfdid='111',
- create_time=now_time())
- data = {
- "vnfdId": "111",
- "vnfInstanceName": "vFW_01",
- "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
- }
- response = self.client.post("/api/vnflcm/v1/vnf_instances", data=data, format='json')
- self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
- context = json.loads(response.content)
- self.assertEqual({'error': 'VNF is already exist.'}, context)
-
- @mock.patch.object(restcall, 'call_req')
- def test_create_vnf_identifier(self, mock_call_req):
- r2_get_vnfpackage_from_catalog = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
- mock_call_req.side_effect = [r2_get_vnfpackage_from_catalog]
- data = {
- "vnfdId": "111",
- "vnfInstanceName": "vFW_01",
- "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
- }
- response = self.client.post("/api/vnflcm/v1/vnf_instances", data=data, format='json')
- self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
- context = json.loads(response.content)
- self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstanceId']).exists())
-
- @mock.patch.object(InstVnf, 'run')
- def test_instantiate_vnf(self, mock_run):
- mock_run.re.return_value = None
- response = self.client.post("/api/vnflcm/v1/vnf_instances/12/instantiate", data=inst_req_data, format='json')
- self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
-
- def test_instantiate_vnf_when_inst_id_not_exist(self):
- self.nf_inst_id = str(uuid.uuid4())
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- jobs = JobStatusModel.objects.filter(jobid=self.job_id,
- progress=0,
- descp="INST_VNF_READY")
- self.assertEqual(1, len(jobs))
- data = inst_req_data
- InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 255, "VNF nf_inst_id is not exist.")
-
- @mock.patch.object(restcall, 'call_req')
- def test_instantiate_vnf_when_get_packageinfo_by_csarid_failed(self, mock_call_req):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='vFW_01',
- package_id='222',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='NOT_INSTANTIATED',
- nf_desc='vFW in Nanjing TIC Edge',
- vnfdid='111',
- create_time=now_time())
- r1_get_vnfpackage_by_vnfdid = [1, json.JSONEncoder().encode(vnfpackage_info), '200']
- mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid]
- self.nf_inst_id = '1111'
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- data = inst_req_data
- InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 255, "Failed to query vnf CSAR(111) from catalog.")
-
- @mock.patch.object(restcall, 'call_req')
- def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='vFW_01',
- package_id='222',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='NOT_INSTANTIATED',
- nf_desc='vFW in Nanjing TIC Edge',
- vnfdid='111',
- create_time=now_time())
- r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
- r2_apply_grant_result = [1, json.JSONEncoder().encode(self.grant_result), '200']
- mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]
- self.nf_inst_id = '1111'
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- data = inst_req_data
- InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 255, "Nf instancing apply grant exception")
-
- @mock.patch.object(restcall, 'call_req')
- @mock.patch.object(api, 'call')
- def test_instantiate_vnf_when_unexpected_exception(self, mock_call, mock_call_req):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='vFW_01',
- package_id='222',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='NOT_INSTANTIATED',
- nf_desc='vFW in Nanjing TIC Edge',
- vnfdid='111',
- create_time=now_time())
- r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
- r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
- mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]
- mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume]
- self.nf_inst_id = '1111'
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- data = inst_req_data
- InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 255, "unexpected exception")
-
- @mock.patch.object(restcall, 'call_req')
- @mock.patch.object(api, 'call')
- def test_instantiate_vnf_success(self, mock_call, mock_call_req):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='vFW_01',
- package_id='222',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='NOT_INSTANTIATED',
- nf_desc='vFW in Nanjing TIC Edge',
- vnfdid='111',
- create_time=now_time())
- r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
- r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
- r3_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
- mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result, r3_lcm_notify_result]
- mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume,
- c4_data_create_network, c5_data_create_subnet, c6_data_create_port,
- c7_data_create_flavor, c8_data_list_image, c9_data_create_vm, c10_data_get_vm]
- self.nf_inst_id = '1111'
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- data = inst_req_data
- InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 100, "Instantiate Vnf success.")
+# Copyright 2017 ZTE Corporation.
+#
+# 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.
+
+import json
+import uuid
+
+import mock
+from django.test import TestCase
+from rest_framework import status
+from rest_framework.test import APIClient
+
+from lcm.nf.biz.instantiate_vnf import InstantiateVnf
+from lcm.nf.const import c1_data_get_tenant_id, c4_data_create_network, c2_data_create_volume, \
+ c5_data_create_subnet, c3_data_get_volume, c6_data_create_port, c7_data_create_flavor, c8_data_list_image, \
+ c9_data_create_vm, c10_data_get_vm, inst_req_data, vnfpackage_info
+from lcm.pub.database.models import NfInstModel, JobStatusModel
+from lcm.pub.utils import restcall
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.utils.timeutil import now_time
+from lcm.pub.vimapi import api
+
+
+class TestNFInstantiate(TestCase):
+ def setUp(self):
+ self.client = APIClient()
+ self.grant_result = {
+ "vimid": 'vimid_1',
+ "tenant": 'tenantname_1'
+ }
+
+ def tearDown(self):
+ pass
+
+ def assert_job_result(self, job_id, job_progress, job_detail):
+ jobs = JobStatusModel.objects.filter(jobid=job_id,
+ progress=job_progress,
+ descp=job_detail)
+ self.assertEqual(1, len(jobs))
+
+ @mock.patch.object(InstantiateVnf, 'run')
+ def test_instantiate_vnf(self, mock_run):
+ NfInstModel(nfinstid='12', nf_name='VNF1').save()
+ mock_run.re.return_value = None
+ response = self.client.post("/api/vnflcm/v1/vnf_instances/12/instantiate", data=inst_req_data, format='json')
+ self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+
+ def test_instantiate_vnf_when_inst_id_not_exist(self):
+ self.nf_inst_id = str(uuid.uuid4())
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ jobs = JobStatusModel.objects.filter(jobid=self.job_id,
+ progress=0,
+ descp="INST_VNF_READY")
+ self.assertEqual(1, len(jobs))
+ data = inst_req_data
+ InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 255, "VNF nf_inst_id is not exist.")
+
+ @mock.patch.object(restcall, 'call_req')
+ def test_instantiate_vnf_when_get_packageinfo_by_csarid_failed(self, mock_call_req):
+ NfInstModel.objects.create(nfinstid='1111',
+ nf_name='vFW_01',
+ package_id='222',
+ version='',
+ vendor='',
+ netype='',
+ vnfd_model='',
+ status='NOT_INSTANTIATED',
+ nf_desc='vFW in Nanjing TIC Edge',
+ vnfdid='111',
+ create_time=now_time())
+ r1_get_vnfpackage_by_vnfdid = [1, json.JSONEncoder().encode(vnfpackage_info), '200']
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid]
+ self.nf_inst_id = '1111'
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ data = inst_req_data
+ InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 255, "Failed to query vnf CSAR(111) from catalog.")
+
+ @mock.patch.object(restcall, 'call_req')
+ def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req):
+ NfInstModel.objects.create(nfinstid='1111',
+ nf_name='vFW_01',
+ package_id='222',
+ version='',
+ vendor='',
+ netype='',
+ vnfd_model='',
+ status='NOT_INSTANTIATED',
+ nf_desc='vFW in Nanjing TIC Edge',
+ vnfdid='111',
+ create_time=now_time())
+ r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
+ r2_apply_grant_result = [1, json.JSONEncoder().encode(self.grant_result), '200']
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]
+ self.nf_inst_id = '1111'
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ data = inst_req_data
+ InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 255, "Nf instancing apply grant exception")
+
+ @mock.patch.object(restcall, 'call_req')
+ @mock.patch.object(api, 'call')
+ def test_instantiate_vnf_when_unexpected_exception(self, mock_call, mock_call_req):
+ NfInstModel.objects.create(nfinstid='1111',
+ nf_name='vFW_01',
+ package_id='222',
+ version='',
+ vendor='',
+ netype='',
+ vnfd_model='',
+ status='NOT_INSTANTIATED',
+ nf_desc='vFW in Nanjing TIC Edge',
+ vnfdid='111',
+ create_time=now_time())
+ r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
+ r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]
+ mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume]
+ self.nf_inst_id = '1111'
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ data = inst_req_data
+ InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 255, "unexpected exception")
+
+ @mock.patch.object(restcall, 'call_req')
+ @mock.patch.object(api, 'call')
+ def test_instantiate_vnf_success(self, mock_call, mock_call_req):
+ NfInstModel.objects.create(nfinstid='1111',
+ nf_name='vFW_01',
+ package_id='222',
+ version='',
+ vendor='',
+ netype='',
+ vnfd_model='',
+ status='NOT_INSTANTIATED',
+ nf_desc='vFW in Nanjing TIC Edge',
+ vnfdid='111',
+ create_time=now_time())
+ r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
+ r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
+ r3_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result, r3_lcm_notify_result]
+ mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume,
+ c4_data_create_network, c5_data_create_subnet, c6_data_create_port,
+ c7_data_create_flavor, c8_data_list_image, c9_data_create_vm, c10_data_get_vm]
+ self.nf_inst_id = '1111'
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ data = inst_req_data
+ InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 100, "Instantiate Vnf success.")
diff --git a/lcm/lcm/nf/tests/test_vnf_query.py b/lcm/lcm/nf/tests/test_query_vnf.py
index 991583e7..991583e7 100644
--- a/lcm/lcm/nf/tests/test_vnf_query.py
+++ b/lcm/lcm/nf/tests/test_query_vnf.py
diff --git a/lcm/lcm/nf/tests/test_vnf_cancel.py b/lcm/lcm/nf/tests/test_terminate_vnf.py
index ef0c7cf2..0136862a 100644
--- a/lcm/lcm/nf/tests/test_vnf_cancel.py
+++ b/lcm/lcm/nf/tests/test_terminate_vnf.py
@@ -1,175 +1,153 @@
-# Copyright 2017 ZTE Corporation.
-#
-# 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.
-
-
-import json
-import uuid
-
-import mock
-from django.test import TestCase, Client
-from rest_framework import status
-
-from lcm.nf.vnf_cancel.term_vnf import TermVnf
-from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \
- PortInstModel, FlavourInstModel, StorageInstModel, NfvoRegInfoModel
-from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JobUtil
-from lcm.pub.utils.timeutil import now_time
-from lcm.pub.vimapi import api
-
-
-class TestNFTerminate(TestCase):
- def setUp(self):
- self.client = Client()
- StorageInstModel.objects.create(storageid="1",
- vimid="1",
- resouceid="11",
- insttype=0,
- instid="1111",
- is_predefined=1)
- NetworkInstModel.objects.create(networkid='1',
- vimid='1',
- resouceid='1',
- name='pnet_network',
- is_predefined=1,
- tenant='admin',
- insttype=0,
- instid='1111')
- SubNetworkInstModel.objects.create(subnetworkid='1',
- vimid='1',
- resouceid='1',
- networkid='1',
- is_predefined=1,
- name='sub_pnet',
- tenant='admin',
- insttype=0,
- instid='1111')
- PortInstModel.objects.create(portid='1',
- networkid='1',
- subnetworkid='1',
- vimid='1',
- resouceid='1',
- is_predefined=1,
- name='aaa_pnet_cp',
- tenant='admin',
- insttype=0,
- instid='1111')
- FlavourInstModel.objects.create(flavourid="1",
- vimid="1",
- resouceid="11",
- instid="1111",
- is_predefined=1)
- VmInstModel.objects.create(vmid="1",
- vimid="1",
- resouceid="11",
- insttype=0,
- instid="1111",
- vmname="test_01",
- is_predefined=1,
- operationalstate=1)
- NfvoRegInfoModel.objects.create(nfvoid='1111',
- vnfminstid='11111',
- apiurl='1')
-
- def tearDown(self):
- VmInstModel.objects.all().delete()
- NetworkInstModel.objects.all().delete()
- SubNetworkInstModel.objects.all().delete()
- PortInstModel.objects.all().delete()
-
- def assert_job_result(self, job_id, job_progress, job_detail):
- jobs = JobStatusModel.objects.filter(jobid=job_id,
- progress=job_progress,
- descp=job_detail)
- self.assertEqual(1, len(jobs))
-
- def test_delete_vnf_identifier(self):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='2222',
- package_id='todo',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='NOT_INSTANTIATED',
- nf_desc='',
- vnfdid='',
- vnfSoftwareVersion='',
- vnfConfigurableProperties='todo',
- localizationLanguage='EN_US',
- create_time=now_time())
- response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111")
- self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)
- self.assertEqual(None, response.data)
-
- def test_delete_vnf_identifier_when_vnf_not_exist(self):
- response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111")
- self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)
-
- @mock.patch.object(TermVnf, 'run')
- def test_terminate_vnf(self, mock_run):
- req_data = {
- "terminationType": "GRACEFUL",
- "gracefulTerminationTimeout": 120
- }
- mock_run.re.return_value = None
- response = self.client.post("/api/vnflcm/v1/vnf_instances/12/terminate", data=req_data, format='json')
- self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
-
- def test_terminate_vnf_when_inst_id_not_exist(self):
- data = {
- "terminationType": "GRACEFUL",
- "gracefulTerminationTimeout": 120
- }
- self.nf_inst_id = str(uuid.uuid4())
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")
-
- @mock.patch.object(restcall, 'call_req')
- @mock.patch.object(api, 'call')
- def test_terminate_vnf_success(self, mock_call, mock_call_req):
- NfInstModel.objects.create(nfinstid='1111',
- nf_name='2222',
- package_id='todo',
- version='',
- vendor='',
- netype='',
- vnfd_model='',
- status='VNF_INSTANTIATED',
- nf_desc='',
- vnfdid='',
- vnfSoftwareVersion='',
- vnfConfigurableProperties='todo',
- localizationLanguage='EN_US',
- create_time=now_time())
- t1_apply_grant_result = [0, json.JSONEncoder().encode(
- {
- "vimid": 'vimid_1',
- "tenant": 'tenantname_1'
- }), '200']
- t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
- t3_delete_flavor = [0, json.JSONEncoder().encode({"vim_id": "vimid_1"}), '200']
- mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_delete_flavor]
- mock_call.return_value = None
- data = {
- "terminationType": "FORCEFUL",
- "gracefulTerminationTimeout": 120
- }
- self.nf_inst_id = '1111'
- self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
- JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
- TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")
+# Copyright 2017 ZTE Corporation.
+#
+# 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.
+
+
+import json
+import uuid
+
+import mock
+from django.test import TestCase, Client
+from rest_framework import status
+
+from lcm.nf.biz.terminate_vnf import TerminateVnf
+from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \
+ PortInstModel, FlavourInstModel, StorageInstModel, NfvoRegInfoModel
+from lcm.pub.utils import restcall
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.utils.timeutil import now_time
+from lcm.pub.vimapi import api
+
+
+class TestNFTerminate(TestCase):
+ def setUp(self):
+ self.client = Client()
+ StorageInstModel.objects.create(storageid="1",
+ vimid="1",
+ resouceid="11",
+ insttype=0,
+ instid="1111",
+ is_predefined=1)
+ NetworkInstModel.objects.create(networkid='1',
+ vimid='1',
+ resouceid='1',
+ name='pnet_network',
+ is_predefined=1,
+ tenant='admin',
+ insttype=0,
+ instid='1111')
+ SubNetworkInstModel.objects.create(subnetworkid='1',
+ vimid='1',
+ resouceid='1',
+ networkid='1',
+ is_predefined=1,
+ name='sub_pnet',
+ tenant='admin',
+ insttype=0,
+ instid='1111')
+ PortInstModel.objects.create(portid='1',
+ networkid='1',
+ subnetworkid='1',
+ vimid='1',
+ resouceid='1',
+ is_predefined=1,
+ name='aaa_pnet_cp',
+ tenant='admin',
+ insttype=0,
+ instid='1111')
+ FlavourInstModel.objects.create(flavourid="1",
+ vimid="1",
+ resouceid="11",
+ instid="1111",
+ is_predefined=1)
+ VmInstModel.objects.create(vmid="1",
+ vimid="1",
+ resouceid="11",
+ insttype=0,
+ instid="1111",
+ vmname="test_01",
+ is_predefined=1,
+ operationalstate=1)
+ NfvoRegInfoModel.objects.create(nfvoid='1111',
+ vnfminstid='11111',
+ apiurl='1')
+
+ def tearDown(self):
+ VmInstModel.objects.all().delete()
+ NetworkInstModel.objects.all().delete()
+ SubNetworkInstModel.objects.all().delete()
+ PortInstModel.objects.all().delete()
+
+ def assert_job_result(self, job_id, job_progress, job_detail):
+ jobs = JobStatusModel.objects.filter(jobid=job_id,
+ progress=job_progress,
+ descp=job_detail)
+ self.assertEqual(1, len(jobs))
+
+ @mock.patch.object(TerminateVnf, 'run')
+ def test_terminate_vnf(self, mock_run):
+ req_data = {
+ "terminationType": "GRACEFUL",
+ "gracefulTerminationTimeout": 120
+ }
+ NfInstModel(nfinstid='12', nf_name='VNF1').save()
+ mock_run.re.return_value = None
+ response = self.client.post("/api/vnflcm/v1/vnf_instances/12/terminate", data=req_data, format='json')
+ self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+
+ def test_terminate_vnf_when_inst_id_not_exist(self):
+ data = {
+ "terminationType": "GRACEFUL",
+ "gracefulTerminationTimeout": 120
+ }
+ self.nf_inst_id = str(uuid.uuid4())
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ TerminateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")
+
+ @mock.patch.object(restcall, 'call_req')
+ @mock.patch.object(api, 'call')
+ def test_terminate_vnf_success(self, mock_call, mock_call_req):
+ NfInstModel.objects.create(nfinstid='1111',
+ nf_name='2222',
+ package_id='todo',
+ version='',
+ vendor='',
+ netype='',
+ vnfd_model='',
+ status='VNF_INSTANTIATED',
+ nf_desc='',
+ vnfdid='',
+ vnfSoftwareVersion='',
+ vnfConfigurableProperties='todo',
+ localizationLanguage='EN_US',
+ create_time=now_time())
+ t1_apply_grant_result = [0, json.JSONEncoder().encode(
+ {
+ "vimid": 'vimid_1',
+ "tenant": 'tenantname_1'
+ }), '200']
+ t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
+ t3_delete_flavor = [0, json.JSONEncoder().encode({"vim_id": "vimid_1"}), '200']
+ mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_delete_flavor]
+ mock_call.return_value = None
+ data = {
+ "terminationType": "FORCEFUL",
+ "gracefulTerminationTimeout": 120
+ }
+ self.nf_inst_id = '1111'
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ TerminateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")
diff --git a/lcm/lcm/nf/urls.py b/lcm/lcm/nf/urls.py
index e59286a5..f279b551 100644
--- a/lcm/lcm/nf/urls.py
+++ b/lcm/lcm/nf/urls.py
@@ -14,11 +14,13 @@
from django.conf.urls import url
-from lcm.nf.views import InstantiateVnf, TerminateVnf, DeleteVnfAndQueryVnf, CreateVnfAndQueryVnfs
+from lcm.nf.views.curd_vnf_views import DeleteVnfAndQueryVnf, CreateVnfAndQueryVnfs
+from lcm.nf.views.instantiate_vnf_view import InstantiateVnfView
+from lcm.nf.views.terminate_vnf_view import TerminateVnfView
urlpatterns = [
url(r'^api/vnflcm/v1/vnf_instances$', CreateVnfAndQueryVnfs.as_view()),
- url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/instantiate$', InstantiateVnf.as_view()),
+ url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/instantiate$', InstantiateVnfView.as_view()),
url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)$', DeleteVnfAndQueryVnf.as_view()),
- url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/terminate$', TerminateVnf.as_view()),
+ url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/terminate$', TerminateVnfView.as_view()),
]
diff --git a/lcm/lcm/nf/views/__init__.py b/lcm/lcm/nf/views/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lcm/lcm/nf/views/__init__.py
diff --git a/lcm/lcm/nf/views.py b/lcm/lcm/nf/views/curd_vnf_views.py
index 0db9d5fa..16d082c6 100644
--- a/lcm/lcm/nf/views.py
+++ b/lcm/lcm/nf/views/curd_vnf_views.py
@@ -16,19 +16,16 @@ import logging
import traceback
from drf_yasg.utils import swagger_auto_schema
+from lcm.nf.biz.delete_vnf import DeleteVnf
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
-from lcm.nf.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer, VnfsInfoSerializer, \
- InstOrTeriVnfResponseSerializer, InstantiateVnfRequestSerializer, VnfInfoSerializer, TerminateVnfRequestSerializer
-from lcm.nf.vnf_cancel.delete_vnf_identifier import DeleteVnf
-from lcm.nf.vnf_cancel.term_vnf import TermVnf
-from lcm.nf.vnf_create.create_vnf_identifier import CreateVnf
-from lcm.nf.vnf_create.inst_vnf import InstVnf
-from lcm.nf.vnf_query.query_vnf import QueryVnf
+from lcm.nf.biz.create_vnf import CreateVnf
+from lcm.nf.biz.query_vnf import QueryVnf
+from lcm.nf.serializers.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer, VnfsInfoSerializer, \
+ VnfInfoSerializer
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.utils.jobutil import JobUtil
logger = logging.getLogger(__name__)
@@ -88,40 +85,6 @@ class CreateVnfAndQueryVnfs(APIView):
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-class InstantiateVnf(APIView):
- @swagger_auto_schema(
- request_body=InstantiateVnfRequestSerializer(),
- responses={
- status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
- }
- )
- def post(self, request, instanceid):
- logger.debug("InstantiateVnf--post::> %s" % request.data)
- try:
- instantiate_vnf_request_serializer = InstantiateVnfRequestSerializer(data=request.data)
- if not instantiate_vnf_request_serializer.is_valid():
- raise NFLCMException(instantiate_vnf_request_serializer.errors)
-
- job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid)
- JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
- InstVnf(instantiate_vnf_request_serializer.data, instanceid, job_id).start()
-
- instantiate_vnf_response_serializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})
- resp_isvalid = instantiate_vnf_response_serializer.is_valid()
- if not resp_isvalid:
- raise NFLCMException(instantiate_vnf_response_serializer.errors)
-
- return Response(data=instantiate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
-
class DeleteVnfAndQueryVnf(APIView):
@swagger_auto_schema(
responses={
@@ -167,36 +130,3 @@ class DeleteVnfAndQueryVnf(APIView):
logger.error(e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
-
-class TerminateVnf(APIView):
- @swagger_auto_schema(
- request_body=TerminateVnfRequestSerializer(),
- responses={
- status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
- }
- )
- def post(self, request, instanceid):
- logger.debug("TerminateVnf--post::> %s" % request.data)
- try:
- terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)
- if not terminate_vnf_request_serializer.is_valid():
- raise NFLCMException(terminate_vnf_request_serializer.errors)
-
- job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)
- JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")
- TermVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()
-
- terminate_vnf_response_serializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})
- if not terminate_vnf_response_serializer.is_valid():
- raise NFLCMException(terminate_vnf_response_serializer.errors)
-
- return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/lcm/lcm/nf/views/instantiate_vnf_view.py b/lcm/lcm/nf/views/instantiate_vnf_view.py
new file mode 100644
index 00000000..3e9c334d
--- /dev/null
+++ b/lcm/lcm/nf/views/instantiate_vnf_view.py
@@ -0,0 +1,62 @@
+# Copyright 2017 ZTE Corporation.
+#
+# 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.
+
+import logging
+import traceback
+
+from drf_yasg.utils import swagger_auto_schema
+from lcm.nf.biz.instantiate_vnf import InstantiateVnf
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from lcm.nf.serializers.serializers import InstOrTeriVnfResponseSerializer, InstantiateVnfRequestSerializer
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.utils.jobutil import JobUtil
+
+logger = logging.getLogger(__name__)
+
+
+class InstantiateVnfView(APIView):
+ @swagger_auto_schema(
+ request_body=InstantiateVnfRequestSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
+ def post(self, request, instanceid):
+ logger.debug("InstantiateVnf--post::> %s" % request.data)
+ try:
+ instantiate_vnf_request_serializer = InstantiateVnfRequestSerializer(data=request.data)
+ if not instantiate_vnf_request_serializer.is_valid():
+ raise NFLCMException(instantiate_vnf_request_serializer.errors)
+
+ job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid)
+ JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
+ InstantiateVnf(instantiate_vnf_request_serializer.data, instanceid, job_id).start()
+
+ instantiate_vnf_response_serializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})
+ resp_isvalid = instantiate_vnf_response_serializer.is_valid()
+ if not resp_isvalid:
+ raise NFLCMException(instantiate_vnf_response_serializer.errors)
+
+ return Response(data=instantiate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)
+ except NFLCMException as e:
+ logger.error(e.message)
+ return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except Exception as e:
+ logger.error(e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/lcm/lcm/nf/views/terminate_vnf_view.py b/lcm/lcm/nf/views/terminate_vnf_view.py
new file mode 100644
index 00000000..8cd26467
--- /dev/null
+++ b/lcm/lcm/nf/views/terminate_vnf_view.py
@@ -0,0 +1,62 @@
+# Copyright 2017 ZTE Corporation.
+#
+# 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.
+
+import logging
+import traceback
+
+from drf_yasg.utils import swagger_auto_schema
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from lcm.nf.biz.terminate_vnf import TerminateVnf
+from lcm.nf.serializers.serializers import InstOrTeriVnfResponseSerializer, TerminateVnfRequestSerializer
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.utils.jobutil import JobUtil
+
+
+logger = logging.getLogger(__name__)
+
+
+class TerminateVnfView(APIView):
+ @swagger_auto_schema(
+ request_body=TerminateVnfRequestSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
+ def post(self, request, instanceid):
+ logger.debug("TerminateVnf--post::> %s" % request.data)
+ try:
+ terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)
+ if not terminate_vnf_request_serializer.is_valid():
+ raise NFLCMException(terminate_vnf_request_serializer.errors)
+
+ job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)
+ JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")
+ TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()
+
+ terminate_vnf_response_serializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})
+ if not terminate_vnf_response_serializer.is_valid():
+ raise NFLCMException(terminate_vnf_response_serializer.errors)
+
+ return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)
+ except NFLCMException as e:
+ logger.error(e.message)
+ return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except Exception as e:
+ logger.error(e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/lcm/lcm/nf/vnf_cancel/__init__.py b/lcm/lcm/nf/vnf_cancel/__init__.py
deleted file mode 100644
index c7b6818e..00000000
--- a/lcm/lcm/nf/vnf_cancel/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017 ZTE Corporation.
-#
-# 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.
diff --git a/lcm/lcm/nf/vnf_create/__init__.py b/lcm/lcm/nf/vnf_create/__init__.py
deleted file mode 100644
index c7b6818e..00000000
--- a/lcm/lcm/nf/vnf_create/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017 ZTE Corporation.
-#
-# 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.
diff --git a/lcm/lcm/nf/vnf_query/__init__.py b/lcm/lcm/nf/vnf_query/__init__.py
deleted file mode 100644
index c7b6818e..00000000
--- a/lcm/lcm/nf/vnf_query/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017 ZTE Corporation.
-#
-# 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.
diff --git a/lcm/lcm/urls.py b/lcm/lcm/urls.py
index 6226e522..ea213ad6 100644
--- a/lcm/lcm/urls.py
+++ b/lcm/lcm/urls.py
@@ -18,7 +18,7 @@ from lcm.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG
urlpatterns = [
url(r'^', include('lcm.samples.urls')),
url(r'^', include('lcm.nf.urls')),
- url(r'^', include('lcm.v2.urls')),
+ # url(r'^', include('lcm.v2.urls')),
url(r'^', include('lcm.jobs.urls')),
url(r'^', include('lcm.swagger.urls')),
]
diff --git a/lcm/lcm/v2/__init__.py b/lcm/lcm/v2/__init__.py
deleted file mode 100644
index 342c2a8c..00000000
--- a/lcm/lcm/v2/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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.
diff --git a/lcm/lcm/v2/serializers.py b/lcm/lcm/v2/serializers.py
deleted file mode 100644
index 3aaad319..00000000
--- a/lcm/lcm/v2/serializers.py
+++ /dev/null
@@ -1,177 +0,0 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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 rest_framework import serializers
-
-
-class VimInfoSerializer(serializers.Serializer):
- id = serializers.CharField(
- help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.",
- required=False,
- max_length=255,
- allow_null=True)
- vimId = serializers.CharField(
- help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.",
- required=False,
- max_length=255,
- allow_null=True)
- vimType = serializers.CharField(
- help_text="Discriminator for the different types of the VIM information.",
- required=False,
- max_length=255,
- allow_null=True)
- interfaceInfo = serializers.DictField(
- help_text="Information about the interface or interfaces to the VIM",
- child=serializers.CharField(allow_blank=True),
- required=False,
- allow_null=True)
- accessInfo = serializers.DictField(
- help_text="Authentication credentials for accessing the VIM, and other access-related information",
- child=serializers.CharField(allow_blank=True),
- required=False,
- allow_null=True)
- extra = serializers.DictField(
- help_text="VIM type specific additional information.",
- child=serializers.CharField(allow_blank=True),
- required=False,
- allow_null=True)
-
-
-class ScaleInfoSerializer(serializers.Serializer):
- aspectId = serializers.CharField(
- help_text="Identifier of the scaling aspect.",
- required=True,
- max_length=255,
- allow_null=True)
- scaleLevel = serializers.IntegerField(
- help_text="Indicates the scale level.",
- required=True)
-
-
-class CpProtocolInfoSerializer(serializers.Serializer):
- layerProtocol = serializers.ChoiceField(
- help_text="The identifier of layer(s) and protocol(s) associated to the network address information.",
- choices=["IP_OVER_ETHERNET"],
- required=False,
- allow_null=True)
- ipOverEthernet = serializers.DictField(
- help_text="IP addresses over Ethernet to assign to the extCP instance.",
- child=serializers.CharField(allow_blank=True),
- required=False,
- allow_null=True)
-
-
-class ExtCpInfoSerializer(serializers.Serializer):
- id = serializers.CharField(
- help_text="Identifier of the external CP instance and the related information instance.",
- required=False,
- max_length=255,
- allow_null=True)
- cpdId = serializers.CharField(
- help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
- required=True,
- max_length=255,
- allow_null=True)
- cpProtocolInfo = CpProtocolInfoSerializer(
- help_text="Network protocol information for this CP.",
- required=False,
- allow_null=True)
- extLinkPortId = serializers.CharField(
- help_text="Identifier of the 'extLinkPortInfo' structure inside the 'extVirtualLinkInfo' structure.",
- required=False,
- max_length=255,
- allow_null=True)
-
-
-class instantiatedVnfInfoSerializer(serializers.Serializer):
- flavourId = serializers.CharField(
- help_text="Identifier of the VNF deployment flavour applied to this VNF instance.",
- required=True,
- max_length=255,
- allow_null=True)
- vnfState = serializers.ChoiceField(
- help_text="State of the VNF instance.",
- choices=["STARTED", "STOPPED"],
- required=True,
- allow_null=True)
- scaleStatus = ScaleInfoSerializer(
- help_text="Scale status of the VNF, one entry per aspect.",
- required=False,
- many=True)
- extCpInfo = ExtCpInfoSerializer(
- help_text="Information about the external CPs exposed by the VNF instance.",
- required=False,
- many=True)
-
-
-class VnfInstanceSerializer(serializers.Serializer):
- id = serializers.CharField(
- help_text="Identifier of the VNF instance",
- required=True)
- vnfInstanceName = serializers.CharField(
- help_text="Name of the VNF instance.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfInstanceDescription = serializers.CharField(
- help_text="Human-readable description of the VNF instance.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfdId = serializers.CharField(
- help_text="Identifier of the VNFD on which the VNF instance is based.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfProvider = serializers.CharField(
- help_text="Provider of the VNF and the VNFD. The value is copied from the VNFD.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfProductName = serializers.CharField(
- help_text="Name to identify the VNF Product. The value is copied from the VNFD.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfSoftwareVersion = serializers.CharField(
- help_text="Software version of the VNF. The value is copied from the VNFD.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfdVersion = serializers.CharField(
- help_text="Identifies the version of the VNFD. The value is copied from the VNFD.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfPkgId = serializers.CharField(
- help_text="Identifier of information held by the NFVO about the specific VNF package on which the VNF is based.",
- required=False,
- allow_null=True,
- allow_blank=True)
- vnfConfigurableProperties = serializers.DictField(
- help_text="Current values of the configurable properties of the VNF instance.",
- child=serializers.CharField(allow_blank=True),
- required=False,
- allow_null=True)
- vimConnectionInfo = VimInfoSerializer(
- help_text="Information about VIM connections to be used for managing the resources for the VNF instance.",
- required=False,
- allow_null=True)
- instantiationState = serializers.ChoiceField(
- help_text="The instantiation state of the VNF.",
- choices=["NOT_INSTANTIATED", "INSTANTIATED"],
- required=False,
- allow_null=True)
- instantiatedVnfInfo = instantiatedVnfInfoSerializer(
- help_text="Information specific to an instantiated VNF instance.",
- required=False)
diff --git a/lcm/lcm/v2/urls.py b/lcm/lcm/v2/urls.py
deleted file mode 100644
index ea23519d..00000000
--- a/lcm/lcm/v2/urls.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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 lcm.v2.views import CreateVnfAndQueryVnfs
-
-urlpatterns = [
- url(r'^api/vnflcm/v2/vnf_instances$', CreateVnfAndQueryVnfs.as_view()),
-]
diff --git a/lcm/lcm/v2/views.py b/lcm/lcm/v2/views.py
deleted file mode 100644
index 4b569584..00000000
--- a/lcm/lcm/v2/views.py
+++ /dev/null
@@ -1,88 +0,0 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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.
-
-import logging
-import traceback
-
-from drf_yasg.utils import swagger_auto_schema
-from rest_framework import status
-from rest_framework.response import Response
-from rest_framework.views import APIView
-
-from lcm.nf.serializers import CreateVnfReqSerializer
-from lcm.nf.vnf_create.create_vnf_identifier import CreateVnf
-from lcm.pub.exceptions import NFLCMException
-from lcm.v2.serializers import VnfInstanceSerializer
-from lcm.v2.vnf_query.query_vnf import QueryVnf
-
-logger = logging.getLogger(__name__)
-
-
-class CreateVnfAndQueryVnfs(APIView):
- @swagger_auto_schema(
- responses={
- status.HTTP_200_OK: VnfInstanceSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
- }
- )
- def get(self, request):
- logger.debug("QueryMultiVnf--get::> %s" % request.data)
- try:
- resp_data = QueryVnf(request.data).query_multi_vnf()
-
- # vnfs_info_serializer = VnfsInfoSerializer(data=resp_data)
- # if not vnfs_info_serializer.is_valid():
- # raise NFLCMException(vnfs_info_serializer.errors)
- #
- # return Response(data=vnfs_info_serializer.data, status=status.HTTP_200_OK)
-
- vnfInstanceSerializer = VnfInstanceSerializer(data=resp_data)
- if not vnfInstanceSerializer.is_valid():
- raise NFLCMException(vnfInstanceSerializer.errors)
- return Response(data=vnfInstanceSerializer.data, status=status.HTTP_200_OK)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'Failed to get Vnfs'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
- @swagger_auto_schema(
- request_body=CreateVnfReqSerializer(),
- responses={
- status.HTTP_201_CREATED: VnfInstanceSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
- }
- )
- def post(self, request):
- logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
- try:
- req_serializer = CreateVnfReqSerializer(data=request.data)
- if not req_serializer.is_valid():
- raise NFLCMException(req_serializer.errors)
-
- resp = CreateVnf(req_serializer.data).do_biz()
-
- vnfInstanceSerializer = VnfInstanceSerializer(data=resp)
- if not vnfInstanceSerializer.is_valid():
- raise NFLCMException(vnfInstanceSerializer.errors)
- return Response(data=vnfInstanceSerializer.data, status=status.HTTP_201_CREATED)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/lcm/lcm/v2/vnf_query/__init__.py b/lcm/lcm/v2/vnf_query/__init__.py
deleted file mode 100644
index 342c2a8c..00000000
--- a/lcm/lcm/v2/vnf_query/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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.
diff --git a/lcm/lcm/v2/vnf_query/query_vnf.py b/lcm/lcm/v2/vnf_query/query_vnf.py
deleted file mode 100644
index 016b1a9c..00000000
--- a/lcm/lcm/v2/vnf_query/query_vnf.py
+++ /dev/null
@@ -1,146 +0,0 @@
-# Copyright 2018 ZTE Corporation.
-#
-# 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.
-
-import logging
-
-from lcm.pub.database.models import NfInstModel, StorageInstModel, VLInstModel, NetworkInstModel, VNFCInstModel, \
- VmInstModel
-from lcm.pub.exceptions import NFLCMException
-
-logger = logging.getLogger(__name__)
-
-
-class QueryVnf:
- def __init__(self, data, instanceid=''):
- self.vnf_inst_id = instanceid
- self.data = data
-
- def query_single_vnf(self):
- vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
- if not vnf_inst.exists():
- raise NFLCMException('VnfInst(%s) does not exist' % self.vnf_inst_id)
- resp_data = self.fill_resp_data(vnf_inst[0])
- return resp_data
-
- def query_multi_vnf(self):
- vnf_insts = NfInstModel.objects.all()
- if not vnf_insts:
- raise NFLCMException('VnfInsts does not exist')
- resp_data = []
- for vnf_inst in vnf_insts:
- resp_data.append(self.fill_resp_data(vnf_inst))
- return resp_data
-
- def fill_resp_data(self, vnf):
- logger.info('Get storages')
- storage_inst = StorageInstModel.objects.filter(instid=vnf.nfinstid)
- arr = []
- for s in storage_inst:
- storage = {
- "virtualStorageInstanceId": s.storageid,
- "storageResource": {
- "vimId": s.vimid,
- "resourceId": s.resouceid
- }
- }
- arr.append(storage)
- logger.info('Get networks')
- vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
- vl_arr = []
- for v in vl_inst:
- net = NetworkInstModel.objects.filter(networkid=v.relatednetworkid)
- if not net:
- raise NFLCMException('NetworkInst(%s) does not exist.' % v.relatednetworkid)
- v_dic = {
- "virtualLinkInstanceId": v.vlinstanceid,
- "virtualLinkDescId": v.vldid,
- "networkResource": {
- "vimId": net[0].vimid,
- "resourceId": net[0].resouceid
- }
- }
- vl_arr.append(v_dic)
- logger.info('Get vnfcs')
- vnfc_insts = VNFCInstModel.objects.filter(instid=vnf.nfinstid)
- vnfc_arr = []
- for vnfc in vnfc_insts:
- vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
- if not vm:
- raise NFLCMException('VmInst(%s) does not exist.' % vnfc.vmid)
- storage = StorageInstModel.objects.filter(ownerid=vm[0].vmid)
- if not storage:
- raise NFLCMException('StorageInst(%s) does not exist.' % vm[0].vmid)
- vnfc_dic = {
- "vnfcInstanceId": vnfc.vnfcinstanceid,
- "vduId": vnfc.vduid,
- "computeResource": {
- "vimId": vm[0].vimid,
- "resourceId": vm[0].resouceid
- },
- "storageResourceIds": [s.storageid for s in storage]
- }
- vnfc_arr.append(vnfc_dic)
- logger.info('Get vms')
- vms = VmInstModel.objects.filter(instid=vnf.nfinstid)
- vm_arr = []
- for vm in vms:
- vm_dic = {
- "vmid": vm.vmid,
- "vimid": vm.vimid,
- "tenant": vm.tenant,
- "resouceid": vm.resouceid,
- "vmname": vm.vmname,
- "nic_array": vm.nic_array,
- "metadata": vm.metadata,
- "volume_array": vm.volume_array,
- "server_group": vm.server_group,
- "availability_zone": vm.availability_zone,
- "flavor_id": vm.flavor_id,
- "security_groups": vm.security_groups,
- "operationalstate": vm.operationalstate,
- "insttype": vm.insttype,
- "is_predefined": vm.is_predefined,
- "create_time": vm.create_time,
- "instid": vm.instid,
- "nodeId": vm.nodeId
- }
- vm_arr.append(vm_dic)
-
- resp_data = {
- 'id': vnf.nfinstid,
- 'vnfInstanceName': vnf.nf_name,
- 'vnfInstanceDescription': 'Human-readable description of the VNF instance.',
- 'vnfdId': vnf.vnfdid,
- 'vnfProvider': vnf.vendor,
- 'vnfProductName': vnf.nf_name,
- 'vnfSoftwareVersion': vnf.vnfSoftwareVersion,
- 'vnfdVersion': vnf.version,
- 'vnfPkgId': vnf.package_id,
- 'vnfConfigurableProperties': {},
- 'instantiationState': '',
- 'vimConnectionInfo': {},
- "instantiatedVnfInfo": {
- "flavourId": vnf.flavour_id,
- "vnfState": vnf.status,
- "scaleStatus": [],
- "extCpInfo": [],
- "extVirtualLink": [],
- "monitoringParameters": {},
- "vimInfo": vm_arr,
- "vnfcResourceInfo": vnfc_arr,
- "virtualLinkResourceInfo": vl_arr,
- "virtualStorageResourceInfo": arr
- }
- }
- return resp_data