X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fcommon%2Fpackage_tool.py;h=b3f5ecf00e6a14307839dc132252c0deb2c4a8da;hb=da42e021c5f07287c0814fdfb3916a42e63fe818;hp=19b1386511a317dfb1b6819d56cd82fd99d15bb5;hpb=89ae6b9c84e8de367519b955c7c9b694c482a641;p=osm%2Fosmclient.git diff --git a/osmclient/common/package_tool.py b/osmclient/common/package_tool.py index 19b1386..b3f5ecf 100644 --- a/osmclient/common/package_tool.py +++ b/osmclient/common/package_tool.py @@ -438,24 +438,46 @@ class PackageTool(object): def charms_search(self, descriptor_file, desc_type): self._logger.debug("") - dict = {} - list = [] with open("{}".format(descriptor_file)) as yaml_desc: - dict = yaml.safe_load(yaml_desc) - for k1, v1 in dict.items(): - for k2, v2 in v1.items(): - for entry in v2: - if '{}-configuration'.format(desc_type) in entry: - name = entry['{}-configuration'.format(desc_type)] - for k3, v3 in name.items(): - if 'charm' in v3: - list.append((v3['charm'])) - if 'vdu' in entry: - name = entry['vdu'] - for vdu in name: - if 'vdu-configuration' in vdu: - for k4, v4 in vdu['vdu-configuration'].items(): - if 'charm' in v4: - list.append((v4['charm'])) - return list - + descriptor_dict = yaml.safe_load(yaml_desc) + if "catalog" in descriptor_dict: # Match OSM-IM vnfd-catalog and nsd-catalog + charms_list = self._charms_search_on_osm_im_dict(descriptor_dict, desc_type) + else: + charms_list = self._charms_search_on_sol006_dict(descriptor_dict, desc_type) + + return charms_list + + def _charms_search_on_osm_im_dict(self, osm_im_dict, desc_type): + charms_list = [] + for k1, v1 in osm_im_dict.items(): + for k2, v2 in v1.items(): + for entry in v2: + if '{}-configuration'.format(desc_type) in entry: + vnf_config = entry['{}-configuration'.format(desc_type)] + for k3, v3 in vnf_config.items(): + if 'charm' in v3: + charms_list.append((v3['charm'])) + if 'vdu' in entry: + vdus = entry['vdu'] + for vdu in vdus: + if 'vdu-configuration' in vdu: + for k4, v4 in vdu['vdu-configuration'].items(): + if 'charm' in v4: + charms_list.append((v4['charm'])) + return charms_list + + def _charms_search_on_sol006_dict(self, sol006_dict, desc_type): + charms_list = [] + for k1, v1 in sol006_dict.items(): + for k2, v2 in v1.items(): + if '{}-configuration'.format(desc_type) in k2: + for vnf_config in v2: + for k3, v3 in vnf_config.items(): + if 'charm' in v3: + charms_list.append((v3['charm'])) + if 'vdu-configuration' in k2: + for vdu_config in v2: + for k3, v3 in vdu_config.items(): + if 'charm' in v3: + charms_list.append((v3['charm'])) + return charms_list \ No newline at end of file