Bug 106 - Cannot instantiate Network services with VNFs having SR-IOV interfaces
[osm/SO.git] / models / openmano / python / rift / openmano / rift2openmano.py
index e8ad3e5..e216e9a 100755 (executable)
@@ -398,8 +398,8 @@ def rift2openmano_vnfd(rift_vnfd):
             }
 
         # Add the specific VDU connection points
-        for int_cp_ref in vld.internal_connection_point_ref:
-            vdu, int_if = find_vdu_and_int_if_by_cp_ref(int_cp_ref)
+        for int_cp in vld.internal_connection_point:
+            vdu, int_if = find_vdu_and_int_if_by_cp_ref(int_cp.id_ref)
             connection["elements"].append({
                 "VNFC": vdu.name,
                 "local_iface_name": int_if.name,
@@ -415,37 +415,52 @@ def rift2openmano_vnfd(rift_vnfd):
         vnfc = {
             "name": vdu.name,
             "description": vdu.name,
-            "numas": [{
-                "memory": max(int(vdu.vm_flavor.memory_mb/1024), 1),
-                "interfaces":[],
-                }],
             "bridge-ifaces": [],
             }
 
+        if vdu.vm_flavor.has_field("storage_gb") and vdu.vm_flavor.storage_gb:
+            vnfc["disk"] = vdu.vm_flavor.storage_gb
+
         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
+        dedicated_int = False
+        for intf in list(vdu.internal_interface) + list(vdu.external_interface):
+            if intf.virtual_interface.type_yang in ["SR_IOV", "PCI_PASSTHROUGH"]:
+                dedicated_int = True
+        if vdu.guest_epa.has_field("numa_node_policy") or dedicated_int:
+            vnfc["numas"] = [{
+                           "memory": max(int(vdu.vm_flavor.memory_mb/1024), 1),
+                           "interfaces":[],
+                           }]
+            numa_node_policy = vdu.guest_epa.numa_node_policy
+            if numa_node_policy.has_field("node"):
+                numa_node = numa_node_policy.node[0]
+
+                if numa_node.has_field("paired_threads"):
+                    if numa_node.paired_threads.has_field("num_paired_threads"):
+                        vnfc["numas"][0]["paired-threads"] = numa_node.paired_threads.num_paired_threads
+                    if len(numa_node.paired_threads.paired_thread_ids) > 0:
+                        vnfc["numas"][0]["paired-threads-id"] = []
+                        for pair in numa_node.paired_threads.paired_thread_ids:
+                             vnfc["numas"][0]["paired-threads-id"].append(
+                                     [pair.thread_a, pair.thread_b]
+                                     )
 
-        numa_node_policy = vdu.guest_epa.numa_node_policy
-        if numa_node_policy.has_field("node"):
-            numa_node = numa_node_policy.node[0]
-
-            if numa_node.has_field("paired_threads"):
-                if numa_node.paired_threads.has_field("num_paired_threads"):
-                    vnfc["numas"][0]["paired-threads"] = numa_node.paired_threads.num_paired_threads
-                if len(numa_node.paired_threads.paired_thread_ids) > 0:
-                    vnfc["numas"][0]["paired-threads-id"] = []
-                    for pair in numa_node.paired_threads.paired_thread_ids:
-                         vnfc["numas"][0]["paired-threads-id"].append(
-                                 [pair.thread_a, pair.thread_b]
-                                 )
+            else:
+                if vdu.vm_flavor.has_field("vcpu_count"):
+                    vnfc["numas"][0]["cores"] = max(vdu.vm_flavor.vcpu_count, 1)
 
         else:
-            if vdu.vm_flavor.has_field("vcpu_count"):
-                vnfc["numas"][0]["cores"] = max(vdu.vm_flavor.vcpu_count, 1)
+            if vdu.vm_flavor.has_field("vcpu_count") and vdu.vm_flavor.vcpu_count:
+                vnfc["vcpus"] = vdu.vm_flavor.vcpu_count
+
+            if vdu.vm_flavor.has_field("memory_mb") and vdu.vm_flavor.memory_mb:
+                vnfc["ram"] = vdu.vm_flavor.memory_mb
+
 
         if vdu.has_field("hypervisor_epa"):
             vnfc["hypervisor"] = {}
@@ -463,12 +478,9 @@ def rift2openmano_vnfd(rift_vnfd):
             if vdu.host_epa.has_field("om_cpu_feature"):
                 vnfc["processor"]["features"] = []
                 for feature in vdu.host_epa.om_cpu_feature:
-                    vnfc["processor"]["features"].append(feature)
+                    vnfc["processor"]["features"].append(feature.feature)
 
 
-        if vdu.vm_flavor.has_field("storage_gb"):
-            vnfc["disk"] = vdu.vm_flavor.storage_gb
-
         vnf["VNFC"].append(vnfc)
 
         for int_if in list(vdu.internal_interface) + list(vdu.external_interface):
@@ -485,9 +497,9 @@ def rift2openmano_vnfd(rift_vnfd):
             elif int_if.virtual_interface.type_yang in ["OM_MGMT"]:
                 vnfc["bridge-ifaces"].append(intf)
 
-            elif int_if.virtual_interface.type_yang == "SR-IOV":
+            elif int_if.virtual_interface.type_yang == "SR_IOV":
                 intf["bandwidth"] = "10 Gbps"
-                intf["dedicated"] = "yes:sriov"
+                intf["dedicated"] = "no"
                 vnfc["numas"][0]["interfaces"].append(intf)
 
             elif int_if.virtual_interface.type_yang == "PCI_PASSTHROUGH":