summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-26 13:33:36 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-01-26 13:33:36 +0800
commitaef65f5c0950526a7fb484a8472f20958660f04e (patch)
treeaeaf8d7053f0b5b3dc63db22a4d1fd8602db42d1
parent5ebe5c5cd5f95f82bf954ae5a72228c24e124ef7 (diff)
Add vfc-vnflcm createVnf auto-swagger
Change-Id: I1886b65a95f4d4f30d4fb577ac6dd04671276fb9 Issue-ID: VFC-682 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/lcm/nf/vnfs/views.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py
index cfdf2800..1980fd48 100644
--- a/lcm/lcm/nf/vnfs/views.py
+++ b/lcm/lcm/nf/vnfs/views.py
@@ -15,10 +15,12 @@
import logging
import traceback
+from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
+from lcm.nf.vnfs.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer
from lcm.nf.vnfs.vnf_cancel.delete_vnf_identifier import DeleteVnf
from lcm.nf.vnfs.vnf_cancel.term_vnf import TermVnf
from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
@@ -45,10 +47,30 @@ class CreateVnfAndQueryVnfs(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=resp_data, status=status.HTTP_200_OK)
+ @swagger_auto_schema(
+ request_body=CreateVnfReqSerializer(),
+ responses={
+ status.HTTP_201_CREATED: CreateVnfRespSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
def post(self, request):
logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
+ req_serializer = CreateVnfReqSerializer(data=request.data)
+ req_isValid = req_serializer.is_valid()
try:
- nf_inst_id = CreateVnf(request.data).do_biz()
+ if not req_isValid:
+ raise NFLCMException(req_serializer.errors)
+
+ nf_inst_id = CreateVnf(req_serializer.data).do_biz()
+ rsp = {
+ "vnfInstanceId": nf_inst_id
+ }
+ resp_serializer = CreateVnfRespSerializer(data=rsp)
+ resp_isValid = resp_serializer.is_valid()
+ if not resp_isValid:
+ raise NFLCMException(resp_serializer.errors)
+ return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
except NFLCMException as e:
logger.error(e.message)
return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -56,10 +78,6 @@ class CreateVnfAndQueryVnfs(APIView):
logger.error(e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- rsp = {
- "vnfInstanceId": nf_inst_id
- }
- return Response(data=rsp, status=status.HTTP_201_CREATED)
class InstantiateVnf(APIView):