from rift.mano.tosca_translator.common.exception import ToscaModImportError
from rift.mano.tosca_translator.conf.config import ConfigProvider as translatorConfig
from rift.mano.tosca_translator.rwmano.syntax.mano_resource import ManoResource
+from toscaparser.tosca_template import ToscaTemplate
class TranslateNodeTemplates(object):
self.log.debug(_("Metadata {0}").format(metadata))
self.metadata = metadata
+
def _recursive_handle_properties(self, resource):
'''Recursively handle the properties of the depends_on_nodes nodes.'''
# Use of hashtable (dict) here should be faster?
vnf_type_substitution_mapping = {}
vnf_type_to_capability_substitution_mapping = {}
tpl = self.tosca.tpl['topology_template']['node_templates']
+ associated_vnfd_flag = False
for node in self.nodetemplates:
all_node_templates.append(node)
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:
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]})
+ if template.substitution_mappings.requirements:
+ for req in template.substitution_mappings.requirements:
+ vnf_type_substitution_mapping[template.substitution_mappings.node_type].append(req)
+ if template.substitution_mappings.capabilities:
+ 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)
metadata=self.metadata)
# Currently tosca-parser does not add the artifacts
# to the node
+ if mano_node.type == 'vnfd':
+ associated_vnfd_flag = True
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
+ if not associated_vnfd_flag:
+ dummy_file = "{0}{1}".format(os.getenv('RIFT_INSTALL'), "/usr/rift/mano/common/dummy_vnf_node.yaml")
+ tosca_vnf = ToscaTemplate(dummy_file, {}, True)
+ vnf_type = self.tosca.topology_template.substitution_mappings.node_type
+ vnf_type_to_vdus_map[vnf_type] = []
+
+ for node in tosca_vnf.nodetemplates:
+ all_node_templates.append(node)
+ base_type = ManoResource.get_base_type(node.type_definition)
+ vnf_type_to_vnf_node[vnf_type] = node.name
+ mano_node = TranslateNodeTemplates. \
+ TOSCA_TO_MANO_TYPE[base_type.type](
+ self.log,
+ node,
+ metadata=self.metadata)
+ mano_node.vnf_type = vnf_type
+ self.mano_resources.append(mano_node)
+
+ for node in self.tosca.nodetemplates:
+ if 'VDU' in node.type:
+ vnf_type_to_vdus_map[vnf_type].append(node.name)
+
# The parser currently do not generate the objects for groups
for group in self.tosca.topology_template.groups:
group_type = group.type
vnf_name=vnf_node)
self.mano_policies.append(policy_node)
+ vnfd_resources = []
for node in self.mano_resources:
self.log.debug(_("Handle properties for {0} of type {1}").
format(node.name, node.type_))
format(node.name, node.type_))
node.update_image_checksum(self.tosca.path)
+ for node in list(self.mano_resources):
+ if node.type == "vnfd":
+ vnfd_resources.append(node)
+ self.mano_resources.remove(node)
+
+ vnfd_resources.sort(key=lambda x: x.member_vnf_id, reverse=True)
+ vnf_type_duplicate_map = {}
+ for node in reversed(vnfd_resources):
+ if node.vnf_type in vnf_type_duplicate_map:
+ for policy in self.mano_policies:
+ if hasattr(policy, '_vnf_name') and policy._vnf_name == node.name:
+ policy._vnf_name = vnf_type_duplicate_map[node.vnf_type]
+ continue
+ vnf_type_duplicate_map[node.vnf_type] = node.name
+
+ self.mano_resources.extend(vnfd_resources)
for node in self.mano_resources:
# Handle vnf and vdu dependencies first
if node.type == "vnfd":