diff options
author | Olivia2047 <zhan.jie1@zte.com.cn> | 2018-02-09 11:17:11 +0800 |
---|---|---|
committer | Olivia2047 <zhan.jie1@zte.com.cn> | 2018-02-09 11:17:11 +0800 |
commit | 450eae26dce786168dbadd26743a04d2c9083322 (patch) | |
tree | b955abd4dc1c5b57e2666375b27a396d2115f55c | |
parent | 30d6ad8562fb87c8ae0c90a50019662c12ec43e7 (diff) |
Add auto swagger code for VnfTermInfo VnfQueryInfo
Change-Id: I77787c2b85811e2f0d3bd708749c6617316c27e5
Issue-ID: VFC-737
Signed-off-by: Olivia2047 <zhan.jie1@zte.com.cn>
-rw-r--r-- | gvnfmadapter/driver/interfaces/serializers.py | 44 | ||||
-rw-r--r-- | gvnfmadapter/driver/interfaces/views.py | 25 |
2 files changed, 57 insertions, 12 deletions
diff --git a/gvnfmadapter/driver/interfaces/serializers.py b/gvnfmadapter/driver/interfaces/serializers.py index 4c0916a..c0fcdc7 100644 --- a/gvnfmadapter/driver/interfaces/serializers.py +++ b/gvnfmadapter/driver/interfaces/serializers.py @@ -32,15 +32,25 @@ class AdditionalParams(serializers.Serializer): ) -class VnfRequestParamsSerializer(serializers.Serializer): +class VnfInstReqParamsSerializer(serializers.Serializer): vnfDescriptorId = serializers.CharField( help_text="Identifier that identifies the VNFD which defines the VNF instance to be created.", - required=True + max_length=255, + required=True, + allow_null=True ) vnfInstanceName = serializers.CharField( - help_text="Human-readable name of the VNF instance to be created.", required=True) + help_text="Human-readable name of the VNF instance to be created.", + max_length=255, + required=True, + allow_null=False + ) vnfInstanceDescription = serializers.CharField( - help_text="Human-readable description of the VNF instance to be created.", required=False) + help_text="Human-readable description of the VNF instance to be created.", + max_length=255, + required=False, + allow_null=True + ) additionalParam = AdditionalParams( help_text="Additional input parameters for the instantiation process," " specific to the VNF being instantiated.", @@ -49,9 +59,27 @@ class VnfRequestParamsSerializer(serializers.Serializer): class ResponseSerializer(serializers.Serializer): - vnfInstanceId = serializers.CharField(help_text="VNF instance identifier", required=True) - jobId = serializers.CharField(help_text="Job ID", required=True) + vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True) + jobId = serializers.CharField(help_text="Job ID.", required=True) + +class VnfTermReqSerializer(serializers.Serializer): + vnfInstanceId = serializers.CharField( + help_text="VNF instance identifier.", + max_length=255, + required=True, + allow_null=True + ) + + +class VnfInfo(serializers.Serializer): + vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True) + vnfStatus = serializers.CharField(help_text="The instantiation state of the VNF.", required=True) + version = serializers.CharField(help_text="Version of the VNF.", required=True) -class ErrorSerializer(serializers.Serializer): - error = serializers.CharField(help_text="error message", required=True) + +class VnfQueryRespSerializer(serializers.Serializer): + vnfInfo = VnfInfo( + help_text="The information items about the selected VNF instance(s) that are returned.", + required=True + ) diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py index 7c56408..eb7c0c9 100644 --- a/gvnfmadapter/driver/interfaces/views.py +++ b/gvnfmadapter/driver/interfaces/views.py @@ -26,24 +26,26 @@ from rest_framework.views import APIView from driver.pub.exceptions import GvnfmDriverException from driver.pub.utils import restcall from driver.pub.utils.restcall import req_by_msb -from driver.interfaces.serializers import VnfRequestParamsSerializer, ResponseSerializer, ErrorSerializer +from driver.interfaces.serializers import VnfInstReqParamsSerializer, ResponseSerializer +from driver.interfaces.serializers import VnfTermReqSerializer, VnfQueryRespSerializer logger = logging.getLogger(__name__) class VnfInstInfo(APIView): @swagger_auto_schema( - request_body=VnfRequestParamsSerializer(), + request_body=VnfInstReqParamsSerializer(), responses={ status.HTTP_201_CREATED: ResponseSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: ErrorSerializer() + status.HTTP_404_NOT_FOUND: "The vnfm instance id is wrong", + status.HTTP_500_INTERNAL_SERVER_ERROR: "The url is invalid" } ) def post(self, request, vnfmtype, vnfmid): logger.debug("instantiate_vnf--post::> %s" % request.data) logger.debug("Create vnf begin!") try: - requestSerializer = VnfRequestParamsSerializer(data=request.data) + requestSerializer = VnfInstReqParamsSerializer(data=request.data) request_isValid = requestSerializer.is_valid() if not request_isValid: raise Exception(requestSerializer.errors) @@ -87,6 +89,14 @@ class VnfInstInfo(APIView): class VnfTermInfo(APIView): + @swagger_auto_schema( + request_body=VnfTermReqSerializer(), + responses={ + status.HTTP_201_CREATED: ResponseSerializer(), + status.HTTP_404_NOT_FOUND: "The vnfmid and vnfInstanceId are wrong", + status.HTTP_500_INTERNAL_SERVER_ERROR: "The url is invalid" + } + ) def post(self, request, vnfmtype, vnfmid, vnfInstanceId): logger.debug("terminate_vnf--post::> %s" % request.data) logger.debug("Terminate vnf begin!") @@ -126,6 +136,13 @@ class VnfTermInfo(APIView): class VnfQueryInfo(APIView): + @swagger_auto_schema( + responses={ + status.HTTP_201_CREATED: VnfQueryRespSerializer(), + status.HTTP_404_NOT_FOUND: "The vnfmid and vnfInstanceId are wrong", + status.HTTP_500_INTERNAL_SERVER_ERROR: "The url is invalid" + } + ) def get(self, request, vnfmtype, vnfmid, vnfInstanceId): logger.debug("query_vnf--post::> %s" % request.data) vnfm_id = vnfmid |