diff options
-rw-r--r-- | catalog/packages/biz/pnf_descriptor.py | 17 | ||||
-rw-r--r-- | catalog/packages/views/pnf_descriptor_views.py | 16 |
2 files changed, 29 insertions, 4 deletions
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py index 74812912..0ae89e0f 100644 --- a/catalog/packages/biz/pnf_descriptor.py +++ b/catalog/packages/biz/pnf_descriptor.py @@ -112,11 +112,11 @@ def upload(files, pnfd_info_id): local_file.write(data) -def query_single(pnfdInfoId): +def query_single(pnfd_info_id): pkg_info = {} - pnf_pkg = PnfPackageModel.objects.filter(pnfPackageId=pnfdInfoId) + pnf_pkg = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id) if not pnf_pkg.exists(): - raise CatalogException('PNF descriptor (%s) does not exist.' % pnfdInfoId) + raise CatalogException('PNF descriptor (%s) does not exist.' % pnfd_info_id) pkg_info["id"] = pnf_pkg[0].pnfPackageId pkg_info["pnfdId"] = pkg_info[0].pnfdId pkg_info["pnfdName"] = pnf_pkg[0].pnfdProductName @@ -129,3 +129,14 @@ def query_single(pnfdInfoId): pkg_info["userDefinedData"] = pnf_pkg[0].userDefinedData pkg_info["_links"] = "" # TODO return pkg_info + + +def delete_pnf(pnfd_info_id): + # TODO + pnf_pkg = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id) + if not pnf_pkg.exists(): + logger.debug('PNF resource(%s) is deleted.' % pnfd_info_id) + return + pnf_pkg.delete() + vnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, pnfd_info_id) + fileutil.delete_dirs(vnf_pkg_path) diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py index 76ec07ee..1103c43c 100644 --- a/catalog/packages/views/pnf_descriptor_views.py +++ b/catalog/packages/views/pnf_descriptor_views.py @@ -20,7 +20,7 @@ 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, query_multiple, upload, query_single +from catalog.packages.biz.pnf_descriptor import create, query_multiple, upload, query_single, delete_pnf from catalog.packages.serializers.create_pnfd_info_request import \ CreatePnfdInfoRequestSerializer from catalog.packages.serializers.pnfd_info import PnfdInfoSerializer @@ -67,6 +67,20 @@ def pnfd_info_rd(request, pnfdInfoId): logger.error(traceback.format_exc()) return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + if request.method == 'DELETE': + logger.debug("Delete an individual PNFD resource> %s" % request.data) + try: + delete_pnf(pnfdInfoId) + return Response(data=None, status=status.HTTP_204_NO_CONTENT) + except CatalogException: + logger.error(traceback.format_exc()) + return Response(data={'error': 'Delete an individual PNFD resource failed.'}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except Exception as e: + logger.error(e.message) + logger.error(traceback.format_exc()) + return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + @swagger_auto_schema( method='POST', |