From: biancunkang Date: Wed, 22 Aug 2018 07:54:17 +0000 (+0800) Subject: Deal with nfPackage X-Git-Tag: 1.2.0~105^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=60b78feccc2463fd5e877addc5361e9020a8cb7b;p=vfc%2Fnfvo%2Fcatalog.git Deal with nfPackage Change-Id: I648914cadf84d4e08cc2704eedee9bea93c4a923 Issue-ID: VFC-1038 Signed-off-by: biancunkang --- diff --git a/catalog/packages/urls.py b/catalog/packages/urls.py index 75d4c71f..ead9bc87 100644 --- a/catalog/packages/urls.py +++ b/catalog/packages/urls.py @@ -14,7 +14,7 @@ from django.conf.urls import url -from catalog.packages.views.vnfpkg_views import package_content, upload_from_uri +from catalog.packages.views.vnfpkg_views import package_content, upload_from_uri, vnf_packages from catalog.packages.views import (catalog_views, ns_descriptor_views, nsd_content_views, pnf_descriptor_views, pnfd_content_views) @@ -42,7 +42,7 @@ urlpatterns = [ # url(r'^api/nsd/v1/subscriptions', nsd_subscriptions.as_view(), name='subscriptions_rc'), # url(r'^api/nsd/v1/subscriptions/(?P[0-9a-zA-Z\-\_]+)$', nsd_subscription.as_view(), name='subscription_rd'), - # url(r'^api/vnfpkgm/v1/vnf_packages', vnf_packages.as_view(), name='vnf_packages_rc'), + url(r'^api/vnfpkgm/v1/vnf_packages$', vnf_packages.as_view(), name='vnf_packages_rc'), # url(r'^api/vnfpkgm/v1/vnf_packages/(?P[0-9a-zA-Z\-\_]+)$', vnf_package.as_view(), name='vnf_package_rd'), # url(r'^api/vnfpkgm/v1/vnf_packages/(?P[0-9a-zA-Z\-\_]+)/vnfd$', vnfd.as_view(), name='vnfd_r'), url(r'^api/vnfpkgm/v1/vnf_packages/(?P[0-9a-zA-Z\-\_]+)/package_content$', diff --git a/catalog/packages/views/vnfpkg_views.py b/catalog/packages/views/vnfpkg_views.py index 0b48702e..1ef8aebe 100644 --- a/catalog/packages/views/vnfpkg_views.py +++ b/catalog/packages/views/vnfpkg_views.py @@ -23,6 +23,9 @@ from rest_framework.response import Response from catalog.packages.biz.nf_package import VnfpkgUploadThread from catalog.pub.exceptions import CatalogException from catalog.packages.serializers.upload_vnf_pkg_from_uri_req import UploadVnfPackageFromUriRequestSerializer +from catalog.packages.serializers.create_vnf_pkg_info_req import CreateVnfPkgInfoRequestSerializer +from catalog.packages.serializers.vnf_pkg_info import VnfPkgInfoSerializer +from catalog.packages.biz.nf_package import create_vnf_pkg logger = logging.getLogger(__name__) @@ -39,15 +42,26 @@ class vnf_packages(APIView): return None @swagger_auto_schema( - # request_body=CreateVnfReqSerializer(), + request_body=CreateVnfPkgInfoRequestSerializer(), responses={ - # status.HTTP_201_CREATED: CreateVnfRespSerializer(), + status.HTTP_201_CREATED: VnfPkgInfoSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" } ) def post(self, request): - # TODO - return None + logger.debug("CreateVnfPkg> %s" % request.data) + try: + req_serializer = CreateVnfPkgInfoRequestSerializer(data=request.data) + if not req_serializer.is_valid(): + raise CatalogException + res = create_vnf_pkg(req_serializer.data) + create_vnf_pkg_resp_serializer = VnfPkgInfoSerializer(data=res) + if not create_vnf_pkg_resp_serializer.is_valid(): + raise CatalogException + return Response(data=create_vnf_pkg_resp_serializer.data, status=status.HTTP_201_CREATED) + except CatalogException: + logger.error(traceback.format_exc()) + return Response(data={'error': 'Creating vnfPkg failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) class vnf_package(APIView):