From ae56055ece5392b8b987206a305567841a9918b7 Mon Sep 17 00:00:00 2001 From: laili Date: Tue, 21 Aug 2018 18:26:26 +0800 Subject: [PATCH] Ns descriptor related stuffs. Implement the view of the creation of pnfd. Change-Id: I5e5f29f359d16852f3a0bdd3a0e7f887a737c306 Issue-ID: VFC-1037 Signed-off-by: laili --- catalog/packages/views/pnf_descriptor_views.py | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 catalog/packages/views/pnf_descriptor_views.py diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py new file mode 100644 index 00000000..2e56c33c --- /dev/null +++ b/catalog/packages/views/pnf_descriptor_views.py @@ -0,0 +1,78 @@ +# Copyright 2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +import traceback + +from drf_yasg.utils import swagger_auto_schema +from rest_framework import status +from rest_framework.decorators import api_view +from rest_framework.response import Response + +from catalog.packages.biz.pnf_descriptor import create +from catalog.packages.serializers.create_pnfd_info_request import \ + CreatePnfdInfoRequestSerializer +from catalog.packages.serializers.pnfd_info import PnfdInfoSerializer +from catalog.pub.exceptions import CatalogException + +logger = logging.getLogger(__name__) + + +@swagger_auto_schema( + responses={ + # status.HTTP_200_OK: Serializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + } +) +# @api_view(http_method_names=['GET']) +def query_multiple_pnfds(self, request): + # TODO + return None + + +@swagger_auto_schema( + responses={ + # status.HTTP_200_OK: Serializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + } +) +# @api_view(http_method_names=['GET']) +def query_single_pnfd(self, request): + # TODO + return None + + +@swagger_auto_schema( + method='POST', + operation_description="Create an individual PNF descriptor resource", + request_body=CreatePnfdInfoRequestSerializer(), + responses={ + status.HTTP_201_CREATED: PnfdInfoSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + } +) +@api_view(http_method_names=['POST']) +def create_pnf_descriptors(request, *args, **kwargs): + try: + create_pnfd_info_request = CreatePnfdInfoRequestSerializer(data=request.data) + if not create_pnfd_info_request.is_valid(): + raise CatalogException + data = create(create_pnfd_info_request.data) + pnfd_info = PnfdInfoSerializer(data=data) + if not pnfd_info.is_valid(): + raise CatalogException + return Response(data=pnfd_info.data, status=status.HTTP_201_CREATED) + except CatalogException: + logger.error(traceback.format_exc()) + return Response(data={'error': 'Creating pnfd info failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) -- 2.16.6