From 0154bfe3242ec3b685c8c6fad2a301a1d54104d4 Mon Sep 17 00:00:00 2001 From: laili Date: Thu, 23 Aug 2018 13:38:20 +0800 Subject: [PATCH] Ns descriptor related stuffs. Merge pnfd_content_views int pnf_descriptor_views. Change-Id: I472917f2ed01a773b95d88bbc2ce85568610e30d Issue-ID: VFC-1037 Signed-off-by: laili --- catalog/packages/urls.py | 5 +- catalog/packages/views/pnf_descriptor_views.py | 26 +++++++++- catalog/packages/views/pnfd_content_views.py | 71 -------------------------- 3 files changed, 26 insertions(+), 76 deletions(-) delete mode 100644 catalog/packages/views/pnfd_content_views.py diff --git a/catalog/packages/urls.py b/catalog/packages/urls.py index 19688c6d..b656c755 100644 --- a/catalog/packages/urls.py +++ b/catalog/packages/urls.py @@ -15,8 +15,7 @@ from django.conf.urls import url from catalog.packages.views import vnf_package_views -from catalog.packages.views import (catalog_views, ns_descriptor_views, pnf_descriptor_views, - pnfd_content_views) +from catalog.packages.views import catalog_views, ns_descriptor_views, pnf_descriptor_views urlpatterns = [ @@ -34,7 +33,7 @@ urlpatterns = [ # PNF url(r'^api/nsd/v1/pnf_descriptors$', pnf_descriptor_views.create_pnf_descriptors, name='pnf_descriptors_rc'), - url(r'^api/nsd/v1/pnf_descriptors/(?P[0-9a-zA-Z\-\_]+)/pnfd_content$', pnfd_content_views.upload_pnfd_content, name='pnfd_content_ru'), + url(r'^api/nsd/v1/pnf_descriptors/(?P[0-9a-zA-Z\-\_]+)/pnfd_content$', pnf_descriptor_views.pnfd_content_ru, name='pnfd_content_ru'), # TODO SOL005 & SOL003 # url(r'^api/nsd/v1/pnf_descriptors/(?P[0-9a-zA-Z\-\_]+)$', pnfd_info.as_view(), name='pnfd_info_rd'), diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py index 2e56c33c..fecba347 100644 --- a/catalog/packages/views/pnf_descriptor_views.py +++ b/catalog/packages/views/pnf_descriptor_views.py @@ -15,12 +15,12 @@ import logging import traceback -from drf_yasg.utils import swagger_auto_schema +from drf_yasg.utils import no_body, 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.biz.pnf_descriptor import create, upload from catalog.packages.serializers.create_pnfd_info_request import \ CreatePnfdInfoRequestSerializer from catalog.packages.serializers.pnfd_info import PnfdInfoSerializer @@ -76,3 +76,25 @@ def create_pnf_descriptors(request, *args, **kwargs): except CatalogException: logger.error(traceback.format_exc()) return Response(data={'error': 'Creating pnfd info failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + +@swagger_auto_schema( + method='PUT', + operation_description="Upload PNFD content", + request_body=no_body, + responses={ + status.HTTP_204_NO_CONTENT: {}, + status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + } +) +@api_view(http_method_names=['PUT']) +def pnfd_content_ru(request, *args, **kwargs): + pnfd_info_id = kwargs.get("pnfdInfoId") + files = request.FILES.getlist('file') + try: + upload(files, pnfd_info_id) + return Response(data={}, status=status.HTTP_204_NO_CONTENT) + except IOError: + logger.error(traceback.format_exc()) + raise CatalogException + return Response(data={'error': 'Uploading pnfd content failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/catalog/packages/views/pnfd_content_views.py b/catalog/packages/views/pnfd_content_views.py deleted file mode 100644 index b991c763..00000000 --- a/catalog/packages/views/pnfd_content_views.py +++ /dev/null @@ -1,71 +0,0 @@ -# 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 no_body, 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 upload -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" - } -) -def get(self, request): - # TODO - return None - - -@swagger_auto_schema( - # request_body=CreateVnfReqSerializer(), - responses={ - # status.HTTP_201_CREATED: CreateVnfRespSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" - } -) -def post(self, request): - # TODO - return None - - -@swagger_auto_schema( - method='PUT', - operation_description="Upload PNFD content", - request_body=no_body, - responses={ - status.HTTP_204_NO_CONTENT: {}, - status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" - } -) -@api_view(http_method_names=['PUT']) -def upload_pnfd_content(request, *args, **kwargs): - pnfd_info_id = kwargs.get("pnfdInfoId") - files = request.FILES.getlist('file') - try: - upload(files, pnfd_info_id) - return Response(data={}, status=status.HTTP_204_NO_CONTENT) - except IOError: - logger.error(traceback.format_exc()) - raise CatalogException - return Response(data={'error': 'Uploading pnfd content failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) -- 2.16.6