SOL003 API ALign 51/59151/2
authormaopengzhang <zhang.maopeng1@zte.com.cn>
Mon, 6 Aug 2018 10:48:45 +0000 (18:48 +0800)
committermaopengzhang <zhang.maopeng1@zte.com.cn>
Mon, 6 Aug 2018 11:18:10 +0000 (19:18 +0800)
SOL003 API ALign -VNFLCM Code Structure

Change-Id: I8da4ed65004eaa2f03bf7cba47b63227053d49ef
Issue-ID: VFC-635
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
29 files changed:
lcm/lcm/nf/biz/__init__.py [new file with mode: 0644]
lcm/lcm/nf/biz/create_vnf.py [moved from lcm/lcm/nf/vnf_create/create_vnf_identifier.py with 100% similarity]
lcm/lcm/nf/biz/delete_vnf.py [moved from lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py with 100% similarity]
lcm/lcm/nf/biz/instantiate_vnf.py [moved from lcm/lcm/nf/vnf_create/inst_vnf.py with 99% similarity]
lcm/lcm/nf/biz/query_vnf.py [moved from lcm/lcm/nf/vnf_query/query_vnf.py with 100% similarity]
lcm/lcm/nf/biz/terminate_vnf.py [moved from lcm/lcm/nf/vnf_cancel/term_vnf.py with 99% similarity]
lcm/lcm/nf/serializers/__init__.py [new file with mode: 0644]
lcm/lcm/nf/serializers/common.py [moved from lcm/lcm/v2/tests/__init__.py with 97% similarity]
lcm/lcm/nf/serializers/serializers.py [moved from lcm/lcm/nf/serializers.py with 68% similarity]
lcm/lcm/nf/tests/test_create_vnf.py [moved from lcm/lcm/v2/tests/test_vnf_create.py with 87% similarity]
lcm/lcm/nf/tests/test_delete_vnf.py [new file with mode: 0644]
lcm/lcm/nf/tests/test_instantiate_vnf.py [moved from lcm/lcm/nf/tests/test_vnf_create.py with 77% similarity]
lcm/lcm/nf/tests/test_query_vnf.py [moved from lcm/lcm/nf/tests/test_vnf_query.py with 100% similarity]
lcm/lcm/nf/tests/test_terminate_vnf.py [moved from lcm/lcm/nf/tests/test_vnf_cancel.py with 82% similarity]
lcm/lcm/nf/urls.py
lcm/lcm/nf/views/__init__.py [new file with mode: 0644]
lcm/lcm/nf/views/curd_vnf_views.py [moved from lcm/lcm/nf/views.py with 58% similarity]
lcm/lcm/nf/views/instantiate_vnf_view.py [new file with mode: 0644]
lcm/lcm/nf/views/terminate_vnf_view.py [new file with mode: 0644]
lcm/lcm/nf/vnf_cancel/__init__.py [deleted file]
lcm/lcm/nf/vnf_create/__init__.py [deleted file]
lcm/lcm/nf/vnf_query/__init__.py [deleted file]
lcm/lcm/urls.py
lcm/lcm/v2/__init__.py [deleted file]
lcm/lcm/v2/serializers.py [deleted file]
lcm/lcm/v2/urls.py [deleted file]
lcm/lcm/v2/views.py [deleted file]
lcm/lcm/v2/vnf_query/__init__.py [deleted file]
lcm/lcm/v2/vnf_query/query_vnf.py [deleted file]

