X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=common%2Fpython%2Frift%2Fmano%2Ftosca_translator%2Frwmano%2Ftranslate_node_templates.py;h=3f74336c10b0b0c863d6e22fb7676c2eef0cbb02;hb=refs%2Fchanges%2F30%2F1330%2F1;hp=dbfaa62a1878de567e54016e25b9d4173afad657;hpb=e178dc94f7ac4025f84685db11ea36e3a38a0b08;p=osm%2FSO.git diff --git a/common/python/rift/mano/tosca_translator/rwmano/translate_node_templates.py b/common/python/rift/mano/tosca_translator/rwmano/translate_node_templates.py index dbfaa62a..3f74336c 100644 --- a/common/python/rift/mano/tosca_translator/rwmano/translate_node_templates.py +++ b/common/python/rift/mano/tosca_translator/rwmano/translate_node_templates.py @@ -161,6 +161,8 @@ class TranslateNodeTemplates(object): for key in FIELDS_MAP: if key in tosca_meta.keys(): metadata[FIELDS_MAP[key]] = str(tosca_meta[key]) + if 'logo' in tosca_meta: + metadata['logo'] = os.path.basename(tosca_meta['logo']) self.log.debug(_("Metadata {0}").format(metadata)) self.metadata = metadata @@ -188,8 +190,48 @@ class TranslateNodeTemplates(object): self.log.debug(_('Translating the node templates.')) # Copy the TOSCA graph: nodetemplate + all_node_templates = [] + node_to_artifact_map = {} + vnf_type_to_vnf_node = {} + vnf_type_to_vdus_map = {} + vnf_type_substitution_mapping = {} + vnf_type_to_capability_substitution_mapping = {} tpl = self.tosca.tpl['topology_template']['node_templates'] + for node in self.nodetemplates: + all_node_templates.append(node) + if node.parent_type.type == 'tosca.nodes.nfv.riftio.VNF1': + vnf_type_to_vnf_node[node.type] = node.name + for node_key in tpl: + if 'artifacts' in tpl[node_key]: + node_to_artifact_map[node_key] = tpl[node_key]['artifacts'] + for template in self.tosca.nested_tosca_templates_with_topology: + tpl_node = template.tpl['node_templates'] + vnf_type = template.substitution_mappings.node_type + + vnf_type_to_vdus_map[vnf_type] = [] + vnf_type_substitution_mapping[vnf_type] = [] + vnf_type_to_capability_substitution_mapping[vnf_type] = [] + vnf_type_to_capability_substitution_mapping[vnf_type] = [] + policies = [] + for node in template.nodetemplates: + all_node_templates.append(node) + for node_key in tpl_node: + if 'artifacts' in tpl_node[node_key]: + node_to_artifact_map[node_key] = tpl_node[node_key]['artifacts'] + for node in template.nodetemplates: + if 'VDU' in node.type: + vnf_type_to_vdus_map[vnf_type].append(node.name) + for policy in template.policies: + policies.append(policy.name) + for req in template.substitution_mappings.requirements: + vnf_type_substitution_mapping[template.substitution_mappings.node_type].append(req) + for capability in template.substitution_mappings.capabilities: + sub_list = template.substitution_mappings.capabilities[capability] + if len(sub_list) > 0: + vnf_type_to_capability_substitution_mapping[vnf_type].append({capability: sub_list[0]}) + + for node in all_node_templates: base_type = ManoResource.get_base_type(node.type_definition) self.log.debug(_("Translate node %(name)s of type %(type)s with " "base %(base)s") % @@ -203,46 +245,48 @@ class TranslateNodeTemplates(object): metadata=self.metadata) # Currently tosca-parser does not add the artifacts # to the node - if mano_node.name in tpl: - tpl_node = tpl[mano_node.name] - self.log.debug("Check artifacts for {}".format(tpl_node)) - if 'artifacts' in tpl_node: - mano_node.artifacts = tpl_node['artifacts'] + if mano_node.name in node_to_artifact_map: + mano_node.artifacts = node_to_artifact_map[mano_node.name] self.mano_resources.append(mano_node) self.mano_lookup[node] = mano_node # The parser currently do not generate the objects for groups - if 'groups' in self.tosca.tpl['topology_template']: - tpl = self.tosca.tpl['topology_template']['groups'] - self.log.debug("Groups: {}".format(tpl)) - for group, details in tpl.items(): - self.log.debug(_("Translate group {}: {}"). - format(group, details)) - group_type = details['type'] - if group_type: - group_node = TranslateNodeTemplates. \ - TOSCA_TO_MANO_TYPE[group_type]( - self.log, - group, - details, - metadata=self.metadata) - self.mano_groups.append(group_node) + for group in self.tosca.topology_template.groups: + group_type = group.type + if group_type: + group_node = TranslateNodeTemplates. \ + TOSCA_TO_MANO_TYPE[group_type]( + self.log, + group, + metadata=self.metadata) + self.mano_groups.append(group_node) # The parser currently do not generate the objects for policies - if 'policies' in self.tosca.tpl['topology_template']: - tpl = self.tosca.tpl['topology_template']['policies'] - # for policy in self.policies: - for policy in tpl: - self.log.debug(_("Translate policy {}"). - format(policy)) - policy_type = self._get_policy_type(policy) - if policy_type: - policy_node = TranslateNodeTemplates. \ - TOSCA_TO_MANO_TYPE[policy_type]( - self.log, - policy, - metadata=self.metadata) - self.mano_policies.append(policy_node) + + for policy in self.tosca.topology_template.policies: + policy_type = policy.type + if policy_type: + policy_node = TranslateNodeTemplates. \ + TOSCA_TO_MANO_TYPE[policy_type]( + self.log, + policy, + metadata=self.metadata) + self.mano_policies.append(policy_node) + for template in self.tosca.nested_tosca_templates_with_topology: + vnf_type = template.substitution_mappings.node_type + if vnf_type in vnf_type_to_vnf_node: + vnf_node = vnf_type_to_vnf_node[vnf_type] + + for policy in template.policies: + policy_type = policy.type + if policy_type: + policy_node = TranslateNodeTemplates. \ + TOSCA_TO_MANO_TYPE[policy_type]( + self.log, + policy, + metadata=self.metadata, + vnf_name=vnf_node) + self.mano_policies.append(policy_node) for node in self.mano_resources: self.log.debug(_("Handle properties for {0} of type {1}"). @@ -272,7 +316,8 @@ class TranslateNodeTemplates(object): self.log.debug(_("Handle requirements for {0} of " "type {1}"). format(node.name, node.type_)) - node.handle_requirements(self.mano_resources) + node.handle_requirements(self.mano_resources, self.mano_policies, vnf_type_to_vdus_map) + except Exception as e: self.log.error(_("Exception for {0} in requirements {1}"). format(node.name, node.type_)) @@ -290,11 +335,17 @@ class TranslateNodeTemplates(object): format(node.name, node.type_)) self.log.exception(e) + for node in self.mano_resources: + if node.type == "vld": + node.handle_vld_properties(self.mano_resources, vnf_type_substitution_mapping) + elif node.type == 'forwarding_path': + node.handle_forwarding_path_dependencies(self.mano_resources, vnf_type_to_capability_substitution_mapping) + return self.mano_resources def translate_groups(self): for group in self.mano_groups: - group.handle_properties(self.mano_resources) + group.handle_properties(self.mano_resources, self.mano_groups) return self.mano_groups def translate_policies(self):