From 1f2b48f4362e59e9c364b811906c86b77608b737 Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Wed, 8 Feb 2017 11:51:14 +0800 Subject: Create VNF instance,Create VNF Identifier Change-Id: I62c5862cc1d3b37446a1141609560c9810f3ddb7 Issue-Id: GVNFM-15 Signed-off-by: ying.yunlong --- lcm/lcm/nf/__init__.py | 13 ++++++++++ lcm/lcm/nf/vnfs/__init__.py | 13 ++++++++++ lcm/lcm/nf/vnfs/tests/__init__.py | 13 ++++++++++ lcm/lcm/nf/vnfs/tests/test_vnf_create.py | 40 ++++++++++++++++++++++++++++++ lcm/lcm/nf/vnfs/urls.py | 24 ++++++++++++++++++ lcm/lcm/nf/vnfs/views.py | 42 ++++++++++++++++++++++++++++++++ lcm/lcm/pub/database/models.py | 6 +++++ lcm/lcm/urls.py | 1 + 8 files changed, 152 insertions(+) create mode 100644 lcm/lcm/nf/__init__.py create mode 100644 lcm/lcm/nf/vnfs/__init__.py create mode 100644 lcm/lcm/nf/vnfs/tests/__init__.py create mode 100644 lcm/lcm/nf/vnfs/tests/test_vnf_create.py create mode 100644 lcm/lcm/nf/vnfs/urls.py create mode 100644 lcm/lcm/nf/vnfs/views.py (limited to 'lcm') 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 -- cgit 1.2.3-korg