- 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
- cp_to_port_security_map = {}
-
- for cp in rift_vnfd.cps:
- # Find the VDU and and external interface for this connection point
- vdu, ext_if = find_vdu_and_ext_if_by_cp_ref(cp.name)
- connection = {
- "name": cp.name,
- "type": rift2openmano_if_type(ext_if),
- "VNFC": vdu.name,
- "local_iface_name": ext_if.name,
- "description": "%s iface on VDU %s" % (ext_if.name, vdu.name),
- }
-
- if cp.has_field('port_security_enabled'):
- cp_to_port_security_map[cp.name] = cp.port_security_enabled
- vnf["external-connections"].append(connection)
-
- # Add all internal networks
- for vld in rift_vnfd.internal_vlds:
- connection = {
- "name": vld.name,
- "description": vld.description,
- "type": "bridge",
- "elements": [],
- }
-
- # Add the specific VDU connection points
- 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,
- })
- if "internal-connections" not in vnf:
- vnf["internal-connections"] = []
-
- vnf["internal-connections"].append(connection)
-
- # Add VDU's
- vnf["VNFC"] = []
- for vdu in rift_vnfd.vdus:
- vnfc = {
- "name": vdu.name,
- "description": vdu.name,
- "bridge-ifaces": [],
- }
-
- if vdu.vm_flavor.has_field("storage_gb") and vdu.vm_flavor.storage_gb:
- vnfc["disk"] = vdu.vm_flavor.storage_gb
-
- if vdu.has_field("image"):
- 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("num_cores"):
- vnfc["numas"][0]["cores"] = numa_node.num_cores
-
- 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]
- )
-
- if numa_node.has_field("num_threads"):
- vnfc["numas"][0]["threads"] = numa_node.num_threads
- 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"] = {}
- if vdu.hypervisor_epa.has_field("type"):
- if vdu.hypervisor_epa.type_yang == "REQUIRE_KVM":
- vnfc["hypervisor"]["type"] = "QEMU-kvm"
-
- if vdu.hypervisor_epa.has_field("version"):
- vnfc["hypervisor"]["version"] = vdu.hypervisor_epa.version
-
- if vdu.has_field("host_epa"):
- vnfc["processor"] = {}
- if vdu.host_epa.has_field("om_cpu_model_string"):
- vnfc["processor"]["model"] = vdu.host_epa.om_cpu_model_string
- 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.feature)
-
- if vdu.has_field("volumes"):
- vnfc["devices"] = []
- # Sort volumes as device-list is implictly ordered by Openmano
- newvollist = sorted(vdu.volumes, key=lambda k: k.name)
- for iter_num, volume in enumerate(newvollist):
- if iter_num == 0:
- # Convert the first volume to vnfc.image
- if os.path.isabs(volume.image):
- vnfc["VNFC image"] = volume.image
- else:
- vnfc["image name"] = volume.image
- if volume.has_field("image_checksum"):
- vnfc["image checksum"] = volume.image_checksum
- else:
- # Add Openmano devices
- device = {}
- device["type"] = volume.device_type
- if volume.has_field("size"):
- device["size"] = volume.size
- if volume.has_field("image"):
- device["image name"] = volume.image
- if volume.has_field("image_checksum"):
- device["image checksum"] = volume.image_checksum
- vnfc["devices"].append(device)
-
- vnfc_boot_data_init = False
- if vdu.has_field("cloud_init") or vdu.has_field("cloud_init_file"):
- vnfc['boot-data'] = dict()
- vnfc_boot_data_init = True
- vnfc['boot-data']['user-data'] = cloud_init(rift_vnfd.id, vdu)
-
- if vdu.has_field("supplemental_boot_data"):
- if vdu.supplemental_boot_data.has_field('boot_data_drive'):
- if vdu.supplemental_boot_data.boot_data_drive is True:
- if vnfc_boot_data_init is False:
- vnfc['boot-data'] = dict()
- vnfc_boot_data_init = True
- vnfc['boot-data']['boot-data-drive'] = vdu.supplemental_boot_data.boot_data_drive
-
- if vdu.supplemental_boot_data.has_field('config_file'):
- om_cfgfile_list = list()
- for custom_config_file in vdu.supplemental_boot_data.config_file:
- cfg_source = config_file_init(rift_vnfd.id, vdu, custom_config_file.source)
- om_cfgfile_list.append({"dest":custom_config_file.dest, "content": cfg_source})
- vnfc['boot-data']['config-files'] = om_cfgfile_list
-
-
- vnf["VNFC"].append(vnfc)
-
- for int_if in list(vdu.internal_interface) + list(vdu.external_interface):
- intf = {
- "name": int_if.name,
- }
- if int_if.virtual_interface.has_field("vpci"):
- intf["vpci"] = int_if.virtual_interface.vpci
-
- 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":
- intf["bandwidth"] = "10 Gbps"
- intf["dedicated"] = "no"
- vnfc["numas"][0]["interfaces"].append(intf)
-
- elif int_if.virtual_interface.type_yang == "PCI_PASSTHROUGH":
- intf["bandwidth"] = "10 Gbps"
- intf["dedicated"] = "yes"
- if "interfaces" not in vnfc["numas"][0]:
- vnfc["numas"][0]["interfaces"] = []
- vnfc["numas"][0]["interfaces"].append(intf)
- else:
- raise ValueError("Interface type %s not supported" % int_if.virtual_interface)
-
- if int_if.virtual_interface.has_field("bandwidth"):
- if int_if.virtual_interface.bandwidth != 0:
- bps = int_if.virtual_interface.bandwidth
-
- # Calculate the bits per second conversion
- for x in [('M', 1000000), ('G', 1000000000)]:
- if bps/x[1] >= 1:
- intf["bandwidth"] = "{} {}bps".format(math.ceil(bps/x[1]), x[0])
-
- for bridge_iface in vnfc["bridge-ifaces"]:
- if bridge_iface['name'] in cp_to_port_security_map:
- bridge_iface['port-security'] = cp_to_port_security_map[bridge_iface['name']]
- # Sort bridge-ifaces-list TODO sort others
- newlist = sorted(vnfc["bridge-ifaces"], key=lambda k: k['name'])
- vnfc["bridge-ifaces"] = newlist
-
- return openmano_vnf