Create VNF instance,Create VNF Identifier
authorying.yunlong <ying.yunlong@zte.com.cn>
Wed, 8 Feb 2017 03:51:14 +0000 (11:51 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Wed, 8 Feb 2017 04:04:46 +0000 (12:04 +0800)
Change-Id: I62c5862cc1d3b37446a1141609560c9810f3ddb7
Issue-Id: GVNFM-15
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
.gitignore
lcm/lcm/nf/__init__.py [new file with mode: 0644]
lcm/lcm/nf/vnfs/__init__.py [new file with mode: 0644]
lcm/lcm/nf/vnfs/tests/__init__.py [new file with mode: 0644]
lcm/lcm/nf/vnfs/tests/test_vnf_create.py [new file with mode: 0644]
lcm/lcm/nf/vnfs/urls.py [new file with mode: 0644]
lcm/lcm/nf/vnfs/views.py [new file with mode: 0644]
lcm/lcm/pub/database/models.py
lcm/lcm/urls.py

index 6991837..cbc61c2 100644 (file)
@@ -1,8 +1,3 @@
-target/
-coverage-report/
-bin/
-.project
-.settings
-.classpath
-.class
-.checkstyle
+lcm/.idea
+lcm/logs/runtime_lcm.log
+*.pyc
diff --git a/lcm/lcm/nf/__init__.py b/lcm/lcm/nf/__init__.py
new file mode 100644 (file)
index 0000000..650d17e
--- /dev/null
@@ -0,0 +1,13 @@
+# 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.
\ No newline at end of file
diff --git a/lcm/lcm/nf/vnfs/__init__.py b/lcm/lcm/nf/vnfs/__init__.py
new file mode 100644 (file)
index 0000000..c7b6818
--- /dev/null
@@ -0,0 +1,13 @@
+# 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/vnfs/tests/__init__.py b/lcm/lcm/nf/vnfs/tests/__init__.py
new file mode 100644 (file)
index 0000000..650d17e
--- /dev/null
@@ -0,0 +1,13 @@
+# 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.
\ No newline at end of file
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
new file mode 100644 (file)
index 0000000..13e579f
--- /dev/null
@@ -0,0 +1,40 @@
+# 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
+
+from django.test import TestCase, Client
+from rest_framework import status
+
+from lcm.pub.database.models import VnfInstModel
+
+
+class TestNsInstantiate(TestCase):
+    def setUp(self):
+        self.client = Client()
+        self.nsd_id = str(uuid.uuid4())
+
+    def tearDown(self):
+        pass
+
+    def test_create_vnf_identifier(self):
+        data = {
+            "vnfdId": "zte_vFW_51610",
+            "vnfInstanceName": "vFW_01",
+            "vnfInstanceDescription": " vFW in Nanjing TIC Edge"}
+        response = self.client.post("/gvnfmapi/lcm/v1/vnf_instances", data=data, format='json')
+        self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
+        context = json.loads(response.content)
+        self.assertTrue(VnfInstModel.objects.filter(id=context['vnfInstanceId']).exists())
diff --git a/lcm/lcm/nf/vnfs/urls.py b/lcm/lcm/nf/vnfs/urls.py
new file mode 100644 (file)
index 0000000..16b7fd8
--- /dev/null
@@ -0,0 +1,24 @@
+# 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.conf.urls import patterns, url
+from rest_framework.urlpatterns import format_suffix_patterns
+
+from lcm.nf.vnfs.views import CreateVnfIdentifier
+
+urlpatterns = patterns('',
+                       url(r'^gvnfmapi/lcm/v1/vnf_instances$', CreateVnfIdentifier.as_view()),
+                       )
+
+urlpatterns = format_suffix_patterns(urlpatterns)
\ No newline at end of file
diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py
new file mode 100644 (file)
index 0000000..02f35cb
--- /dev/null
@@ -0,0 +1,42 @@
+# 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 uuid
+
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from lcm.pub.database.models import VnfInstModel
+from lcm.pub.utils.timeutil import now_time
+from lcm.pub.utils.values import ignore_case_get
+
+logger = logging.getLogger(__name__)
+
+
+class CreateVnfIdentifier(APIView):
+    def post(self, request):
+        logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
+        self.vnfd_id = ignore_case_get(request.data, "vnfdId")
+        self.vnf_instance_mame = ignore_case_get(request.data, "vnfInstanceName")
+        self.description = ignore_case_get(request.data, "vnfInstanceDescription")
+        self.nf_inst_id = str(uuid.uuid4())
+        VnfInstModel(id=self.nf_inst_id, name=self.vnf_instance_mame, vnfd_id=self.vnfd_id,
+                     description=self.description, status='empty', create_time=now_time(), lastuptime=now_time()).save()
+        vnf_inst = VnfInstModel.objects.get(id=self.nf_inst_id)
+        logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s],lastuptime is [%s],' %
+                     (vnf_inst.id, vnf_inst.name, vnf_inst.vnfd_id, vnf_inst.description, vnf_inst.create_time, vnf_inst.lastuptime))
+        rsp = {"vnfInstanceId": self.nf_inst_id}
+        return Response(data=rsp, status=status.HTTP_201_CREATED)
\ No newline at end of file
index 91bec30..200387b 100644 (file)
@@ -19,5 +19,11 @@ class VnfInstModel(models.Model):
         db_table = 'GVNFM_VNFINST'
 
     id = models.CharField(db_column='ID', primary_key=True, max_length=200)
+    name = models.CharField(db_column='NAME', max_length=200)
+    vnfd_id = models.CharField(db_column='VNFDID', max_length=200)
+    description = models.CharField(db_column='DESCRIPTION', max_length=255, null=True, blank=True)
+    status = models.CharField(db_column='STATUS', max_length=200, null=True, blank=True)
+    create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
+    lastuptime = models.CharField(db_column='LASTUPTIME', max_length=200, null=True, blank=True)
 
 
index 152a787..b217d14 100644 (file)
@@ -17,6 +17,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.vnfs.urls')),
 ]
 
 # regist to MSB when startup