From 17e5ab17a74dc19cb4dde033c17b8b67e30aef89 Mon Sep 17 00:00:00 2001 From: laili Date: Wed, 22 Aug 2018 17:35:22 +0800 Subject: [PATCH] Ns descriptor related stuffs. Add the view for deletion of an individual nsd. Change-Id: Ib0b2ce3b59c9b7ebd486446329c1d9bf9fba0b9e Issue-ID: VFC-1037 Signed-off-by: laili --- catalog/packages/views/ns_descriptor_views.py | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py index eb673aba..455b01ae 100644 --- a/catalog/packages/views/ns_descriptor_views.py +++ b/catalog/packages/views/ns_descriptor_views.py @@ -20,7 +20,7 @@ from rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response -from catalog.packages.biz.ns_descriptor import create, query_multiple, query_single +from catalog.packages.biz.ns_descriptor import create, query_multiple, query_single, delete_single from catalog.packages.serializers.create_nsd_info_request import \ CreateNsdInfoRequestSerializer from catalog.packages.serializers.nsd_info import NsdInfoSerializer @@ -29,26 +29,26 @@ from catalog.pub.exceptions import CatalogException logger = logging.getLogger(__name__) -""" + @swagger_auto_schema( + method='GET', + operation_description="Query an individual NS descriptor resource", + request_body=no_body, responses={ - # status.HTTP_200_OK: Serializer(), + status.HTTP_200_OK: NsdInfoSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" } ) -""" - - @swagger_auto_schema( - method='GET', - operation_description="Query an individual NS descriptor resource", + method='DELETE', + operation_description="Delete an individual NS descriptor resource", request_body=no_body, responses={ - status.HTTP_200_OK: NsdInfoSerializer(), + status.HTTP_204_NO_CONTENT: {}, status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" } ) -@api_view(http_method_names=['GET']) +@api_view(http_method_names=['GET', 'DELETE']) def ns_info_rd(request, nsdInfoId): if request.method == 'GET': try: @@ -64,6 +64,17 @@ def ns_info_rd(request, nsdInfoId): status=status.HTTP_500_INTERNAL_SERVER_ERROR ) + if request.method == 'DELETE': + try: + data = delete_single(nsdInfoId) + return Response(data={}, status=status.HTTP_204_NO_CONTENT) + except CatalogException: + logger.error(traceback.format_exc()) + return Response( + data={'error': 'Deletion of an individual NS descriptor resource failed.'}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR + ) + @swagger_auto_schema( method='POST', -- 2.16.6