Bug 72 - Update rift2openmano to support e1000 virtual interfaces
[osm/SO.git] / models / openmano / python / rift / openmano / rift2openmano.py
index a98335b..e8ad3e5 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# 
+#
 #   Copyright 2016 RIFT.IO Inc
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,11 @@ import sys
 import tempfile
 import yaml
 
+import gi
+gi.require_version('RwYang', '1.0')
+gi.require_version('RwVnfdYang', '1.0')
+gi.require_version('RwNsdYang', '1.0')
+
 from gi.repository import (
     RwYang,
     RwVnfdYang,
@@ -235,7 +240,7 @@ def convert_vnfd_name(vnfd_name, member_idx):
     return vnfd_name + "__" + str(member_idx)
 
 
-def rift2openmano_nsd(rift_nsd, rift_vnfds):
+def rift2openmano_nsd(rift_nsd, rift_vnfds,openmano_vnfd_ids):
     for vnfd_id in rift_nsd.vnfd_ids:
         if vnfd_id not in rift_vnfds:
             raise VNFNotFoundError("VNF id %s not provided" % vnfd_id)
@@ -251,7 +256,14 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds):
         vnfd_id = vnfd.vnfd_id_ref
         rift_vnfd = rift_vnfds[vnfd_id]
         member_idx = vnfd.member_vnf_index
-        topology["nodes"][rift_vnfd.name + "__" + str(member_idx)] = {
+        openmano_vnfd_id = openmano_vnfd_ids.get(vnfd_id,None)
+        if openmano_vnfd_id:
+            topology["nodes"][rift_vnfd.name + "__" + str(member_idx)] = {
+                "type": "VNF",
+                "vnf_id": openmano_vnfd_id
+                }
+        else:
+            topology["nodes"][rift_vnfd.name + "__" + str(member_idx)] = {
                 "type": "VNF",
                 "VNF model": rift_vnfd.name
                 }
@@ -270,7 +282,8 @@ def rift2openmano_nsd(rift_nsd, rift_vnfds):
         topology["connections"][vld.name] = {}
         topology["connections"][vld.name]["nodes"] = []
 
-        if vld.vim_network_name:
+        #if vld.vim_network_name:
+        if True:
             if vld.name not in topology["nodes"]:
                 topology["nodes"][vld.name] = {
                         "type": "external_network",
@@ -348,11 +361,19 @@ def rift2openmano_vnfd(rift_vnfd):
     def rift2openmano_if_type(rift_type):
         if rift_type == "OM_MGMT":
             return "mgmt"
-        elif rift_type == "VIRTIO":
+        elif rift_type == "VIRTIO" or rift_type == "E1000":
             return "bridge"
         else:
             return "data"
 
+    def rift2openmano_vif(rift_type):
+        if rift_type == "VIRTIO":
+            return "virtio"
+        elif rift_type == "E1000":
+            return "e1000"
+        else:
+            raise ValueError("VDU Virtual Interface type {} not supported".format(rift_type))
+
     # Add all external connections
     for cp in rift_vnfd.cps:
         # Find the VDU and and external interface for this connection point
@@ -394,7 +415,6 @@ def rift2openmano_vnfd(rift_vnfd):
         vnfc = {
             "name": vdu.name,
             "description": vdu.name,
-            "VNFC image": vdu.image if os.path.isabs(vdu.image) else "/var/images/{}".format(vdu.image),
             "numas": [{
                 "memory": max(int(vdu.vm_flavor.memory_mb/1024), 1),
                 "interfaces":[],
@@ -402,6 +422,13 @@ def rift2openmano_vnfd(rift_vnfd):
             "bridge-ifaces": [],
             }
 
+        if os.path.isabs(vdu.image):
+            vnfc["VNFC image"] = vdu.image
+        else:
+            vnfc["image name"] = vdu.image
+            if vdu.has_field("image_checksum"):
+                vnfc["image checksum"] = vdu.image_checksum
+
         numa_node_policy = vdu.guest_epa.numa_node_policy
         if numa_node_policy.has_field("node"):
             numa_node = numa_node_policy.node[0]
@@ -451,7 +478,11 @@ def rift2openmano_vnfd(rift_vnfd):
             if int_if.virtual_interface.has_field("vpci"):
                 intf["vpci"] = int_if.virtual_interface.vpci
 
-            if int_if.virtual_interface.type_yang in ["VIRTIO", "OM_MGMT"]:
+            if int_if.virtual_interface.type_yang in ["VIRTIO", "E1000"]:
+                intf["model"] = rift2openmano_vif(int_if.virtual_interface.type_yang)
+                vnfc["bridge-ifaces"].append(intf)
+
+            elif int_if.virtual_interface.type_yang in ["OM_MGMT"]:
                 vnfc["bridge-ifaces"].append(intf)
 
             elif int_if.virtual_interface.type_yang == "SR-IOV":