X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fosmrepo.py;h=aa2a5f0ee492829804c6733fe729fcdcb125ddd7;hb=0438395c63edebf5f34688906decc06935f037e6;hp=efd2207a9392deb06fa9734a80f7a608c32c3534;hpb=3c1603818230f52cf5102fdfbdd8fd8907062e8d;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/osmrepo.py b/osmclient/sol005/osmrepo.py index efd2207..aa2a5f0 100644 --- a/osmclient/sol005/osmrepo.py +++ b/osmclient/sol005/osmrepo.py @@ -31,7 +31,7 @@ from osmclient.common.package_tool import PackageTool from osmclient.sol005.repo import Repo from packaging import version as versioning import requests -import ruamel.yaml +import yaml class OSMRepo(Repo): @@ -64,7 +64,7 @@ class OSMRepo(Repo): r = requests.get('{}/index.yaml'.format(repository.get('url'))) if r.status_code == 200: - repo_list = ruamel.yaml.safe_load(r.text) + repo_list = yaml.safe_load(r.text) vnf_packages = repo_list.get('{}_packages'.format(pkgtype)) for repo in vnf_packages: versions = vnf_packages.get(repo) @@ -137,7 +137,7 @@ class OSMRepo(Repo): raise ClientException('Package not found') folder, descriptor = self.zip_extraction(pkg_name) with open(descriptor) as pkg: - pkg_descriptor = ruamel.yaml.safe_load(pkg) + pkg_descriptor = yaml.safe_load(pkg) rmtree(folder, ignore_errors=False) if ((pkgtype == 'vnf' and (pkg_descriptor.get('vnfd') or pkg_descriptor.get('vnfd:vnfd_catalog'))) or (pkgtype == 'ns' and (pkg_descriptor.get('nsd') or pkg_descriptor.get('nsd:nsd_catalog')))): @@ -187,10 +187,10 @@ class OSMRepo(Repo): hash_md5.update(chunk) return hash_md5.hexdigest() - def fields_building(self, descriptor_json, file, package_type): + def fields_building(self, descriptor_dict, file, package_type): """ From an artifact descriptor, obtain the fields required for indexing - :param descriptor_json: artifact description + :param descriptor_dict: artifact description :param file: artifact package :param package_type: type of artifact (vnf or ns) :return: fields @@ -200,20 +200,20 @@ class OSMRepo(Repo): base_path = '/{}/'.format(package_type) aux_dict = {} if package_type == "vnf": - if descriptor_json.get('vnfd-catalog', False): - aux_dict = descriptor_json.get('vnfd-catalog', {}).get('vnfd', [{}])[0] + if descriptor_dict.get('vnfd-catalog', False): + aux_dict = descriptor_dict.get('vnfd-catalog', {}).get('vnfd', [{}])[0] else: - aux_dict = descriptor_json.get('vnfd:vnfd-catalog', {}).get('vnfd', [{}])[0] + aux_dict = descriptor_dict.get('vnfd:vnfd-catalog', {}).get('vnfd', [{}])[0] images = [] for vdu in aux_dict.get('vdu', ()): images.append(vdu.get('image')) fields['images'] = images if package_type == "ns": - if descriptor_json.get('nsd-catalog', False): - aux_dict = descriptor_json.get('nsd-catalog', {}).get('nsd', [{}])[0] + if descriptor_dict.get('nsd-catalog', False): + aux_dict = descriptor_dict.get('nsd-catalog', {}).get('nsd', [{}])[0] else: - aux_dict = descriptor_json.get('nsd:nsd-catalog', {}).get('nsd', [{}])[0] + aux_dict = descriptor_dict.get('nsd:nsd-catalog', {}).get('nsd', [{}])[0] vnfs = [] @@ -269,16 +269,16 @@ class OSMRepo(Repo): with open(descriptor_file, 'r') as f: descriptor_data = f.read() validation = validation_im() - desc_type, descriptor_data = validation.yaml_validation(descriptor_data) - validation_im.pyangbind_validation(self, desc_type, descriptor_data) - if 'vnf' in list(descriptor_data.keys())[0]: + desc_type, descriptor_dict = validation.yaml_validation(descriptor_data) + validation_im.pyangbind_validation(self, desc_type, descriptor_dict) + if 'vnf' in list(descriptor_dict.keys())[0]: package_type = 'vnf' else: # raise ClientException("Not VNF package") package_type = 'ns' - self._logger.debug("Descriptor: {}".format(descriptor_data)) - fields = self.fields_building(descriptor_data, path, package_type) + self._logger.debug("Descriptor: {}".format(descriptor_dict)) + fields = self.fields_building(descriptor_dict, path, package_type) self._logger.debug("Descriptor sucessfully validated") return {"detail": "{}D successfully validated".format(package_type.upper()), "code": "OK"}, True, fields, package_type @@ -337,28 +337,31 @@ class OSMRepo(Repo): mkdir(final_path) copyfile(path, final_path + '/' + fields.get('id') + "-" + fields.get('version') + '.tar.gz') - ruamel.yaml.dump(fields, open(final_path + '/' + 'metadata.yaml', 'w'), - Dumper=ruamel.yaml.RoundTripDumper) - index = ruamel.yaml.load(open(destination + '/index.yaml'), Loader=ruamel.yaml.Loader) + yaml.safe_dump(fields, open(final_path + '/' + 'metadata.yaml', 'w'), + default_flow_style=False, width=80, indent=4) + index = yaml.safe_load(open(destination + '/index.yaml')) index['{}_packages'.format(package_type)][fields.get('id')][fields.get('version')] = data_ind if versioning.parse(index['{}_packages'.format(package_type)][fields.get('id')][ 'latest']) < versioning.parse(fields.get('version')): index['{}_packages'.format(package_type)][fields.get('id')]['latest'] = fields.get( 'version') - ruamel.yaml.dump(index, open(destination + '/index.yaml', 'w'), Dumper=ruamel.yaml.RoundTripDumper) + yaml.safe_dump(index, open(destination + '/index.yaml', 'w'), + default_flow_style=False, width=80, indent=4) self._logger.info('{} {} added in the repository'.format(package_type.upper(), str(path))) else: mkdir(destination + '/{}/'.format(package_type) + fields.get('id')) mkdir(final_path) copyfile(path, final_path + '/' + fields.get('id') + "-" + fields.get('version') + '.tar.gz') - ruamel.yaml.dump(fields, open(join(final_path, 'metadata.yaml'), 'w'), Dumper=ruamel.yaml.RoundTripDumper) - index = ruamel.yaml.load(open(destination + '/index.yaml'), Loader=ruamel.yaml.Loader) + yaml.safe_dump(fields, open(join(final_path, 'metadata.yaml'), 'w'), + default_flow_style=False, width=80, indent=4) + index = yaml.safe_load(open(destination + '/index.yaml')) index['{}_packages'.format(package_type)][fields.get('id')] = {fields.get('version'): data_ind} index['{}_packages'.format(package_type)][fields.get('id')]['latest'] = fields.get('version') - ruamel.yaml.dump(index, open(join(destination, 'index.yaml'), 'w'), Dumper=ruamel.yaml.RoundTripDumper) + yaml.safe_dump(index, open(join(destination, 'index.yaml'), 'w'), + default_flow_style=False, width=80, indent=4) self._logger.info('{} {} added in the repository'.format(package_type.upper(), str(path))) def current_datatime(self): @@ -384,5 +387,5 @@ class OSMRepo(Repo): index_data = {'apiVersion': 'v1', 'generated': self.current_datatime(), 'vnf_packages': {}, 'ns_packages': {}} with open(join(destination, 'index.yaml'), 'w') as outfile: - ruamel.yaml.dump(index_data, outfile, default_flow_style=False) + yaml.safe_dump(index_data, outfile, default_flow_style=False, width=80, indent=4)