X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=common%2Fpython%2Frift%2Fmano%2Fyang_translator%2Frwmano%2Fsyntax%2Ftosca_template.py;h=95f2cb2698af59c4906245116718868bad249249;hb=93f10aabdba5a1c745d002654c0bb6345a682a47;hp=7c31df5973d0c42a7ec56e0de5733e35b858f3d1;hpb=6f07e6f33f751ab4ffe624f6037f887b243bece2;p=osm%2FSO.git diff --git a/common/python/rift/mano/yang_translator/rwmano/syntax/tosca_template.py b/common/python/rift/mano/yang_translator/rwmano/syntax/tosca_template.py index 7c31df59..95f2cb26 100644 --- a/common/python/rift/mano/yang_translator/rwmano/syntax/tosca_template.py +++ b/common/python/rift/mano/yang_translator/rwmano/syntax/tosca_template.py @@ -36,6 +36,15 @@ class ToscaTemplate(object): self.log.debug(_('Converting translated output to tosca template.')) templates = {} + vnfd_templates = {} + + for resource in self.resources: + if resource.type == 'vnfd': + tmpl = resource.generate_tosca() + tmpl = resource.generate_tosca_template(tmpl) + self.log.debug(_("TOSCA template generated for {0}:\n{1}"). + format(resource.name, tmpl)) + vnfd_templates[resource.name] = tmpl for resource in self.resources: # Each NSD should generate separate templates @@ -49,6 +58,14 @@ class ToscaTemplate(object): if len(files): templates[resource.name][self.FILES] = files + for resource in self.resources: + if resource.type == 'vnfd': + tmpl = vnfd_templates[resource.name] + templates[resource.name] = {self.TOSCA: self.output_to_yaml(tmpl)} + files = resource.get_supporting_files() + if len(files): + templates[resource.name][self.FILES] = files + return templates def represent_ordereddict(self, dumper, data): @@ -66,6 +83,7 @@ class ToscaTemplate(object): ToscaResource.REQUIREMENTS,ToscaResource.ARTIFACTS, ToscaResource.INTERFACES] new_node = OrderedDict() + self.log.debug("Node to oder: {}".format(node)) for ent in order: if ent in node: new_node.update({ent: node.pop(ent)}) @@ -87,10 +105,18 @@ class ToscaTemplate(object): else: return nodes + def ordered_nodes_sub_mapping(self, nodes): + new_nodes = OrderedDict() + if isinstance(nodes, dict): + for name, node in nodes.items(): + new_nodes.update({name: node}) + return new_nodes + else: + return nodes + def output_to_yaml(self, tosca): self.log.debug(_('Converting translated output to yaml format.')) dict_output = OrderedDict() - dict_output.update({'tosca_definitions_version': tosca['tosca_definitions_version']}) # Description @@ -106,6 +132,9 @@ class ToscaTemplate(object): if ToscaResource.METADATA in tosca: dict_output.update({ToscaResource.METADATA: tosca[ToscaResource.METADATA]}) + if ToscaResource.IMPORT in tosca: + dict_output.update({ToscaResource.IMPORT: + tosca[ToscaResource.IMPORT]}) # Add all types types_list = [ToscaResource.DATA_TYPES, ToscaResource.CAPABILITY_TYPES, @@ -122,9 +151,14 @@ class ToscaTemplate(object): if ToscaResource.TOPOLOGY_TMPL in tosca: tmpl = OrderedDict() for typ in tosca[ToscaResource.TOPOLOGY_TMPL]: - tmpl.update({typ: - self.ordered_nodes( - tosca[ToscaResource.TOPOLOGY_TMPL][typ])}) + if typ != ToscaResource.SUBSTITUTION_MAPPING: + tmpl.update({typ: + self.ordered_nodes( + tosca[ToscaResource.TOPOLOGY_TMPL][typ])}) + else: + tmpl.update({typ: + self.ordered_nodes_sub_mapping( + tosca[ToscaResource.TOPOLOGY_TMPL][typ])}) dict_output.update({ToscaResource.TOPOLOGY_TMPL: tmpl}) yaml.add_representer(OrderedDict, self.represent_ordereddict)