summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-25 09:47:39 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-01-25 09:47:39 +0800
commit96114591d43b8c73a6210a904c15f9314624150d (patch)
treee98068aeccc81ea38a3dca8df326e53fee57d6e0
parentd399489b17591260c77b128b5aac4a9578466a09 (diff)
Add vfc-vnfres get_Cps auto-swagger
Change-Id: I450351c2c47a7faf93ca09e2ca4d759174b7941a Issue-ID: VFC-679 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-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 0a53881..5bcfb9a 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -25,7 +25,7 @@ urlpatterns = [
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\-\_]+)/cps$', views.get_cps, name='get_cps'),
+ 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'),
url(r'^api/vnfres/v1/swagger.json$', SwaggerJsonView.as_view()),
]
diff --git a/res/res/resources/views.py b/res/res/resources/views.py
index e7fc4f6..049f584 100644
--- a/res/res/resources/views.py
+++ b/res/res/resources/views.py
@@ -28,7 +28,7 @@ from res.pub.utils.values import ignore_case_get
from res.pub.utils.syscomm import fun_name
from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \
VNFCInstModel, VmInstModel, FlavourInstModel, SubNetworkInstModel, CPInstModel
-from res.resources.serializers import VolumeInfoSerializer, NoneSerializer
+from res.resources.serializers import VolumeInfoSerializer, NoneSerializer, CpsInfoSerializer
logger = logging.getLogger(__name__)
@@ -310,22 +310,31 @@ def fill_subnets_data(subnet):
return subnets_data
-@api_view(http_method_names=['GET'])
-def get_cps(request, *args, **kwargs):
- logger.debug("Query all the cps by vnfInstanceId[%s]", fun_name())
- try:
- vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
- cps = CPInstModel.objects.filter(ownerid=vnf_inst_id)
- if not cps:
- return Response(data={'error': 'Cps does not exist'}, status=status.HTTP_404_NOT_FOUND)
- arr = []
- for cp in cps:
- arr.append(fill_cps_data(cp))
- 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 cps'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+class getCps(APIView):
+ @swagger_auto_schema(request_body=NoneSerializer(),
+ responses={
+ status.HTTP_200_OK: CpsInfoSerializer(),
+ status.HTTP_404_NOT_FOUND: 'Cps does not exist',
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'})
+ def get(self, request, vnfInstanceId):
+ logger.debug("Query all the cps by vnfInstanceId[%s]", fun_name())
+ try:
+ cps = CPInstModel.objects.filter(ownerid=vnfInstanceId)
+ if not cps:
+ return Response(data={'error': 'Cps does not exist'}, status=status.HTTP_404_NOT_FOUND)
+ arr = []
+ for cp in cps:
+ arr.append(fill_cps_data(cp))
+ cpInfoSerializer = CpsInfoSerializer(data={'resp_data': arr})
+ isValid = cpInfoSerializer.is_valid()
+ if not isValid:
+ raise Exception(cpInfoSerializer.errors)
+
+ return Response(data=cpInfoSerializer.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 cps'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def fill_cps_data(cp):