diff options
author | hongyuzhao <zhao.hongyu@zte.com.cn> | 2020-02-18 16:11:50 +0800 |
---|---|---|
committer | hongyuzhao <zhao.hongyu@zte.com.cn> | 2020-02-18 16:43:58 +0800 |
commit | 6215857a5a88907c2ba522b862992815e47f4960 (patch) | |
tree | da37d53a3ea6215600ac496a8f13d0d166d4c5f4 /catalog/packages/biz/vnf_package.py | |
parent | 14eb438e920a9905e7254bf3aeb6bc4cc423e6b3 (diff) |
additionalArtifacts is not implemented in the response of the Query VNF API
Change-Id: I62e3338b038eec1a318841521c3f2dcd1c05ee5e
Issue-ID: MODELING-312
Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
Diffstat (limited to 'catalog/packages/biz/vnf_package.py')
-rw-r--r-- | catalog/packages/biz/vnf_package.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py index daf2fb2..6dec204 100644 --- a/catalog/packages/biz/vnf_package.py +++ b/catalog/packages/biz/vnf_package.py @@ -229,6 +229,56 @@ class VnfPkgUploadThread(threading.Thread): logger.info('VNF packge(%s) has been uploaded.' % self.vnf_pkg_id) +def get_mfile_data(path): + logger.debug('get_mfile_data path %s' % path) + files = fileutil.filter_files(path, '.mf') + if files: + src_file = os.path.join(path, files[0]) + src_dict_list = [] + with open(src_file, 'r') as f: + data = f.readlines() + for line in data: + if line.strip() == "": + continue + src_dict = {} + k, v = line.split(':', maxsplit=1) + if k.strip() in ["Source", "Algorithm", "Hash"]: + if k.strip() == "Source" and src_dict: + src_dict_list.extend(src_dict) + src_dict = {} + src_dict[k.strip()] = v.strip() + print("src_dict:%s" % src_dict) + if src_dict: + src_dict_list.append(src_dict) + + logger.debug('get_mfile_data: %s' % src_dict_list) + return src_dict_list + + +def fill_artifacts_data(vnf_pkg_id): + vnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, vnf_pkg_id) + if os.path.exists(vnf_pkg_path) is False: + return None + files = fileutil.filter_files(vnf_pkg_path, '.csar') + for filename in files: + logger.info('fill_artifacts_data filename (%s)...' % filename) + dst_file_path = os.path.join(vnf_pkg_path, "tmp") + src_file = os.path.join(vnf_pkg_path, filename) + dst_file = os.path.join(dst_file_path, filename) + fileutil.recreate_dir(dst_file_path) + fileutil.copy(src_file, vnf_pkg_path, dst_file) + artifact_vnf_file = fileutil.unzip_file(dst_file, dst_file_path, "") + artifacts = get_mfile_data(artifact_vnf_file) + if artifacts: + return [{ + "artifactPath": artifact.get("Source", ""), + "checksum": { + "algorithm": artifact.get("Hash", "Null"), + "hash": artifact.get("Algorithm", "Null") + } + } for artifact in artifacts] + + def fill_response_data(nf_pkg): pkg_info = {} pkg_info["id"] = nf_pkg.vnfPackageId @@ -239,7 +289,7 @@ def fill_response_data(nf_pkg): if nf_pkg.checksum: pkg_info["checksum"] = json.JSONDecoder().decode(nf_pkg.checksum) pkg_info["softwareImages"] = None # TODO - pkg_info["additionalArtifacts"] = None # TODO + pkg_info["additionalArtifacts"] = fill_artifacts_data(nf_pkg.vnfPackageId) pkg_info["onboardingState"] = nf_pkg.onboardingState pkg_info["operationalState"] = nf_pkg.operationalState pkg_info["usageState"] = nf_pkg.usageState |