X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=lcm%2Fns%2Fvnfs%2Fviews.py;h=3ec7932a05e2080f982bdacd363c5f48b1880616;hb=43d4d88bae88ca75a575789ed76eb3f268e46530;hp=411ecf05238cb81e3d37f042e5f1c012efc2d674;hpb=f1c3a65a24b92d29ca43065117ba71c07255366e;p=vfc%2Fnfvo%2Flcm.git diff --git a/lcm/ns/vnfs/views.py b/lcm/ns/vnfs/views.py index 411ecf05..3ec7932a 100644 --- a/lcm/ns/vnfs/views.py +++ b/lcm/ns/vnfs/views.py @@ -18,6 +18,7 @@ import uuid from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView +from drf_yasg.utils import swagger_auto_schema from lcm.ns.vnfs import create_vnfs from lcm.ns.vnfs.create_vnfs import CreateVnfs @@ -31,13 +32,27 @@ from lcm.pub.exceptions import NSLCMException from lcm.pub.msapi.extsys import get_vnfm_by_id, get_vim_by_id from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE from lcm.pub.utils.values import ignore_case_get +from lcm.ns.vnfs.serializers import InstVnfReqSerializer +from lcm.ns.vnfs.serializers import InstVnfRespSerializer +from lcm.ns.vnfs.serializers import GetVnfRespSerializer logger = logging.getLogger(__name__) class NfView(APIView): + @swagger_auto_schema( + request_body=InstVnfReqSerializer(), + responses={ + status.HTTP_202_ACCEPTED: InstVnfRespSerializer() + } + ) def post(self, request): logger.debug("VnfCreateView--post::> %s" % request.data) + + req_serializer = InstVnfReqSerializer(data=request.data) + if not req_serializer.is_valid(): + logger.error(req_serializer.errors) + data = {'ns_instance_id': ignore_case_get(request.data, 'nsInstanceId'), 'additional_param_for_ns': ignore_case_get(request.data, 'additionalParamForVnf'), 'additional_param_for_vnf': ignore_case_get(request.data, 'additionalParamForVnf'), @@ -47,18 +62,38 @@ class NfView(APIView): rsp = { "vnfInstId": nf_inst_id, "jobId": job_id} + + resp_serializer = InstVnfRespSerializer(data=rsp) + if not resp_serializer.is_valid(): + logger.error(resp_serializer.errors) + return Response(data=rsp, status=status.HTTP_202_ACCEPTED) class NfDetailView(APIView): + @swagger_auto_schema( + request_body=None, + responses={ + status.HTTP_200_OK: GetVnfRespSerializer(), + status.HTTP_404_NOT_FOUND: "VNF not found" + } + ) def get(self, request, vnfinstid): logger.debug("VnfQueryView--get::> %s" % vnfinstid) nf_inst_info = GetVnf(vnfinstid).do_biz() if not nf_inst_info: return Response(status=status.HTTP_404_NOT_FOUND) - return Response(status=status.HTTP_200_OK, - data={'vnfInstId': nf_inst_info[0].nfinstid, 'vnfName': nf_inst_info[0].nf_name, - 'vnfStatus': nf_inst_info[0].status}) + + rsp = { + 'vnfInstId': nf_inst_info[0].nfinstid, + 'vnfName': nf_inst_info[0].nf_name, + 'vnfStatus': nf_inst_info[0].status + } + resp_serializer = GetVnfRespSerializer(data=rsp) + if not resp_serializer.is_valid(): + logger.error(resp_serializer.errors) + + return Response(status=status.HTTP_200_OK, data=rsp) def post(self, request_paras, vnfinstid): logger.debug("VnfTerminateView--post::> %s, %s", vnfinstid, request_paras.data)