From da42e021c5f07287c0814fdfb3916a42e63fe818 Mon Sep 17 00:00:00 2001 From: garciaale Date: Thu, 19 Nov 2020 12:04:56 -0300 Subject: [PATCH] Changes package_tool to also support SOL006 descriptors Change-Id: Id93031ddd53ce02297c740b61d44951a7678952d Signed-off-by: garciaale --- osmclient/common/package_tool.py | 62 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 20 deletions(-) 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 -- 2.25.1