1 # Copyright 2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from drf_yasg.utils import swagger_auto_schema
19 from rest_framework import status
20 from rest_framework.decorators import api_view
21 from rest_framework.response import Response
23 from catalog.packages.biz.pnf_descriptor import create
24 from catalog.packages.serializers.create_pnfd_info_request import \
25 CreatePnfdInfoRequestSerializer
26 from catalog.packages.serializers.pnfd_info import PnfdInfoSerializer
27 from catalog.pub.exceptions import CatalogException
29 logger = logging.getLogger(__name__)
34 # status.HTTP_200_OK: Serializer(),
35 status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
38 # @api_view(http_method_names=['GET'])
39 def query_multiple_pnfds(self, request):
46 # status.HTTP_200_OK: Serializer(),
47 status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
50 # @api_view(http_method_names=['GET'])
51 def query_single_pnfd(self, request):
58 operation_description="Create an individual PNF descriptor resource",
59 request_body=CreatePnfdInfoRequestSerializer(),
61 status.HTTP_201_CREATED: PnfdInfoSerializer(),
62 status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
65 @api_view(http_method_names=['POST'])
66 def create_pnf_descriptors(request, *args, **kwargs):
68 create_pnfd_info_request = CreatePnfdInfoRequestSerializer(data=request.data)
69 if not create_pnfd_info_request.is_valid():
70 raise CatalogException
71 data = create(create_pnfd_info_request.data)
72 pnfd_info = PnfdInfoSerializer(data=data)
73 if not pnfd_info.is_valid():
74 raise CatalogException
75 return Response(data=pnfd_info.data, status=status.HTTP_201_CREATED)
76 except CatalogException:
77 logger.error(traceback.format_exc())
78 return Response(data={'error': 'Creating pnfd info failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)