diff options
author | fengyuanxing <feng.yuanxing@zte.com.cn> | 2018-01-29 16:06:47 +0800 |
---|---|---|
committer | fengyuanxing <feng.yuanxing@zte.com.cn> | 2018-01-29 16:50:09 +0800 |
commit | 6e419424f210e9703ff094ba4efe37d61f9bf630 (patch) | |
tree | 0932932f2cef3e68dbaa3a8e6d20379428d871a5 | |
parent | ec6d4382849a899f7dc5934ed1ff4e669d2d185a (diff) |
Add code for swagger of delete/get nf package
Change-Id: I1a1432c072bd09d87f371a385059ef87b4d00966
Issue-ID: VFC-685
Signed-off-by: fengyuanxing <feng.yuanxing@zte.com.cn>
-rw-r--r-- | catalog/packages/views.py | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/catalog/packages/views.py b/catalog/packages/views.py index 3c6623eb..40971543 100644 --- a/catalog/packages/views.py +++ b/catalog/packages/views.py @@ -24,10 +24,11 @@ from catalog.packages import ns_package from catalog.serializers import NsPackagesSerializer from catalog.serializers import NfPackagesSerializer from catalog.serializers import NfPackageDistributeRequestSerializer -from catalog.serializers import PostJobResponseSerializer +from catalog.serializers import NfPackageSerializer from catalog.serializers import ParseModelRequestSerializer from catalog.serializers import ParseModelResponseSerializer from catalog.serializers import InternalErrorRequestSerializer +from catalog.serializers import PostJobResponseSerializer from drf_yasg import openapi from drf_yasg.utils import no_body, swagger_auto_schema @@ -169,26 +170,68 @@ def ns_rd_csar(request, *args, **kwargs): return Response(data=ret[1], status=normal_status) +@swagger_auto_schema( + method='DELETE', + operation_description="Delete one Nf package", + request_body=no_body, + manual_parameters=[ + openapi.Parameter( + 'csarId', + openapi.IN_QUERY, + "csarId", + type=openapi.TYPE_STRING)], + responses={ + status.HTTP_200_OK: PostJobResponseSerializer, + status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response( + 'error message', + openapi.Schema( + type=openapi.TYPE_STRING))}) +@swagger_auto_schema( + method='GET', + operation_description="Query one Nf package", + request_body=no_body, + manual_parameters=[ + openapi.Parameter( + 'csarId', + openapi.IN_QUERY, + "csarId", + type=openapi.TYPE_STRING)], + responses={ + status.HTTP_200_OK: NfPackageSerializer, + status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response( + 'error message', + openapi.Schema( + type=openapi.TYPE_STRING))}) @api_view(http_method_names=['DELETE', 'GET']) def nf_rd_csar(request, *args, **kwargs): csar_id = ignore_case_get(kwargs, "csarId") logger.info("Enter %s, method is %s, csar_id is %s", fun_name(), request.method, csar_id) - ret, normal_status = None, None + ret, normal_status, validation_error = None, None, None + if request.method == 'GET': ret = nf_package.nf_get_csar(csar_id) normal_status = status.HTTP_200_OK + response_serializer = NfPackageSerializer(data=ret[1]) + elif request.method == 'DELETE': job_id = str(uuid.uuid4()) nf_package.NfPkgDeleteThread(csar_id, job_id).start() ret = [0, {"jobId": job_id}] normal_status = status.HTTP_202_ACCEPTED + response_serializer = PostJobResponseSerializer(data=ret[1]) + logger.info("Leave %s, Return value is %s", fun_name(), ret) if ret[0] != 0: return Response( data={ 'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + if not response_serializer.is_valid(): + validation_error = handleValidatonError(response_serializer, False) + return validation_error + return Response(data=ret[1], status=normal_status) |