package documentation

KVM hypervisor

Module monitor Qemu monitor control classes
Module netdev KVM hypervisor tap device helpers
Module validation KVM hypervisor parameter/syntax validation helpers

From __init__.py:

Class HeadRequest Undocumented
Class KVMHypervisor KVM hypervisor interface
Variable psutil Undocumented
Variable psutil_err Undocumented
Function _AnalyzeSerializedRuntime Return runtime entries for a serialized runtime file
Function _CheckUrl Check if a given URL exists on the server
Function _GenerateDeviceHVInfo Helper function to generate hvinfo of a device (disk, NIC)
Function _GenerateDeviceHVInfoStr Construct the -device option string for hvinfo dict
Function _GenerateDeviceKVMId Helper function to generate a unique device name used by KVM
Function _GetDriveURI Helper function to get the drive uri to be used in --drive kvm option
Function _GetExistingDeviceInfo Helper function to get an existing device inside the runtime file
Function _UpgradeSerializedRuntime Upgrade runtime data
Function _with_qmp Wrapper used on hotplug related methods
Constant _DEVICE_BUS Undocumented
Constant _DEVICE_DRIVER Undocumented
Constant _DEVICE_RUNTIME_INDEX Undocumented
Constant _DEVICE_TYPE Undocumented
Constant _FIND_RUNTIME_ENTRY Undocumented
Constant _HOTPLUGGABLE_DEVICE_TYPES Undocumented
Constant _KVM_DISKS_RUNTIME_INDEX Undocumented
Constant _KVM_NETWORK_SCRIPT Undocumented
Constant _KVM_NICS_RUNTIME_INDEX Undocumented
Constant _KVM_START_PAUSED_FLAG Undocumented
Constant _MIGRATION_CAPS_DELIM Undocumented
Constant _PCI_BUS Undocumented
Constant _POSTCOPY_SYNC_COUNT_THRESHOLD Undocumented
Constant _RUNTIME_DEVICE Undocumented
Constant _RUNTIME_ENTRY Undocumented
Constant _SCSI_BUS Undocumented
psutil_err =

Undocumented

psutil =

Undocumented

_KVM_NETWORK_SCRIPT =

Undocumented

Value
pathutils.CONF_DIR+'/kvm-vif-bridge'
_KVM_START_PAUSED_FLAG: str =

Undocumented

Value
'-S'
_KVM_NICS_RUNTIME_INDEX: int =

Undocumented

Value
1
_KVM_DISKS_RUNTIME_INDEX: int =

Undocumented

Value
3
_FIND_RUNTIME_ENTRY =

Undocumented

Value
{constants.HOTPLUG_TARGET_NIC: (lambda nic, kvm_nics: [n for n in kvm_nics if n.
uuid == nic.uuid]),
 constants.HOTPLUG_TARGET_DISK: (lambda disk, kvm_disks: [(d, l, u) for d, l, u 
in kvm_disks if d.uuid ==
    disk.uuid])}
_RUNTIME_DEVICE =

Undocumented

Value
{constants.HOTPLUG_TARGET_NIC: (lambda d: d),
 constants.HOTPLUG_TARGET_DISK: (lambda d_e_x: d_e_x[0])}
_RUNTIME_ENTRY =

Undocumented

Value
{constants.HOTPLUG_TARGET_NIC: (lambda d, e: d),
 constants.HOTPLUG_TARGET_DISK: (lambda d, e: (d, e[0], e[1]))}
_DEVICE_TYPE =

Undocumented

Value
{constants.HOTPLUG_TARGET_NIC: (lambda hvp: hvp[constants.HV_NIC_TYPE]),
 constants.HOTPLUG_TARGET_DISK: (lambda hvp: hvp[constants.HV_DISK_TYPE])}
_DEVICE_DRIVER =

Undocumented

Value
{constants.HOTPLUG_TARGET_NIC: (lambda ht: 'virtio-net-pci' if ht == constants.H
T_NIC_PARAVIRTUAL else ht),
 constants.HOTPLUG_TARGET_DISK: (lambda ht: 'virtio-blk-pci' if ht == constants.
HT_DISK_PARAVIRTUAL else ht)}
_DEVICE_BUS =

Undocumented

Value
{constants.HOTPLUG_TARGET_NIC: (lambda _: _PCI_BUS),
 constants.HOTPLUG_TARGET_DISK: (lambda ht: _SCSI_BUS if ht in constants.HT_SCSI
_DEVICE_TYPES else _PCI_BUS)}
_PCI_BUS: str =

