- else:
- 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.guest_params.device_type
- device["image"] = volume.image
- vnfc["devices"].append(device)
-
- vnfc_cloud_config_init = False
- if vdu.has_field("cloud_init") or vdu.has_field("cloud_init_file"):
- vnfc['cloud-config'] = dict()
- vnfc_cloud_config_init = True
- vnfc['cloud-config']['user-data'] = cloud_init(rift_vnfd.id, vdu)
-
- if vdu.has_field("custom_boot_data"):
- if vdu.custom_boot_data.has_field('custom_drive'):
- if vdu.custom_boot_data.custom_drive is True:
- if vnfc_cloud_config_init is False:
- vnfc['cloud-config'] = dict()
- vnfc_cloud_config_init = True
- vnfc['cloud-config']['config-drive'] = vdu.custom_boot_data.custom_drive
- if vdu.custom_boot_data.has_field('custom_meta_data'):
- if vnfc_cloud_config_init is False:
- vnfc['cloud-config'] = dict()
- vnfc_cloud_config_init = True
- vnfc['cloud-config']['meta-data'] = list()
- for metaitem in vdu.custom_boot_data.custom_meta_data:
- openmano_metaitem = dict()
- openmano_metaitem['key'] = metaitem.name
- openmano_metaitem['value'] = metaitem.value
- vnfc['cloud-config']['meta-data'].append(openmano_metaitem)
-
- 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])
-
-
- return openmano_vnf