summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-30 15:40:37 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-01-30 15:41:54 +0800
commit02e801d6f4ae8b5b7780666e87439d0fe88a5bf1 (patch)
tree7154f53dae5dc97666802b533cd4543bb9262ff0 /res
parent00aba92f331c198e9d73ce0ceb64feb1cbad6135 (diff)
Update vfc-vnfres vnfinfo schema
Change-Id: I19cfd66435801509da4ee4b8b391ccbdd1e72f6e Issue-ID: VFC-679 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'res')
-rw-r--r--res/res/resources/serializers.py46
-rw-r--r--res/res/resources/urls.py2
-rw-r--r--res/res/resources/views.py35
3 files changed, 46 insertions, 37 deletions
diff --git a/res/res/resources/serializers.py b/res/res/resources/serializers.py
index 0f2a1e2..65d9920 100644
--- a/res/res/resources/serializers.py
+++ b/res/res/resources/serializers.py
@@ -15,7 +15,7 @@
from rest_framework import serializers
-class StorageResourceSerializer(serializers.Serializer):
+class ResourceSerializer(serializers.Serializer):
resourceId = serializers.CharField(help_text="resourceId", required=True)
vimId = serializers.CharField(help_text="vimId", required=True)
@@ -23,15 +23,20 @@ class StorageResourceSerializer(serializers.Serializer):
class virtualStorageResourceInfoSerializer(serializers.Serializer):
virtualStorageInstanceId = serializers.CharField(help_text="virtualStorageInstanceId", required=True)
virtualStorageDescId = serializers.CharField(help_text="virtualStorageDescId", required=True, allow_null=True)
- storageResource = StorageResourceSerializer(help_text="storageResource", required=True)
+ storageResource = ResourceSerializer(help_text="storageResource", required=True)
class virtualLinkResourceInfoSerializer(serializers.Serializer):
- pass
+ virtualLinkInstanceId = serializers.IntegerField(help_text="virtualLinkInstanceId", required=True, allow_null=True)
+ virtualLinkDescId = serializers.IntegerField(help_text="virtualLinkDescId", required=True, allow_null=True)
+ networkResource = ResourceSerializer(help_text="networkResource", required=True, allow_null=True)
class vnfcResourceInfoSerializer(serializers.Serializer):
- pass
+ vnfcInstanceId = serializers.IntegerField(help_text="vnfcInstanceId", required=True, allow_null=True)
+ vduId = serializers.IntegerField(help_text="vduId", required=True, allow_null=True)
+ storageResourceIds = serializers.IntegerField(help_text="storageResourceIds", required=True, allow_null=True)
+ computeResource = ResourceSerializer(help_text="computeResource", required=True, allow_null=True)
class accessInfoSerializer(serializers.Serializer):
@@ -47,22 +52,24 @@ class InterfaceInfoSerializer(serializers.Serializer):
class VmResponseSerializer(serializers.Serializer):
- vmid = serializers.CharField(help_text="vmid", required=True)
- vimid = serializers.CharField(help_text="the vim id", required=True)
- resouceid = serializers.CharField(help_text="the resouce id", required=True)
+ vmid = serializers.CharField(help_text="vmid", required=True, allow_null=True)
+ vimid = serializers.CharField(help_text="the vim id", required=True, allow_null=True)
+ resouceid = serializers.CharField(help_text="the resouce id", required=True, allow_null=True)
tenant = serializers.CharField(help_text="tenant", required=True, allow_null=True)
- instid = serializers.CharField(help_text="the inst id", required=True)
- vmname = serializers.CharField(help_text="vmname", required=True)
- insttype = serializers.IntegerField(help_text="insttype", required=True)
+ instid = serializers.CharField(help_text="the inst id", required=True, allow_null=True)
+ vmname = serializers.CharField(help_text="vmname", required=True, allow_null=True)
+ insttype = serializers.IntegerField(help_text="insttype", required=True, allow_null=True)
operationalstate = serializers.CharField(help_text="operationalstate", required=True, allow_null=True)
- is_predefined = serializers.IntegerField(help_text="is_predefined", required=True)
- security_groups = serializers.CharField(help_text="security_groups", required=True)
- flavor_id = serializers.CharField(help_text="flavor_id", required=True)
- availability_zone = serializers.CharField(help_text="availability_zone", required=True)
- server_group = serializers.CharField(help_text="server_group", required=True)
- volume_array = serializers.CharField(help_text="volume_array", required=True)
- metadata = serializers.CharField(help_text="metadata", required=True)
- nic_array = serializers.CharField(help_text="nic_array", required=True)
+ is_predefined = serializers.IntegerField(help_text="is_predefined", required=True, allow_null=True)
+ security_groups = serializers.CharField(help_text="security_groups", required=True, allow_null=True)
+ flavor_id = serializers.CharField(help_text="flavor_id", required=True, allow_null=True)
+ availability_zone = serializers.CharField(help_text="availability_zone", required=True, allow_null=True)
+ server_group = serializers.CharField(help_text="server_group", required=True, allow_null=True)
+ volume_array = serializers.CharField(help_text="volume_array", required=True, allow_null=True)
+ metadata = serializers.CharField(help_text="metadata", required=True, allow_null=True)
+ nic_array = serializers.CharField(help_text="nic_array", required=True, allow_null=True)
+ create_time = serializers.CharField(help_text="create_time", required=False, allow_null=True)
+ nodeId = serializers.CharField(help_text="nodeId", required=False, allow_null=True)
class vimInfoSerializer(serializers.Serializer):
@@ -138,8 +145,7 @@ class VnfInfoSerializer(serializers.Serializer):
vnfInstanceId = serializers.CharField(help_text="vnf Instance Id", required=True)
vnfInstanceName = serializers.CharField(help_text="vnf Instance Name", required=True)
vnfInstanceDescription = serializers.CharField(help_text="vnfInstanceDescription", required=True, allow_null=True)
- onboardedVnfPkgInfoId = serializers.CharField(help_text="onboarded Vnf Pkg Info Id", required=False,
- allow_null=True)
+ onboardedVnfPkgInfoId = serializers.CharField(help_text="onboarded Vnf Pkg Info Id", required=False, allow_null=True)
vnfdId = serializers.CharField(help_text="vnfdId", required=True, allow_null=True)
vnfdVersion = serializers.CharField(help_text="vnfd Version", required=False, allow_null=True)
vnfSoftwareVersion = serializers.CharField(help_text="vnfSoftwareVersion", required=True, allow_null=True)
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
index 408be98..fa50f82 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -18,7 +18,7 @@ from rest_framework.urlpatterns import format_suffix_patterns
from res.resources import views
urlpatterns = [
- url(r'^api/vnfres/v1/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', views.get_vnf, name='get_vnf'),
+ url(r'^api/vnfres/v1/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', views.getVnfs.as_view(), name='get_vnf'),
url(r'^api/vnfres/v1/vnfs$', views.get_vnfs, name='get_vnfs'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/vms$', views.getVms.as_view(), name='get_vms'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/flavors$', views.getFlavors.as_view(), name='get_flavors'),
diff --git a/res/res/resources/views.py b/res/res/resources/views.py
index 6cfac2e..582a1d4 100644
--- a/res/res/resources/views.py
+++ b/res/res/resources/views.py
@@ -25,27 +25,30 @@ from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstMo
VNFCInstModel, VmInstModel, FlavourInstModel, SubNetworkInstModel, CPInstModel
from res.pub.exceptions import VNFRESException
from res.pub.utils.syscomm import fun_name
-from res.pub.utils.values import ignore_case_get
from res.resources.serializers import VolumeInfoSerializer, CpsInfoSerializer, SubnetInfoSerializer, \
- NetworkInfoSerializer, FlavorInfoSerializer, VmInfoSerializer
+ NetworkInfoSerializer, FlavorInfoSerializer, VmInfoSerializer, VnfInfoSerializer
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)
- resp_data = fill_resp_data(vnf_inst[0])
- return Response(data=resp_data, status=status.HTTP_200_OK)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'Failed to get Vnf(%s)' % vnf_inst_id}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+class getVnfs(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: VnfInfoSerializer(),
+ status.HTTP_404_NOT_FOUND: 'Vnf does not exist',
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'})
+ def get(self, request, vnfInstanceId):
+ logger.debug("[%s]vnf_inst_id=%s", fun_name(), vnfInstanceId)
+ try:
+ vnf_inst = NfInstModel.objects.filter(nfinstid=vnfInstanceId)
+ if not vnf_inst:
+ return Response(data={'error': 'Vnf(%s) does not exist' % vnfInstanceId}, status=status.HTTP_404_NOT_FOUND)
+ resp_data = fill_resp_data(vnf_inst[0])
+ return Response(data=resp_data, status=status.HTTP_200_OK)
+ except Exception as e:
+ logger.error(e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'Failed to get Vnf(%s)' % vnfInstanceId}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def fill_resp_data(vnf):