Undocumented

Value
'pci.0'
_SCSI_BUS: str =

Undocumented

Value
'scsi.0'
_MIGRATION_CAPS_DELIM: str =

Undocumented

Value
':'
_POSTCOPY_SYNC_COUNT_THRESHOLD: int =

Undocumented

Value
2
def _with_qmp(fn):

Wrapper used on hotplug related methods

def _GetDriveURI(disk, link, uri):

Helper function to get the drive uri to be used in --drive kvm option

Invoked during startup and disk hot-add. In latter case and if no userspace access mode is used it will be overriden with /dev/fdset/<fdset-id> (see HotAddDisk() and AddFd() of QmpConnection).

Parameters
disk:objects.DiskA disk configuration object
link:stringThe device link as returned by _SymlinkBlockDev()
uri:stringThe drive uri as returned by _CalculateDeviceURI()
Returns
The drive uri to use in kvm option
def _GenerateDeviceKVMId(dev_type, dev):

Helper function to generate a unique device name used by KVM

QEMU monitor commands use names to identify devices. Since the UUID is too long for a device ID (36 chars vs. 30), we choose to use only the part until the third '-' with a disk/nic prefix. For example if a disk has UUID '932df160-7a22-4067-a566-7e0ca8386133' the resulting device ID would be 'disk-932df160-7a22-4067'.

Parameters
dev_type:stringdevice type of param dev (HOTPLUG_TARGET_DISK|NIC)
dev:objects.Disk or objects.NICthe device object for which we generate a kvm name
def _GenerateDeviceHVInfoStr(hvinfo):

Construct the -device option string for hvinfo dict

PV disk: virtio-blk-pci,id=disk-1234,bus=pci.0,addr=0x9 PV NIC: virtio-net-pci,id=nic-1234,bus=pci.0,addr=0x9 SG disk: scsi-generic,id=disk-1234,bus=scsi.0,channel=0,scsi-id=1,lun=0

Parameters
hvinfo:dictdictionary created by _GenerateDeviceHVInfo()
Returns
stringThe constructed string to be passed along with a -device option
def _GenerateDeviceHVInfo(dev_type, kvm_devid, hv_dev_type, bus_slots):

Helper function to generate hvinfo of a device (disk, NIC)

hvinfo will hold all necessary info for generating the -device QEMU option. We have two main buses: a PCI bus and a SCSI bus (created by a SCSI controller on the PCI bus).

In case of PCI devices we add them on a free PCI slot (addr) on the first PCI bus (pci.0), and in case of SCSI devices we decide to put each disk on a different SCSI target (scsi-id) on the first SCSI bus (scsi.0).

Parameters
dev_type:stringeither HOTPLUG_TARGET_DISK or HOTPLUG_TARGET_NIC
kvm_devid:stringthe id of the device
hv_dev_type:stringeither disk_type or nic_type hvparam
bus_slots:dictthe current slots of the first PCI and SCSI buses
Returns
dictdict including all necessary info (driver, id, bus and bus location) for generating a -device QEMU option for either a disk or a NIC
def _GetExistingDeviceInfo(dev_type, device, runtime):

Helper function to get an existing device inside the runtime file

Used when an instance is running. Load kvm runtime file and search for a device based on its type and uuid.

Parameters
dev_type:stingdevice type of param dev
device:objects.Disk or objects.NICthe device object for which we generate a kvm name
runtime:tuple (cmd, nics, hvparams, disks)the runtime data to search for the device
Raises
errors.HotplugErrorin case the requested device does not exist (e.g. device has been added without --hotplug option)
def _UpgradeSerializedRuntime(serialized_runtime):

Upgrade runtime data

Remove any deprecated fields or change the format of the data. The runtime files are not upgraded when Ganeti is upgraded, so the required modification have to be performed here.

Parameters
serialized_runtime:stringraw text data read from actual runtime file
Returns
tuple(cmd, nic dicts, hvparams, bdev dicts)
def _AnalyzeSerializedRuntime(serialized_runtime):

Return runtime entries for a serialized runtime file

Parameters
serialized_runtime:stringraw text data read from actual runtime file
Returns
tuple(cmd, nics, hvparams, bdevs)
def _CheckUrl(url):

Check if a given URL exists on the server