update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / common / python / rift / mano / yang_translator / rwmano / translate_descriptors.py
index f0a6866..2023db5 100644 (file)
@@ -104,10 +104,11 @@ class TranslateDescriptors(object):
 
         return types_map
 
-    def __init__(self, log, yangs, tosca_template):
+    def __init__(self, log, yangs, tosca_template, vnfd_files=None):
         self.log = log
         self.yangs = yangs
         self.tosca_template = tosca_template
+        self.vnfd_files = vnfd_files
         # list of all TOSCA resources generated
         self.tosca_resources = []
         self.metadata = {}
@@ -143,27 +144,35 @@ class TranslateDescriptors(object):
 
     def _translate_yang(self):
         self.log.debug(_('Translating the descriptors.'))
-        for nsd in self.yangs[self.NSD]:
-            self.log.debug(_("Translate descriptor of type nsd: {}").
-                           format(nsd))
-            tosca_node = TranslateDescriptors. \
-                         YANG_TO_TOSCA_TYPE[self.NSD](
-                             self.log,
-                             nsd.pop(ToscaResource.NAME),
-                             self.NSD,
-                             nsd)
-            self.tosca_resources.append(tosca_node)
-
-        for vnfd in self.yangs[self.VNFD]:
-            self.log.debug(_("Translate descriptor of type vnfd: {}").
-                           format(vnfd))
-            tosca_node = TranslateDescriptors. \
-                         YANG_TO_TOSCA_TYPE[self.VNFD](
-                             self.log,
-                             vnfd.pop(ToscaResource.NAME),
-                             self.VNFD,
-                             vnfd)
-            self.tosca_resources.append(tosca_node)
+        if self.NSD in self.yangs:
+            for nsd in self.yangs[self.NSD]:
+                self.log.debug(_("Translate descriptor of type nsd: {}").
+                               format(nsd))
+                node_name = nsd.pop(ToscaResource.NAME).replace(' ','_')
+                node_name = node_name if node_name.endswith('nsd') else ''.join([node_name, '_nsd'])
+                tosca_node = TranslateDescriptors. \
+                             YANG_TO_TOSCA_TYPE[self.NSD](
+                                 self.log,
+                                 node_name,
+                                 self.NSD,
+                                 nsd,
+                                 self.vnfd_files)
+                self.tosca_resources.append(tosca_node)
+
+        vnfd_name_list = []
+        if self.VNFD in self.yangs:
+            for vnfd in self.yangs[self.VNFD]:
+                if vnfd['name'] not in vnfd_name_list:
+                    self.log.debug(_("Translate descriptor of type vnfd: {}").
+                                   format(vnfd))
+                    vnfd_name_list.append(vnfd['name'])
+                    tosca_node = TranslateDescriptors. \
+                                 YANG_TO_TOSCA_TYPE[self.VNFD](
+                                     self.log,
+                                     vnfd.pop(ToscaResource.NAME),
+                                     self.VNFD,
+                                     vnfd)
+                    self.tosca_resources.append(tosca_node)
 
         # First translate VNFDs
         for node in self.tosca_resources: