diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2017-02-13 19:04:43 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2017-02-13 19:04:43 +0800 |
commit | b11f35792aaea24540cd8ed7d3e98a9b945cac8e (patch) | |
tree | abfa474b7f4da61741f8807aa30c4d7f295babe2 | |
parent | ada238af5d2e29b2ffe2c13f3f84281cc259faa2 (diff) |
Add get vnf instance info interface
Change-Id: I2a689db91b807d8d283a6b06b4d59c2d5e6e2581
Issue-Id: GVNFM-5
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | res/res/pub/database/models.py | 46 | ||||
-rw-r--r-- | res/res/resources/__init__.py | 13 | ||||
-rw-r--r-- | res/res/resources/tests.py | 32 | ||||
-rw-r--r-- | res/res/resources/urls.py | 24 | ||||
-rw-r--r-- | res/res/resources/views.py | 45 | ||||
-rw-r--r-- | res/res/settings.py | 3 | ||||
-rw-r--r-- | res/res/urls.py | 1 |
7 files changed, 160 insertions, 4 deletions
diff --git a/res/res/pub/database/models.py b/res/res/pub/database/models.py index 91bec30..1110ea1 100644 --- a/res/res/pub/database/models.py +++ b/res/res/pub/database/models.py @@ -14,10 +14,50 @@ 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 index 0000000..c7b6818 --- /dev/null +++ b/res/res/resources/__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/res/res/resources/tests.py b/res/res/resources/tests.py new file mode 100644 index 0000000..3aec23a --- /dev/null +++ b/res/res/resources/tests.py @@ -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 index 0000000..1bd41f5 --- /dev/null +++ b/res/res/resources/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 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 index 0000000..be3cbf2 --- /dev/null +++ b/res/res/resources/views.py @@ -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) + + diff --git a/res/res/settings.py b/res/res/settings.py index 374355d..6b19ab5 100644 --- a/res/res/settings.py +++ b/res/res/settings.py @@ -44,7 +44,8 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'rest_framework', 'res.pub.database', - 'res.samples' + 'res.samples', + 'res.resources' ] MIDDLEWARE_CLASSES = [ diff --git a/res/res/urls.py b/res/res/urls.py index 6009a83..9db7895 100644 --- a/res/res/urls.py +++ b/res/res/urls.py @@ -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 |