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
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'),
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)