diff options
author | Fu Jinhua <fu.jinhua@zte.com.cn> | 2018-08-27 00:54:42 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-27 00:54:42 +0000 |
commit | 8887fb6d7ed8e751bc4749a21641255c62825d7e (patch) | |
tree | 5416ddcb4d585c11fba452918e635de99c10edc7 | |
parent | baee0608458dd63bc5abb7cda057eb1f7ae920e7 (diff) | |
parent | 1378fb5df25dc382a71c340805c2149d634afed0 (diff) |
Merge "Ns descriptor related stuffs."
-rw-r--r-- | catalog/packages/biz/ns_descriptor.py | 34 | ||||
-rw-r--r-- | 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 |