diff options
author | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-24 14:13:38 +0800 |
---|---|---|
committer | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-24 14:13:38 +0800 |
commit | a27f6de826fb35e35b1571c730d8a12b792959c8 (patch) | |
tree | 7c827bbac96333ad0bdb76a98fe15eac1937aeac | |
parent | c4f1304d3135422ace319b94aaac95176510a6fb (diff) |
Deal with pnfd
Change-Id: If689084b1d75db7c3f8a6c0f6f45af5373402f3d
Issue-ID: VFC-1038
Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
-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', |