diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2017-08-17 09:14:30 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2017-08-17 09:14:30 +0800 |
commit | 67086d091cf050ac4d97aeeec5851fc486b62d25 (patch) | |
tree | 7903ce09abae54df9b25e22bf43db353a6ecade6 | |
parent | b01b0ffe63b61d2877a388cc2fb21f699763c7a0 (diff) |
Add nf pkg get and delete logic
Change-Id: I6ffe7163a5da74c4ae1bdd52923ba3fc47646f69
Issue-Id: VFC-104
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/packages/sdc_nf_package.py | 29 | ||||
-rw-r--r-- | lcm/packages/urls.py | 1 | ||||
-rw-r--r-- | lcm/packages/views.py | 42 |
3 files changed, 59 insertions, 13 deletions
diff --git a/lcm/packages/sdc_nf_package.py b/lcm/packages/sdc_nf_package.py index 88bfd5c1..01df7812 100644 --- a/lcm/packages/sdc_nf_package.py +++ b/lcm/packages/sdc_nf_package.py @@ -34,6 +34,29 @@ logger = logging.getLogger(__name__) JOB_ERROR = 255 +def nf_get_csars(): + ret = None + try: + ret = SdcNfPackage().get_csars() + except NSLCMException as e: + return [1, e.message] + except: + logger.error(traceback.format_exc()) + return [1, str(sys.exc_info())] + return ret + +def nf_get_csar(csar_id): + ret = None + try: + ret = SdcNfPackage().get_csar(csar_id) + except NSLCMException as e: + return [1, e.message] + except: + logger.error(traceback.format_exc()) + return [1, str(sys.exc_info())] + return ret + +##################################################################################### class SdcNfDistributeThread(threading.Thread): """ @@ -158,14 +181,14 @@ class SdcNfPackage(object): pass def get_csars(self): - ret = {"csars": []} + csars = {"csars": []} nf_pkgs = NfPackageModel.objects.filter() for nf_pkg in nf_pkgs: - ret["csars"].append({ + csars["csars"].append({ "csarId": nf_pkg.nfpackageid, "vnfdId": nf_pkg.vnfdid }) - return ret + return [0, csars] def get_csar(self, csar_id): pkg_info = {} diff --git a/lcm/packages/urls.py b/lcm/packages/urls.py index bef33f39..10bf8357 100644 --- a/lcm/packages/urls.py +++ b/lcm/packages/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ url(r'^api/nslcm/v1/nspackage$', views.ns_distribute_get, name='ns_distribute_get'), url(r'^api/nslcm/v1/nspackage/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_rd_csar, name='ns_rd_csar'), url(r'^api/nslcm/v1/vnfpackage$', views.nf_distribute_get, name='nf_distribute_get'), + url(r'^api/nslcm/v1/vnfpackage/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.nf_rd_csar, name='nf_rd_csar'), ######################################################################################### url(r'^api/nslcm/v0/nspackage/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_access_csar, name='ns_access_csar'), url(r'^api/nslcm/v0/nspackage$', views.ns_on_boarding, name='ns_on_boarding'), diff --git a/lcm/packages/views.py b/lcm/packages/views.py index 44c1c76c..a5d91abf 100644 --- a/lcm/packages/views.py +++ b/lcm/packages/views.py @@ -66,19 +66,41 @@ def ns_rd_csar(request, *args, **kwargs): @api_view(http_method_names=['POST', 'GET']) def nf_distribute_get(request, *args, **kwargs): logger.debug("Enter %s%s, method is %s", fun_name(), request.data, request.method) + ret, normal_status = None, None if request.method == 'GET': - ret = sdc_nf_package.SdcNfPackage().get_csars() - logger.debug("csars=%s", ret) - return Response(data=ret, status=status.HTTP_200_OK) - csar_id = ignore_case_get(request.data, "csarId") - vim_ids = ignore_case_get(request.data, "vimIds") - lab_vim_id = ignore_case_get(request.data, "labVimId") - job_id = str(uuid.uuid4()) - sdc_nf_package.SdcNfDistributeThread(csar_id, vim_ids, lab_vim_id, job_id).start() - ret = {"jobId": job_id} + ret = sdc_nf_package.nf_get_csars() + normal_status = status.HTTP_200_OK + else: + csar_id = ignore_case_get(request.data, "csarId") + vim_ids = ignore_case_get(request.data, "vimIds") + lab_vim_id = ignore_case_get(request.data, "labVimId") + job_id = str(uuid.uuid4()) + sdc_nf_package.SdcNfDistributeThread(csar_id, vim_ids, lab_vim_id, job_id).start() + ret = [0, {"jobId": job_id}] + normal_status = status.HTTP_202_ACCEPTED logger.debug("Leave %s, Return value is %s", fun_name(), ret) - return Response(data=ret, status=status.HTTP_202_ACCEPTED) + if ret[0] != 0: + return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data=ret[1], status=normal_status) +@api_view(http_method_names=['GET', 'DELETE']) +def nf_rd_csar(request, *args, **kwargs): + csar_id = ignore_case_get(kwargs, "csarId") + logger.info("Enter %s, method is %s, csar_id is %s", fun_name(), request.method, csar_id) + ret, normal_status = None, None + if request.method == 'GET': + ret = sdc_nf_package.nf_get_csar(csar_id) + normal_status = status.HTTP_200_OK + else: + force_delete = csar_id.endswith("force") + if force_delete: + csar_id = csar_id[:-5] + ret = sdc_nf_package.nf_delete_csar(csar_id, force_delete) + normal_status = status.HTTP_202_ACCEPTED + logger.info("Leave %s, Return value is %s", fun_name(), str(ret)) + if ret[0] != 0: + return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data=ret[1], status=normal_status) #################################################################################################### |