diff --git a/lcm/lcm/nf/biz/__init__.py b/lcm/lcm/nf/biz/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
similarity index 99%
rename from lcm/lcm/nf/vnf_create/inst_vnf.py
rename to lcm/lcm/nf/biz/instantiate_vnf.py
index b87602c..f47746d 100644 (file)
@@ -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
similarity index 99%
rename from lcm/lcm/nf/vnf_cancel/term_vnf.py
rename to lcm/lcm/nf/biz/terminate_vnf.py
index 1dd8067..5d51512 100644 (file)
@@ -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 (file)
index 0000000..e69de29
similarity index 97%
rename from lcm/lcm/v2/tests/__init__.py
rename to lcm/lcm/nf/serializers/common.py
index 342c2a8..ca9a194 100644 (file)
@@ -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.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#         http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
similarity index 68%
rename from lcm/lcm/nf/serializers.py
rename to lcm/lcm/nf/serializers/serializers.py
index 98f6823..d7555c6 100644 (file)
@@ -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)
similarity index 87%
rename from lcm/lcm/v2/tests/test_vnf_create.py
rename to lcm/lcm/nf/tests/test_create_vnf.py
index 154b781..368b22f 100644 (file)
@@ -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 (file)
index 0000000..2667923
--- /dev/null
@@ -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)
similarity index 77%
rename from lcm/lcm/nf/tests/test_vnf_create.py
rename to lcm/lcm/nf/tests/test_instantiate_vnf.py
index 5a01749..7cf2646 100644 (file)
-# 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.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#         http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+import json\r
+import uuid\r
+\r
+import mock\r
+from django.test import TestCase\r
+from rest_framework import status\r
+from rest_framework.test import APIClient\r
+\r
+from lcm.nf.biz.instantiate_vnf import InstantiateVnf\r
+from lcm.nf.const import c1_data_get_tenant_id, c4_data_create_network, c2_data_create_volume, \\r
+    c5_data_create_subnet, c3_data_get_volume, c6_data_create_port, c7_data_create_flavor, c8_data_list_image, \\r
+    c9_data_create_vm, c10_data_get_vm, inst_req_data, vnfpackage_info\r
+from lcm.pub.database.models import NfInstModel, JobStatusModel\r
+from lcm.pub.utils import restcall\r
+from lcm.pub.utils.jobutil import JobUtil\r
+from lcm.pub.utils.timeutil import now_time\r
+from lcm.pub.vimapi import api\r
+\r
+\r
+class TestNFInstantiate(TestCase):\r
+    def setUp(self):\r
+        self.client = APIClient()\r
+        self.grant_result = {\r
+            "vimid": 'vimid_1',\r
+            "tenant": 'tenantname_1'\r
+        }\r
+\r
+    def tearDown(self):\r
+        pass\r
+\r
+    def assert_job_result(self, job_id, job_progress, job_detail):\r
+        jobs = JobStatusModel.objects.filter(jobid=job_id,\r
+                                             progress=job_progress,\r
+                                             descp=job_detail)\r
+        self.assertEqual(1, len(jobs))\r
+\r
+    @mock.patch.object(InstantiateVnf, 'run')\r
+    def test_instantiate_vnf(self, mock_run):\r
+        NfInstModel(nfinstid='12', nf_name='VNF1').save()\r
+        mock_run.re.return_value = None\r
+        response = self.client.post("/api/vnflcm/v1/vnf_instances/12/instantiate", data=inst_req_data, format='json')\r
+        self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)\r
+\r
+    def test_instantiate_vnf_when_inst_id_not_exist(self):\r
+        self.nf_inst_id = str(uuid.uuid4())\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        jobs = JobStatusModel.objects.filter(jobid=self.job_id,\r
+                                             progress=0,\r
+                                             descp="INST_VNF_READY")\r
+        self.assertEqual(1, len(jobs))\r
+        data = inst_req_data\r
+        InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 255, "VNF nf_inst_id is not exist.")\r
+\r
+    @mock.patch.object(restcall, 'call_req')\r
+    def test_instantiate_vnf_when_get_packageinfo_by_csarid_failed(self, mock_call_req):\r
+        NfInstModel.objects.create(nfinstid='1111',\r
+                                   nf_name='vFW_01',\r
+                                   package_id='222',\r
+                                   version='',\r
+                                   vendor='',\r
+                                   netype='',\r
+                                   vnfd_model='',\r
+                                   status='NOT_INSTANTIATED',\r
+                                   nf_desc='vFW in Nanjing TIC Edge',\r
+                                   vnfdid='111',\r
+                                   create_time=now_time())\r
+        r1_get_vnfpackage_by_vnfdid = [1, json.JSONEncoder().encode(vnfpackage_info), '200']\r
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid]\r
+        self.nf_inst_id = '1111'\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        data = inst_req_data\r
+        InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 255, "Failed to query vnf CSAR(111) from catalog.")\r
+\r
+    @mock.patch.object(restcall, 'call_req')\r
+    def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req):\r
+        NfInstModel.objects.create(nfinstid='1111',\r
+                                   nf_name='vFW_01',\r
+                                   package_id='222',\r
+                                   version='',\r
+                                   vendor='',\r
+                                   netype='',\r
+                                   vnfd_model='',\r
+                                   status='NOT_INSTANTIATED',\r
+                                   nf_desc='vFW in Nanjing TIC Edge',\r
+                                   vnfdid='111',\r
+                                   create_time=now_time())\r
+        r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']\r
+        r2_apply_grant_result = [1, json.JSONEncoder().encode(self.grant_result), '200']\r
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]\r
+        self.nf_inst_id = '1111'\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        data = inst_req_data\r
+        InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 255, "Nf instancing apply grant exception")\r
+\r
+    @mock.patch.object(restcall, 'call_req')\r
+    @mock.patch.object(api, 'call')\r
+    def test_instantiate_vnf_when_unexpected_exception(self, mock_call, mock_call_req):\r
+        NfInstModel.objects.create(nfinstid='1111',\r
+                                   nf_name='vFW_01',\r
+                                   package_id='222',\r
+                                   version='',\r
+                                   vendor='',\r
+                                   netype='',\r
+                                   vnfd_model='',\r
+                                   status='NOT_INSTANTIATED',\r
+                                   nf_desc='vFW in Nanjing TIC Edge',\r
+                                   vnfdid='111',\r
+                                   create_time=now_time())\r
+        r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']\r
+        r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']\r
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]\r
+        mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume]\r
+        self.nf_inst_id = '1111'\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        data = inst_req_data\r
+        InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 255, "unexpected exception")\r
+\r
+    @mock.patch.object(restcall, 'call_req')\r
+    @mock.patch.object(api, 'call')\r
+    def test_instantiate_vnf_success(self, mock_call, mock_call_req):\r
+        NfInstModel.objects.create(nfinstid='1111',\r
+                                   nf_name='vFW_01',\r
+                                   package_id='222',\r
+                                   version='',\r
+                                   vendor='',\r
+                                   netype='',\r
+                                   vnfd_model='',\r
+                                   status='NOT_INSTANTIATED',\r
+                                   nf_desc='vFW in Nanjing TIC Edge',\r
+                                   vnfdid='111',\r
+                                   create_time=now_time())\r
+        r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']\r
+        r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']\r
+        r3_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result, r3_lcm_notify_result]\r
+        mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume,\r
+                                 c4_data_create_network, c5_data_create_subnet, c6_data_create_port,\r
+                                 c7_data_create_flavor, c8_data_list_image, c9_data_create_vm, c10_data_get_vm]\r
+        self.nf_inst_id = '1111'\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        data = inst_req_data\r
+        InstantiateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 100, "Instantiate Vnf success.")\r
similarity index 82%
rename from lcm/lcm/nf/tests/test_vnf_cancel.py
rename to lcm/lcm/nf/tests/test_terminate_vnf.py
index ef0c7cf..0136862 100644 (file)
-# 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.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#         http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+\r
+import json\r
+import uuid\r
+\r
+import mock\r
+from django.test import TestCase, Client\r
+from rest_framework import status\r
+\r
+from lcm.nf.biz.terminate_vnf import TerminateVnf\r
+from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \\r
+    PortInstModel, FlavourInstModel, StorageInstModel, NfvoRegInfoModel\r
+from lcm.pub.utils import restcall\r
+from lcm.pub.utils.jobutil import JobUtil\r
+from lcm.pub.utils.timeutil import now_time\r
+from lcm.pub.vimapi import api\r
+\r
+\r
+class TestNFTerminate(TestCase):\r
+    def setUp(self):\r
+        self.client = Client()\r
+        StorageInstModel.objects.create(storageid="1",\r
+                                        vimid="1",\r
+                                        resouceid="11",\r
+                                        insttype=0,\r
+                                        instid="1111",\r
+                                        is_predefined=1)\r
+        NetworkInstModel.objects.create(networkid='1',\r
+                                        vimid='1',\r
+                                        resouceid='1',\r
+                                        name='pnet_network',\r
+                                        is_predefined=1,\r
+                                        tenant='admin',\r
+                                        insttype=0,\r
+                                        instid='1111')\r
+        SubNetworkInstModel.objects.create(subnetworkid='1',\r
+                                           vimid='1',\r
+                                           resouceid='1',\r
+                                           networkid='1',\r
+                                           is_predefined=1,\r
+                                           name='sub_pnet',\r
+                                           tenant='admin',\r
+                                           insttype=0,\r
+                                           instid='1111')\r
+        PortInstModel.objects.create(portid='1',\r
+                                     networkid='1',\r
+                                     subnetworkid='1',\r
+                                     vimid='1',\r
+                                     resouceid='1',\r
+                                     is_predefined=1,\r
+                                     name='aaa_pnet_cp',\r
+                                     tenant='admin',\r
+                                     insttype=0,\r
+                                     instid='1111')\r
+        FlavourInstModel.objects.create(flavourid="1",\r
+                                        vimid="1",\r
+                                        resouceid="11",\r
+                                        instid="1111",\r
+                                        is_predefined=1)\r
+        VmInstModel.objects.create(vmid="1",\r
+                                   vimid="1",\r
+                                   resouceid="11",\r
+                                   insttype=0,\r
+                                   instid="1111",\r
+                                   vmname="test_01",\r
+                                   is_predefined=1,\r
+                                   operationalstate=1)\r
+        NfvoRegInfoModel.objects.create(nfvoid='1111',\r
+                                        vnfminstid='11111',\r
+                                        apiurl='1')\r
+\r
+    def tearDown(self):\r
+        VmInstModel.objects.all().delete()\r
+        NetworkInstModel.objects.all().delete()\r
+        SubNetworkInstModel.objects.all().delete()\r
+        PortInstModel.objects.all().delete()\r
+\r
+    def assert_job_result(self, job_id, job_progress, job_detail):\r
+        jobs = JobStatusModel.objects.filter(jobid=job_id,\r
+                                             progress=job_progress,\r
+                                             descp=job_detail)\r
+        self.assertEqual(1, len(jobs))\r
+\r
+    @mock.patch.object(TerminateVnf, 'run')\r
+    def test_terminate_vnf(self, mock_run):\r
+        req_data = {\r
+            "terminationType": "GRACEFUL",\r
+            "gracefulTerminationTimeout": 120\r
+        }\r
+        NfInstModel(nfinstid='12', nf_name='VNF1').save()\r
+        mock_run.re.return_value = None\r
+        response = self.client.post("/api/vnflcm/v1/vnf_instances/12/terminate", data=req_data, format='json')\r
+        self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)\r
+\r
+    def test_terminate_vnf_when_inst_id_not_exist(self):\r
+        data = {\r
+            "terminationType": "GRACEFUL",\r
+            "gracefulTerminationTimeout": 120\r
+        }\r
+        self.nf_inst_id = str(uuid.uuid4())\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        TerminateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")\r
+\r
+    @mock.patch.object(restcall, 'call_req')\r
+    @mock.patch.object(api, 'call')\r
+    def test_terminate_vnf_success(self, mock_call, mock_call_req):\r
+        NfInstModel.objects.create(nfinstid='1111',\r
+                                   nf_name='2222',\r
+                                   package_id='todo',\r
+                                   version='',\r
+                                   vendor='',\r
+                                   netype='',\r
+                                   vnfd_model='',\r
+                                   status='VNF_INSTANTIATED',\r
+                                   nf_desc='',\r
+                                   vnfdid='',\r
+                                   vnfSoftwareVersion='',\r
+                                   vnfConfigurableProperties='todo',\r
+                                   localizationLanguage='EN_US',\r
+                                   create_time=now_time())\r
+        t1_apply_grant_result = [0, json.JSONEncoder().encode(\r
+            {\r
+                "vimid": 'vimid_1',\r
+                "tenant": 'tenantname_1'\r
+            }), '200']\r
+        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        t3_delete_flavor = [0, json.JSONEncoder().encode({"vim_id": "vimid_1"}), '200']\r
+        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_delete_flavor]\r
+        mock_call.return_value = None\r
+        data = {\r
+            "terminationType": "FORCEFUL",\r
+            "gracefulTerminationTimeout": 120\r
+        }\r
+        self.nf_inst_id = '1111'\r
+        self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)\r
+        JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")\r
+        TerminateVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()\r
+        self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")\r
index e59286a..f279b55 100644 (file)
 
 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 (file)
