summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-08 11:51:14 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-08 12:04:46 +0800
commit1f2b48f4362e59e9c364b811906c86b77608b737 (patch)
tree0b789bf5372cfdd4dda5c3da6410819bac7f8a99
parentba64ce23c5572b0de5e5596a479d9090115009e4 (diff)
Create VNF instance,Create VNF Identifier
Change-Id: I62c5862cc1d3b37446a1141609560c9810f3ddb7 Issue-Id: GVNFM-15 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--.gitignore11
-rw-r--r--lcm/lcm/nf/__init__.py13
-rw-r--r--lcm/lcm/nf/vnfs/__init__.py13
-rw-r--r--lcm/lcm/nf/vnfs/tests/__init__.py13
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py40
-rw-r--r--lcm/lcm/nf/vnfs/urls.py24
-rw-r--r--lcm/lcm/nf/vnfs/views.py42
-rw-r--r--lcm/lcm/pub/database/models.py6
-rw-r--r--lcm/lcm/urls.py1
9 files changed, 155 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 69918373..cbc61c28 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
index 00000000..650d17ec
--- /dev/null
+++ b/lcm/lcm/nf/__init__.py
@@ -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
index 00000000..c7b6818e
--- /dev/null
+++ b/lcm/lcm/nf/vnfs/__init__.py
@@ -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
index 00000000..650d17ec
--- /dev/null
+++ b/lcm/lcm/nf/vnfs/tests/__init__.py
@@ -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
index 00000000..13e579fe
--- /dev/null
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -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
index 00000000..16b7fd89
--- /dev/null
+++ b/lcm/lcm/nf/vnfs/urls.py
@@ -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
index 00000000..02f35cb2
--- /dev/null
+++ b/lcm/lcm/nf/vnfs/views.py
@@ -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
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index 91bec30a..200387b7 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -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)
diff --git a/lcm/lcm/urls.py b/lcm/lcm/urls.py
index 152a787e..b217d146 100644
--- a/lcm/lcm/urls.py
+++ b/lcm/lcm/urls.py
@@ -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