Add get vnf instance info interface
authorfujinhua <fu.jinhua@zte.com.cn>
Mon, 13 Feb 2017 11:04:43 +0000 (19:04 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Mon, 13 Feb 2017 11:04:43 +0000 (19:04 +0800)
Change-Id: I2a689db91b807d8d283a6b06b4d59c2d5e6e2581
Issue-Id: GVNFM-5
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
res/res/pub/database/models.py
res/res/resources/__init__.py [new file with mode: 0644]
res/res/resources/tests.py [new file with mode: 0644]
res/res/resources/urls.py [new file with mode: 0644]
res/res/resources/views.py [new file with mode: 0644]
res/res/settings.py
res/res/urls.py

index 91bec30..1110ea1 100644 (file)
 from django.db import models
 
 
-class VnfInstModel(models.Model):
+class NfInstModel(models.Model):
     class Meta:
-        db_table = 'GVNFM_VNFINST'
+        db_table = 'NFINST'
+
+    nfinstid = models.CharField(db_column='NFINSTID', max_length=200, primary_key=True)
+    mnfinstid = models.CharField(db_column='M_NFINSTID', max_length=200, blank=True, null=True)
+    nf_name = models.CharField(db_column='NFNAME', max_length=100, blank=True, null=True) #CreateVnfRequest.vnfInstanceName
+    template_id = models.CharField(db_column='TEMPLATEID', max_length=200, blank=True, null=True)
+    vnf_id = models.CharField(db_column='VNFID', max_length=200, blank=True, null=True)
+    package_id = models.CharField(db_column='PACKAGEID', max_length=200, blank=True, null=True)
+    vnfm_inst_id = models.CharField(db_column='VNFMINSTID', max_length=200, blank=True, null=True)
+    multivim = models.IntegerField(db_column='MULTIVIM', default=0)
+    ns_inst_id = models.CharField(db_column='NSINSTID', max_length=200, blank=True, null=True)
+    status = models.CharField(db_column='STATUS', max_length=20, blank=True, null=True)
+    flavour_id = models.CharField(db_column='FLAVOURID', max_length=200, blank=True, null=True) #InstantiateVnfRequest.flavourId
+    vnf_level = models.CharField(db_column='VNFLEVEL', max_length=200, blank=True, null=True) #InstantiateVnfRequest.instantiationLevelId
+    location = models.CharField(db_column='LOCATION', max_length=200, blank=True, null=True)
+    deploy_environment = models.CharField(db_column='DEPLOYENVIRONMENT', max_length=100, blank=True, null=True)
+    max_vm = models.IntegerField(db_column='MAXVM', blank=True, null=True)
+    max_cpu = models.IntegerField(db_column='MAXCPU', blank=True, null=True)
+    max_ram = models.IntegerField(db_column='MAXRAM', blank=True, null=True)
+    max_hd = models.IntegerField(db_column='MAXHD', blank=True, null=True)
+    max_shd = models.IntegerField(db_column='MAXSHD', blank=True, null=True)
+    max_net = models.IntegerField(db_column='MAXNET', blank=True, null=True)
+    version = models.CharField(db_column='VERSION', max_length=255, null=True)
+    vendor = models.CharField(db_column='VENDOR', max_length=255, null=True, blank=True)
+    producttype = models.CharField(db_column='PRODUCTTYPE', max_length=255, null=True)
+    netype = models.CharField(db_column='NETYPE', max_length=255, null=True)
+    vnfd_model = models.TextField(db_column='VNFDMODEL', max_length=20000, blank=True, null=True)
+    input_params = models.TextField(db_column='INPUTPARAMS', max_length=2000, blank=True, null=True)  #InstantiateVnfRequest.additionalParams
+    scale_params = models.TextField(db_column='SCALEPARAMS', max_length=2000, 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, blank=True, null=True)
+    extension = models.TextField(db_column='EXTENSION', max_length=65535, blank=True, null=True)
+    initallocatedata = models.TextField(db_column='INITALLOCATEDATA', max_length=20000, blank=True, null=True)
+    predefinedvm = models.TextField(db_column='PREDEFINEDVM', max_length=65535, blank=True, null=True)
+    vnfextendtype = models.CharField(db_column='VNFEXTENDTYPE', max_length=255, null=True)
+
+    instantiationState = models.CharField(db_column='INSTANTIATIONSTATE', max_length=200, blank=True, null=True)
+    nf_desc = models.CharField(db_column='VNFINSTANCEDESC', max_length=200, blank=True, null=True)
+    vnfdid = models.CharField(db_column='VNFDID', max_length=200, blank=True, null=True)
+    vnfSoftwareVersion = models.CharField(db_column='VNFSOFTWAREVER', max_length=200, blank=True, null=True)
+    vnfConfigurableProperties = models.TextField(db_column='VNFCONFIGURABLEPROPERTIES', max_length=20000, blank=True, null=True)
+    localizationLanguage = models.CharField(db_column='LOCALIZATIONLANGUAGE', max_length=255, null=True)
 
-    id = models.CharField(db_column='ID', primary_key=True, max_length=200)
 
 
diff --git a/res/res/resources/__init__.py b/res/res/resources/__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/res/res/resources/tests.py b/res/res/resources/tests.py
new file mode 100644 (file)
index 0000000..3aec23a
--- /dev/null
@@ -0,0 +1,32 @@
+# 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 res.pub.database.models import NfInstModel
+
+
+class ResourceTest(TestCase):
+    def setUp(self):
+        self.client = Client()
+        NfInstModel.objects.all().delete()
+
+    def tearDown(self):
+        pass
+        
+    def test_get_vnf(self):
+        vnf_inst_id = "1"
+        NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
+        response = self.client.get("/openoapi/vnfres/v1/vnfs/%s" % vnf_inst_id)
+        self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
new file mode 100644 (file)
index 0000000..1bd41f5
--- /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 url
+from rest_framework.urlpatterns import format_suffix_patterns
+
+from res.resources import views
+
+urlpatterns = [
+    url(r'^openoapi/vnfres/v1/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', views.get_vnf, name='get_vnf'),
+]
+
+urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/res/res/resources/views.py b/res/res/resources/views.py
new file mode 100644 (file)
index 0000000..be3cbf2
--- /dev/null
@@ -0,0 +1,45 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import logging
+import traceback
+
+from rest_framework import status
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+
+from res.pub.utils.values import ignore_case_get
+from res.pub.utils.syscomm import fun_name
+from res.pub.database.models import NfInstModel
+
+logger = logging.getLogger(__name__)
+
+
+@api_view(http_method_names=['GET'])
+def get_vnf(request, *args, **kwargs):
+    vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+    logger.debug("[%s]vnf_inst_id=%s", fun_name(), vnf_inst_id)
+    try:
+        vnf_inst = NfInstModel.objects.filter(nfinstid=vnf_inst_id)
+        if not vnf_inst:
+            return Response(data={'error': 'Vnf(%s) does not exist' % vnf_inst_id}, 
+                status=status.HTTP_404_NOT_FOUND)
+        # TODO: fill resp_data
+        resp_data = {"vnfInstanceId": vnf_inst_id}
+        return Response(data=resp_data, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get Vnf(%s)' % vnf_inst_id}, 
+            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+    
+    
index 374355d..6b19ab5 100644 (file)
@@ -44,7 +44,8 @@ INSTALLED_APPS = [
     'django.contrib.staticfiles',
     'rest_framework',
     'res.pub.database',
-    'res.samples'
+    'res.samples',
+    'res.resources'
 ]
 
 MIDDLEWARE_CLASSES = [
index 6009a83..9db7895 100644 (file)
@@ -17,6 +17,7 @@ from res.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG
 
 urlpatterns = [
     url(r'^', include('res.samples.urls')),
+    url(r'^', include('res.resources.urls')),
 ]
 
 # regist to MSB when startup