summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-27 15:03:19 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-01-27 15:03:19 +0800
commit43710aa9466768b43c24757c37095515eaafcb09 (patch)
tree1c1b5dfa73db737e7255823bb623475783965d30 /res
parentdecdce82bcee8eed90926ec382387f70bc0fd625 (diff)
Add vfc-vnfres getSubnet auto-swagger
Change-Id: I415dc51b647cd41d64451d588efe2b2eabb78b60 Issue-ID: VFC-679 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'res')
-rw-r--r--res/res/resources/urls.py2
-rw-r--r--res/res/resources/views.py43
2 files changed, 27 insertions, 18 deletions
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
index e282e86..8698690 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -23,7 +23,7 @@ urlpatterns = [
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/vms$', views.get_vms, name='get_vms'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/flavors$', views.get_flavors, name='get_flavors'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/networks$', views.get_networks, name='get_networks'),
- url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/subnets$', views.get_subnets, name='get_subnets'),
+ url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/subnets$', views.getSubnets.as_view(), name='get_subnets'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/cps$', views.getCps.as_view(), name='get_cps'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'),
]
diff --git a/res/res/resources/views.py b/res/res/resources/views.py
index dfecd87..13ba7c4 100644
--- a/res/res/resources/views.py
+++ b/res/res/resources/views.py
@@ -26,7 +26,7 @@ from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstMo
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
+from res.resources.serializers import VolumeInfoSerializer, CpsInfoSerializer, SubnetInfoSerializer
logger = logging.getLogger(__name__)
@@ -276,22 +276,31 @@ def fill_networks_data(network):
return networks_data
-@api_view(http_method_names=['GET'])
-def get_subnets(request, *args, **kwargs):
- logger.debug("Query all the subnets by vnfInstanceId[%s]", fun_name())
- try:
- vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
- subnets = SubNetworkInstModel.objects.filter(instid=vnf_inst_id)
- if not subnets:
- return Response(data={'error': 'Subnets does not exist'}, status=status.HTTP_404_NOT_FOUND)
- arr = []
- for subnet in subnets:
- arr.append(fill_subnets_data(subnet))
- return Response(data={'resp_data': arr}, 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 subnets'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+class getSubnets(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: SubnetInfoSerializer(),
+ status.HTTP_404_NOT_FOUND: 'Subnets does not exist',
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'})
+ def get(self, request, vnfInstanceId):
+ logger.debug("Query all the subnets by vnfInstanceId[%s]", fun_name())
+ try:
+ subnets = SubNetworkInstModel.objects.filter(instid=vnfInstanceId)
+ if not subnets:
+ return Response(data={'error': 'Subnets does not exist'}, status=status.HTTP_404_NOT_FOUND)
+ arr = []
+ for subnet in subnets:
+ arr.append(fill_subnets_data(subnet))
+ subnetInfoSerializer = SubnetInfoSerializer(data={'resp_data': arr})
+ isValid = subnetInfoSerializer.is_valid()
+ if not isValid:
+ raise Exception(subnetInfoSerializer.errors)
+
+ return Response(data=subnetInfoSerializer.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 subnets'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def fill_subnets_data(subnet):