From: biancunkang Date: Tue, 21 Aug 2018 07:24:57 +0000 (+0800) Subject: Deal with nfPackage X-Git-Tag: 1.2.0~122 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=771e8e0a46f27f9d1c3f323622383f3426e1df1a;p=vfc%2Fnfvo%2Fcatalog.git Deal with nfPackage Change-Id: Ib714cca4a50477824f7f0f403ff1363f8291e494 Issue-ID: VFC-1038 Signed-off-by: biancunkang --- diff --git a/catalog/packages/urls.py b/catalog/packages/urls.py index 7cd72cde..a3b4f0fe 100644 --- a/catalog/packages/urls.py +++ b/catalog/packages/urls.py @@ -15,6 +15,7 @@ from django.conf.urls import url from catalog.packages.views import catalog_views, ns_descriptor_views, nsd_content_views +from catalog.packages.views.vnfpkg_views import package_content urlpatterns = [ @@ -39,7 +40,8 @@ urlpatterns = [ # 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$', package_content.as_view(), name='package_content_ru'), + url(r'^api/vnfpkgm/v1/vnf_packages/(?P[0-9a-zA-Z\-\_]+)/package_content$', + package_content.as_view(), name='package_content_ru'), # url(r'^api/vnfpkgm/v1/vnf_packages/(?P[0-9a-zA-Z\-\_]+)/package_content/upload_from_uri$', upload_from_uri.as_view(), name='upload_from_uri_c'), # url(r'^api/vnfpkgm/v1/vnf_packages/(?P[0-9a-zA-Z\-\_]+)/artifacts/artifactPath$', artifacts.as_view(), name='artifacts_r'), # url(r'^api/vnfpkgm/v1/subscriptions', vnfpkg_subscriptions.as_view(), name='subscriptions_rc'), diff --git a/catalog/packages/views/vnfpkg_views.py b/catalog/packages/views/vnfpkg_views.py index a95bcd1a..98c6dd99 100644 --- a/catalog/packages/views/vnfpkg_views.py +++ b/catalog/packages/views/vnfpkg_views.py @@ -12,9 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os +import traceback +import logging +from catalog.pub.config.config import CATALOG_ROOT_PATH from drf_yasg.utils import swagger_auto_schema from rest_framework import status from rest_framework.views import APIView +from rest_framework.response import Response + +logger = logging.getLogger(__name__) class vnf_packages(APIView): @@ -108,6 +115,22 @@ class package_content(APIView): # TODO return None + def put(self, request, vnfPkgId): + logger.debug("UploadVnf %s" % vnfPkgId) + file_object = request.FILES.get('file') + upload_path = os.path.join(CATALOG_ROOT_PATH, vnfPkgId) + if not os.path.exists(upload_path): + os.makedirs(upload_path, 0o777) + try: + upload_file_name = os.path.join(upload_path, file_object.name) + with open(upload_file_name, 'wb+') as dest_file: + for chunk in file_object.chunks(): + dest_file.write(chunk) + except Exception as e: + logger.error("File upload exception.[%s:%s]" % (type(e), str(e))) + logger.error("%s", traceback.format_exc()) + return Response(None, status.HTTP_202_ACCEPTED) + class upload_from_uri(APIView): @swagger_auto_schema(