From 1378fb5df25dc382a71c340805c2149d634afed0 Mon Sep 17 00:00:00 2001 From: laili Date: Fri, 24 Aug 2018 17:36:29 +0800 Subject: Ns descriptor related stuffs. Check before uploading. Change-Id: I45f81ad0f4a26badf46d4cf1392436aaf18fe036 Issue-ID: VFC-1037 Signed-off-by: laili --- catalog/packages/biz/ns_descriptor.py | 34 +++++++++++++++++++--------------- catalog/packages/biz/pnf_descriptor.py | 4 ++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py index 6eaa118e..8b394671 100644 --- a/catalog/packages/biz/ns_descriptor.py +++ b/catalog/packages/biz/ns_descriptor.py @@ -141,21 +141,6 @@ def delete_single(nsd_info_id): ns_pkgs.delete() -def upload(remote_file, nsd_info_id): - local_file_name = remote_file.name - local_file_dir = os.path.join(CATALOG_ROOT_PATH, nsd_info_id) - local_file_name = os.path.join(local_file_dir, local_file_name) - if not os.path.exists(local_file_dir): - fileutil.make_dirs(local_file_dir) - with open(local_file_name, 'wb') as local_file: - if remote_file.multiple_chunks(chunk_size=None): - for chunk in remote_file.chunks(): - local_file.write(chunk) - else: - data = remote_file.read() - local_file.write(data) - - def process(nsd_info_id, local_file_name): nsd_json = toscaparser.parse_nsd(local_file_name) nsd = json.JSONDecoder().decode(nsd_json) @@ -186,6 +171,25 @@ def process(nsd_info_id, local_file_name): ).save() +def upload(remote_file, nsd_info_id): + ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id) + if not ns_pkgs.exists(): + raise CatalogException('The NS descriptor (%s) does not exist.' % nsd_info_id) + + local_file_name = remote_file.name + local_file_dir = os.path.join(CATALOG_ROOT_PATH, nsd_info_id) + local_file_name = os.path.join(local_file_dir, local_file_name) + if not os.path.exists(local_file_dir): + fileutil.make_dirs(local_file_dir) + with open(local_file_name, 'wb') as local_file: + if remote_file.multiple_chunks(chunk_size=None): + for chunk in remote_file.chunks(): + local_file.write(chunk) + else: + data = remote_file.read() + local_file.write(data) + + def download(nsd_info_id): ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id) if not ns_pkgs.exists(): diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py index d52e82f2..43ed8410 100644 --- a/catalog/packages/biz/pnf_descriptor.py +++ b/catalog/packages/biz/pnf_descriptor.py @@ -96,6 +96,10 @@ def process(pnfd_info_id, local_file_name): # TODO: onboardingState changes def upload(files, pnfd_info_id): + ns_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id) + if not ns_pkgs.exists(): + raise CatalogException('The NS descriptor (%s) does not exist.' % pnfd_info_id) + remote_files = files for remote_file in remote_files: local_file_name = remote_file.name -- cgit 1.2.3-korg