summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-22 09:40:37 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-22 09:40:37 +0800
commit1b2be6b59f9361a56e434216ef9d6d3d57c7d46b (patch)
tree56dedd5b57dc46fa9b5fcb9a1054b1a7acf1e813 /res
parentb494650da07307c9698ad6901ae45bf7277d181a (diff)
Add code of gvnfm res
Change-Id: Ic3c085cdf6d0ff7f97c12dab54948366f822fc16 Issue-Id: GVNFM-12 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'res')
-rw-r--r--res/res/pub/database/models.py201
-rw-r--r--res/res/resources/tests.py53
-rw-r--r--res/res/resources/urls.py1
-rw-r--r--res/res/resources/views.py142
4 files changed, 387 insertions, 10 deletions
diff --git a/res/res/pub/database/models.py b/res/res/pub/database/models.py
index 1110ea1..0ec1b2e 100644
--- a/res/res/pub/database/models.py
+++ b/res/res/pub/database/models.py
@@ -60,4 +60,205 @@ class NfInstModel(models.Model):
localizationLanguage = models.CharField(db_column='LOCALIZATIONLANGUAGE', max_length=255, null=True)
+class CPInstModel(models.Model):
+ class Meta:
+ db_table = 'CPINST'
+
+ cpinstanceid = models.CharField(db_column='CPINSTANCEID', max_length=255, primary_key=True)
+ cpdid = models.CharField(db_column='CPDID', max_length=255)
+ cpinstancename = models.CharField(db_column='CPINSTANCENAME', max_length=255)
+ vlinstanceid = models.CharField(db_column='VLINSTANCEID', max_length=255)
+ ownertype = models.IntegerField(db_column='OWNERTYPE')
+ ownerid = models.CharField(db_column='OWNERID', max_length=255)
+ relatedtype = models.IntegerField(db_column='RELATEDTYPE')
+ relatedvl = models.CharField(db_column='RELATEDVL', max_length=255, blank=True, null=True)
+ relatedcp = models.CharField(db_column='RELATEDCP', max_length=255, blank=True, null=True)
+ relatedport = models.CharField(db_column='RELATEDPORT', max_length=255, blank=True, null=True)
+
+class StorageInstModel(models.Model):
+ class Meta:
+ db_table = 'STORAGEINST'
+
+ storageid = models.CharField(db_column='STORAGEID', primary_key=True, max_length=255)
+ vimid = models.CharField(db_column='VIMID', max_length=255)
+ resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
+ insttype = models.IntegerField(db_column='INSTTYPE')
+ instid = models.CharField(db_column='INSTID', max_length=255)
+ name = models.CharField(db_column='NAME', max_length=255, null=True)
+ storageDesc = models.CharField(db_column='STORAGEDESC', max_length=255, null=True)
+ storagetype = models.CharField(db_column='STORAGETYPE', max_length=255)
+ size = models.CharField(db_column='SIZE', max_length=255)
+ rdmaenabled = models.IntegerField(db_column='RDMAENABLED', null=True)
+ disktype = models.CharField(db_column='DISKTYPE', max_length=255)
+ ownerid = models.CharField(db_column='OWNERID', max_length=255, null=True)
+ zoneid = models.CharField(db_column='ZONEID', max_length=255, null=True)
+ hostid = models.CharField(db_column='HOSTID', max_length=255, null=True)
+ operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
+ tenant = models.CharField(db_column='TENANT', max_length=50, null=True)
+ is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
+
+
+class NetworkInstModel(models.Model):
+ class Meta:
+ db_table = 'NETWORKINST'
+
+ networkid = models.CharField(db_column='NETWORKID', primary_key=True, max_length=255)
+ vimid = models.CharField(db_column='VIMID', max_length=255)
+ resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
+ insttype = models.IntegerField(db_column='INSTTYPE')
+ instid = models.CharField(db_column='INSTID', max_length=255)
+ name = models.CharField(db_column='NAME', max_length=255)
+ tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
+ is_shared = models.IntegerField(db_column='ISSHARED', default=0, null=True)
+ is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
+ desc = models.CharField(db_column='DESC', max_length=255, null=True)
+ vendor = models.CharField(db_column='VENDOR', max_length=255, null=True)
+ bandwidth = models.IntegerField(db_column='BANDWIDTH', null=True)
+ mtu = models.IntegerField(db_column='MTU', null=True)
+ network_type = models.CharField(db_column='NETWORKTYPE', max_length=255, null=True)
+ segmentid = models.CharField(db_column='SEGMENTID', max_length=255, null=True)
+ vlantrans = models.IntegerField(db_column='VLANTRANS', null=True)
+ networkqos = models.CharField(db_column='NETWORKQOS', max_length=255, null=True)
+
+
+class SubNetworkInstModel(models.Model):
+ class Meta:
+ db_table = 'SUBNETWORKINST'
+
+ subnetworkid = models.CharField(db_column='SUBNETWORKID', primary_key=True, max_length=255)
+ vimid = models.CharField(db_column='VIMID', max_length=255)
+ resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
+ networkid = models.CharField(db_column='NETWORKID', max_length=255)
+ insttype = models.IntegerField(db_column='INSTTYPE')
+ instid = models.CharField(db_column='INSTID', max_length=255)
+ name = models.CharField(db_column='NAME', max_length=255)
+ ipversion = models.IntegerField(db_column='IPVERSION', null=True)
+ gatewayip = models.CharField(db_column='GATEWAYIP', max_length=255, null=True)
+ isdhcpenabled = models.IntegerField(db_column='ISDHCPENABLED', null=True)
+ cidr = models.CharField(db_column='CIDR', max_length=255)
+ vdsname = models.CharField(db_column='VDSNAME', max_length=255, null=True)
+ operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
+ tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
+ is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
+
+
+class PortInstModel(models.Model):
+ class Meta:
+ db_table = 'PORTINST'
+
+ portid = models.CharField(db_column='PORTID', primary_key=True, max_length=255)
+ networkid = models.CharField(db_column='NETWORKID', max_length=255)
+ subnetworkid = models.CharField(db_column='SUBNETWORKID', max_length=255, null=True)
+ vimid = models.CharField(db_column='VIMID', max_length=255)
+ resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
+ name = models.CharField(db_column='NAME', max_length=255, null=True)
+ insttype = models.IntegerField(db_column='INSTTYPE')
+ instid = models.CharField(db_column='INSTID', max_length=255)
+ cpinstanceid = models.CharField(db_column='CPINSTANCEID', max_length=255, null=True)
+ bandwidth = models.CharField(db_column='BANDWIDTH', max_length=255, null=True)
+ operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
+ ipaddress = models.CharField(db_column='IPADDRESS', max_length=255)
+ macaddress = models.CharField(db_column='MACADDRESS', max_length=255)
+ nicorder = models.CharField(db_column='NICORDER', max_length=255)
+ floatipaddress = models.CharField(db_column='FLOATIPADDRESS', max_length=255, null=True)
+ serviceipaddress = models.CharField(db_column='SERVICEIPADDRESS', max_length=255, null=True)
+ typevirtualnic = models.CharField(db_column='TYPEVIRTUALNIC', max_length=255, null=True)
+ sfcencapsulation = models.CharField(db_column='SFCENCAPSULATION', max_length=255, null=True)
+ direction = models.CharField(db_column='DIRECTION', max_length=255, null=True)
+ tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
+ interfacename = models.CharField(db_column='INTERFACENAME', max_length=255, blank=True, null=True)
+ vmid = models.CharField(db_column='VMID', max_length=255, blank=True, null=True)
+
+
+class FlavourInstModel(models.Model):
+ class Meta:
+ db_table = 'FLAVOURINST'
+
+ flavourid = models.CharField(db_column='FLAVOURID', max_length=255, primary_key=True)
+ name = models.CharField(db_column='NAME', max_length=255)
+ vcpu = models.CharField(db_column='VCPU', max_length=255)
+ memory = models.CharField(db_column='MEMORY', max_length=255)
+ extraspecs = models.CharField(db_column='EXTRASPECS', max_length=255)
+ instid = models.CharField(db_column='INSTID', max_length=255)
+
+
+class VmInstModel(models.Model):
+ class Meta:
+ db_table = 'VMINST'
+
+ vmid = models.CharField(db_column='VMID', primary_key=True, max_length=255)
+ vimid = models.CharField(db_column='VIMID', max_length=255)
+ resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
+ insttype = models.IntegerField(db_column='INSTTYPE')
+ instid = models.CharField(db_column='INSTID', max_length=255)
+ vmname = models.CharField(db_column='VMNAME', max_length=255)
+ operationalstate = models.IntegerField(db_column='OPERATIONALSTATE', null=True)
+ zoneid = models.CharField(db_column='ZONEID', max_length=255, null=True)
+ tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
+ hostid = models.CharField(db_column='HOSTID', max_length=255, null=True)
+ detailinfo = models.CharField(db_column='DETAILINFO', max_length=8192, null=True)
+ is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
+
+class VLInstModel(models.Model):
+ class Meta:
+ db_table = 'VLINST'
+
+ vlinstanceid = models.CharField(db_column='VLINSTANCEID', max_length=255, primary_key=True)
+ vldid = models.CharField(db_column='VLDID', max_length=255)
+ vlinstancename = models.CharField(db_column='VLINSTANCENAME', max_length=255, blank=True, null=True)
+ ownertype = models.IntegerField(db_column='OWNERTYPE')
+ ownerid = models.CharField(db_column='OWNERID', max_length=255)
+ relatednetworkid = models.CharField(db_column='RELATEDNETWORKID', max_length=255, blank=True, null=True)
+ relatedsubnetworkid = models.CharField(db_column='RELATEDSUBNETWORKID', max_length=255, blank=True, null=True)
+ vltype = models.IntegerField(db_column='VLTYPE', default=0)
+ vimid = models.CharField(db_column='VIMID', max_length=255)
+ tenant = models.CharField(db_column='TENANT', max_length=50)
+
+class VNFCInstModel(models.Model):
+ class Meta:
+ db_table = 'VNFCINST'
+
+ vnfcinstanceid = models.CharField(db_column='VNFCINSTANCEID', max_length=255, primary_key=True)
+ vduid = models.CharField(db_column='VDUID', max_length=255)
+ vdutype = models.CharField(db_column='VDUTYPE', max_length=255)
+ nfinstid = models.CharField(db_column='NFINSTID', max_length=255)
+ vmid = models.CharField(db_column='VMID', max_length=255)
+
+
+class VimModel(models.Model):
+ vimid = models.IntegerField(db_column='CMSERVERID', primary_key=True)
+ name = models.CharField(db_column='NAME', max_length=255, blank=True, null=True)
+ type = models.CharField(db_column='CMSTYPE', max_length=255, blank=True, null=True)
+ imageurl = models.CharField(db_column='IMAGEURL', max_length=1024, blank=True, null=True)
+ apiurl = models.CharField(db_column='APIURL', max_length=1024, blank=True, null=True)
+ version = models.CharField(db_column='VER', max_length=1024, blank=True, null=True)
+ supportnotification = models.IntegerField(db_column='SUPPORTNOTIFICATION', default=0)
+ longitude = models.CharField(db_column='LONGITUDE', max_length=1024, blank=True, null=True)
+ latitude = models.CharField(db_column='LATITUDE', max_length=1024, blank=True, null=True)
+ grantexclude = models.CharField(db_column='GRANTEXCLUDE', max_length=1, default='0', blank=True, null=True)
+ slalevel = models.IntegerField(db_column='SLALEVEL', default=0)
+
+ class Meta:
+ db_table = 'CMSSERVER'
+
+ def __unicode__(self):
+ return '%s' % self.name
+
+
+class VimUserModel(models.Model):
+ class Meta:
+ db_table = 'CMSSERVER_USER'
+
+ uuid = models.CharField(db_column='UUID', primary_key=True, max_length=255)
+ vimid = models.IntegerField(db_column='CMSERVERID')
+ username = models.CharField(db_column='USERNAME', max_length=255)
+ password = models.CharField(db_column='PWD', max_length=255, blank=True)
+ defaulttenant = models.CharField(db_column='TENANT', max_length=255, blank=True)
+
+ def __unicode__(self):
+ return '%s' % self.username
+
+
+
+
diff --git a/res/res/resources/tests.py b/res/res/resources/tests.py
index 3aec23a..4ca694a 100644
--- a/res/res/resources/tests.py
+++ b/res/res/resources/tests.py
@@ -14,13 +14,51 @@
from django.test import TestCase, Client
from rest_framework import status
-from res.pub.database.models import NfInstModel
+from res.pub.database.models import NfInstModel, StorageInstModel
class ResourceTest(TestCase):
def setUp(self):
self.client = Client()
NfInstModel.objects.all().delete()
+ self.test_data = {
+ "vnfInstanceId": u'1',
+ "vnfInstanceName": 'VNF1',
+ "vnfInstanceDescription": None,
+ "onboardedVnfPkgInfoId": None,
+ "vnfdId": None,
+ "vnfdVersion": None,
+ "vnfSoftwareVersion": None,
+ "vnfProvider": None,
+ "vnfProductName": None,
+ "vnfConfigurableProperties": {None},
+ "instantiationState": None,
+ "instantiatedVnfInfo": {
+ "flavourId": None,
+ "vnfState": None,
+ "scaleStatus": [],
+ "extCpInfo": [],
+ "extVirtualLink": [],
+ "monitoringParameters": {},
+ "localizationLanguage": None,
+ "vimInfo": [],
+ "vnfcResourceInfo": [],
+ "virtualLinkResourceInfo": [],
+ "virtualStorageResourceInfo": [
+ {
+ "virtualStorageInstanceId": "s01",
+ "virtualStorageDescId": "desc01",
+ "storageResource": {
+ "vimId": "vim01",
+ "resourceId": "resource01"
+ }
+ }
+
+ ]
+ },
+ "metadata": None,
+ "extensions": None
+ }
def tearDown(self):
pass
@@ -28,5 +66,16 @@ class ResourceTest(TestCase):
def test_get_vnf(self):
vnf_inst_id = "1"
NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
+ StorageInstModel(storageid='s01', vimid='vim01', resouceid='resource01', insttype=1,\
+ instid=vnf_inst_id, storageDesc='desc01').save()
response = self.client.get("/openoapi/vnfres/v1/vnfs/%s" % vnf_inst_id)
- self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+ self.assertEqual(self.test_data, response.data)
+ # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+ def test_get_vnfs(self):
+ for i in range(1):
+ NfInstModel(nfinstid='%s' % i, nf_name='VNF%s' % i).save()
+ StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i, insttype=1, instid='%s' % i, storageDesc='desc%s' % i).save()
+ response = self.client.get("/openoapi/vnfres/v1/vnfs")
+ # self.assertEqual(self.test_data, response.data)
+ self.failUnlessEqual(status.HTTP_200_OK, response.status_code) \ No newline at end of file
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
index 1bd41f5..09fb95d 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -19,6 +19,7 @@ from res.resources import views
urlpatterns = [
url(r'^openoapi/vnfres/v1/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', views.get_vnf, name='get_vnf'),
+ url(r'^openoapi/vnfres/v1/vnfs$', views.get_vnfs, name='get_vnfs'),
]
urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/res/res/resources/views.py b/res/res/resources/views.py
index be3cbf2..81c4e4a 100644
--- a/res/res/resources/views.py
+++ b/res/res/resources/views.py
@@ -18,9 +18,11 @@ from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
+from res.pub.exceptions import VNFRESException
from res.pub.utils.values import ignore_case_get
from res.pub.utils.syscomm import fun_name
-from res.pub.database.models import NfInstModel
+from res.pub.database.models import NfInstModel, CPInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \
+ VNFCInstModel, VmInstModel, VimModel, VimUserModel
logger = logging.getLogger(__name__)
@@ -32,14 +34,138 @@ def get_vnf(request, *args, **kwargs):
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)
+ 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}
+ # resp_data = {"vnfInstanceId": vnf_inst_id, "vnfInstanceName": vnf_inst[0].nf_name, "vnfInstanceDescription":}
+ resp_data = fill_resp_data(vnf_inst[0])
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)
-
-
+ return Response(data={'error': 'Failed to get Vnf(%s)' % vnf_inst_id}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_resp_data(vnf):
+ # cp_insts = CPInstModel.objects.filter(ownerid=vnf_inst_id)
+ # if not cp_insts:
+ # raise VNFRESException('CpInst(%s) does not exist.' % vnf_inst_id)
+ # cp_inst = cp_insts.first()
+ logger.info('Get the StorageInstModel of list')
+ storage_inst = StorageInstModel.objects.filter(instid=vnf.nfinstid)
+ arr = []
+ for s in storage_inst:
+ storage = {
+ "virtualStorageInstanceId": s.storageid,
+ "virtualStorageDescId": s.storageDesc,
+ "storageResource": {
+ "vimId": s.vimid,
+ "resourceId": s.resouceid
+ }
+ }
+ arr.append(storage)
+ logger.info('Get the VLInstModel of list.')
+ vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
+ vl_arr = []
+ for v in vl_inst:
+ net = NetworkInstModel.objects.filter(networkid=v.relatednetworkid)
+ if not net:
+ raise VNFRESException('NetworkInst(%s) does not exist.' % v.relatednetworkid)
+ v_dic = {
+ "virtualLinkInstanceId": v.vlinstanceid,
+ "virtualLinkDescId": v.vldid,
+ "networkResource": {
+ "vimId": net[0].vimid,
+ "resourceId": net[0].resouceid
+ }
+ }
+ vl_arr.append(v_dic)
+ logger.info('Get VNFCInstModel of list.')
+ vnfc_insts = VNFCInstModel.objects.filter(nfinstid=vnf.nfinstid)
+ vnfc_arr = []
+ for vnfc in vnfc_insts:
+ vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
+ if not vm:
+ raise VNFRESException('VmInst(%s) does not exist.' % vnfc.vmid)
+ storage = StorageInstModel.objects.filter(ownerid=vm[0].vmid)
+ if not storage:
+ raise VNFRESException('StorageInst(%s) does not exist.' % vm[0].vmid)
+ vnfc_dic = {
+ "vnfcInstanceId": vnfc.vnfcinstanceid,
+ "vduId": vnfc.vduid,
+ "computeResource": {
+ "vimId": vm[0].vimid,
+ "resourceId": vm[0].resouceid
+ },
+ "storageResourceIds": [s.storageid for s in storage]
+ }
+ vnfc_arr.append(vnfc_dic)
+ logger.info('Get the VimInstModel of list.')
+ vms = VmInstModel.objects.filter(instid=vnf.nfinstid)
+ vim_arr = []
+ # The 'vimInfoId' and 'vimId' each value are same
+ for vm in vms:
+ vims = VimModel.objects.filter(vimid=vm.vimid)
+ for vim in vims:
+ vim_users = VimUserModel.objects.filter(vimid=vim.vimid)
+ vim_dic = {
+ "vimInfoId": vim.vimid,
+ "vimId": vim.vimid,
+ "interfaceInfo": {
+ "vimType": vim.type,
+ "apiVersion": vim.version,
+ "protocolType": (vim.apiurl.split(':')[0] if vim.apiurl and vim.apiurl.index(':') else 'http')
+ },
+ "accessInfo": {
+ "tenant": (vim_users[0].defaulttenant if vim_users and vim_users[0].defaulttenant else ''),
+ "username": (vim_users[0].username if vim_users and vim_users[0].username else ''),
+ "password": (vim_users[0].password if vim_users and vim_users[0].password else '')
+ },
+ "interfaceEndpoint": vim.apiurl
+ }
+ vim_arr.append(vim_dic)
+
+ resp_data = {
+ "vnfInstanceId": vnf.nfinstid,
+ "vnfInstanceName": vnf.nf_name,
+ "vnfInstanceDescription": vnf.nf_desc,
+ "onboardedVnfPkgInfoId": vnf.package_id,
+ "vnfdId": vnf.vnfdid,
+ "vnfdVersion": vnf.version,
+ "vnfSoftwareVersion": vnf.vnfSoftwareVersion,
+ "vnfProvider": vnf.vendor,
+ "vnfProductName": vnf.producttype,
+ "vnfConfigurableProperties": {vnf.vnfConfigurableProperties},
+ "instantiationState": vnf.instantiationState,
+ "instantiatedVnfInfo": {
+ "flavourId": vnf.flavour_id,
+ "vnfState": vnf.status,
+ "scaleStatus": [],
+ "extCpInfo": [],
+ "extVirtualLink": [],
+ "monitoringParameters": {},
+ "localizationLanguage": vnf.localizationLanguage,
+ "vimInfo": vim_arr,
+ "vnfcResourceInfo": vnfc_arr,
+ "virtualLinkResourceInfo": vl_arr,
+ "virtualStorageResourceInfo": arr
+ },
+ "metadata": vnf.input_params,
+ "extensions": vnf.extension
+ }
+ return resp_data
+
+
+@api_view(http_method_names=['GET'])
+def get_vnfs(request):
+ logger.debug("Query all the vnfs[%s]", fun_name())
+ try:
+ vnf_insts = NfInstModel.objects.all()
+ if not vnf_insts:
+ return Response(data={'error': 'Vnfs does not exist'}, status=status.HTTP_404_NOT_FOUND)
+ # FIXME: fill resp_datas
+ arr = []
+ for vnf_inst in vnf_insts:
+ arr.append(fill_resp_data(vnf_inst))
+ return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+ except:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'Failed to get Vnfs'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file