index 0000000..e69de29
similarity index 58%
rename from lcm/lcm/nf/views.py
rename to lcm/lcm/nf/views/curd_vnf_views.py
index 0db9d5f..16d082c 100644 (file)
@@ -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 (file)
index 0000000..3e9c334
--- /dev/null
@@ -0,0 +1,62 @@
+# Copyright 2017 ZTE Corporation.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#         http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+import logging\r
+import traceback\r
+\r
+from drf_yasg.utils import swagger_auto_schema\r
+from lcm.nf.biz.instantiate_vnf import InstantiateVnf\r
+from rest_framework import status\r
+from rest_framework.response import Response\r
+from rest_framework.views import APIView\r
+\r
+from lcm.nf.serializers.serializers import InstOrTeriVnfResponseSerializer, InstantiateVnfRequestSerializer\r
+from lcm.pub.exceptions import NFLCMException\r
+from lcm.pub.utils.jobutil import JobUtil\r
+\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class InstantiateVnfView(APIView):\r
+    @swagger_auto_schema(\r
+        request_body=InstantiateVnfRequestSerializer(),\r
+        responses={\r
+            status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),\r
+            status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
+        }\r
+    )\r
+    def post(self, request, instanceid):\r
+        logger.debug("InstantiateVnf--post::> %s" % request.data)\r
+        try:\r
+            instantiate_vnf_request_serializer = InstantiateVnfRequestSerializer(data=request.data)\r
+            if not instantiate_vnf_request_serializer.is_valid():\r
+                raise NFLCMException(instantiate_vnf_request_serializer.errors)\r
+\r
+            job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid)\r
+            JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")\r
+            InstantiateVnf(instantiate_vnf_request_serializer.data, instanceid, job_id).start()\r
+\r
+            instantiate_vnf_response_serializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})\r
+            resp_isvalid = instantiate_vnf_response_serializer.is_valid()\r
+            if not resp_isvalid:\r
+                raise NFLCMException(instantiate_vnf_response_serializer.errors)\r
+\r
+            return Response(data=instantiate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)\r
+        except NFLCMException as e:\r
+            logger.error(e.message)\r
+            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+        except Exception as e:\r
+            logger.error(e.message)\r
+            logger.error(traceback.format_exc())\r
+            return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
diff --git a/lcm/lcm/nf/views/terminate_vnf_view.py b/lcm/lcm/nf/views/terminate_vnf_view.py
new file mode 100644 (file)
index 0000000..8cd2646
--- /dev/null
@@ -0,0 +1,62 @@
+# Copyright 2017 ZTE Corporation.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#         http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+import logging\r
+import traceback\r
+\r
+from drf_yasg.utils import swagger_auto_schema\r
+from rest_framework import status\r
+from rest_framework.response import Response\r
+from rest_framework.views import APIView\r
+\r
+from lcm.nf.biz.terminate_vnf import TerminateVnf\r
+from lcm.nf.serializers.serializers import InstOrTeriVnfResponseSerializer, TerminateVnfRequestSerializer\r
+from lcm.pub.exceptions import NFLCMException\r
+from lcm.pub.utils.jobutil import JobUtil\r
+\r
+\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class TerminateVnfView(APIView):\r
+    @swagger_auto_schema(\r
+        request_body=TerminateVnfRequestSerializer(),\r
+        responses={\r
+            status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),\r
+            status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
+        }\r
+    )\r
+    def post(self, request, instanceid):\r
+        logger.debug("TerminateVnf--post::> %s" % request.data)\r
+        try:\r
+            terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)\r
+            if not terminate_vnf_request_serializer.is_valid():\r
+                raise NFLCMException(terminate_vnf_request_serializer.errors)\r
+\r
+            job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)\r
+            JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")\r
+            TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()\r
+\r
+            terminate_vnf_response_serializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})\r
+            if not terminate_vnf_response_serializer.is_valid():\r
+                raise NFLCMException(terminate_vnf_response_serializer.errors)\r
+\r
+            return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)\r
+        except NFLCMException as e:\r
+            logger.error(e.message)\r
+            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+        except Exception as e:\r
+            logger.error(e.message)\r
+            logger.error(traceback.format_exc())\r
+            return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
diff --git a/lcm/lcm/nf/vnf_cancel/__init__.py b/lcm/lcm/nf/vnf_cancel/__init__.py
deleted file mode 100644 (file)
index c7b6818..0000000
+++ /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 (file)
index c7b6818..0000000
+++ /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 (file)
index c7b6818..0000000
+++ /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.
index 6226e52..ea213ad 100644 (file)
@@ -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 (file)
index 342c2a8..0000000
+++ /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 (file)
index 3aaad31..0000000
+++ /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 (file)
index ea23519..0000000
+++ /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 (file)
index 4b56958..0000000
+++ /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 (file)
index 342c2a8..0000000
+++ /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 (file)
index 016b1a9..0000000
+++ /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