* YANG to TOSCA translator
[osm/SO.git] / common / python / rift / mano / yang_translator / rwmano / translate_descriptors.py
index f0a6866..707ab7f 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,30 @@ 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))
+                tosca_node = TranslateDescriptors. \
+                             YANG_TO_TOSCA_TYPE[self.NSD](
+                                 self.log,
+                                 nsd.pop(ToscaResource.NAME),
+                                 self.NSD,
+                                 nsd,
+                                 self.vnfd_files)
+                self.tosca_resources.append(tosca_node)
+
+        if self.VNFD in self.yangs:
+            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)
 
         # First translate VNFDs
         for node in self.tosca_resources: