class documentation

Connection to the QEMU Monitor using the QEMU Monitor Protocol (QMP).

Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method CheckDiskHotAddSupport Check if disk hotplug is possible
Method CheckNicHotAddSupport Check if NIC hotplug is possible
Method connect Connects to the QMP monitor.
Method ContinueGuestEmulation Continue the previously paused guest
Method execute_qmp Undocumented
Method GetCpuInformation Retrieve CPU/thread information uses the query-cpus-fast which does not interrupt the guest
Method GetFreePCISlot Get the first available PCI slot of a running instance.
Method GetMigrationStatus Retrieve the current migration status
Method GetVersion Return the QMP/qemu version field
Method HasDevice Check if a specific device exists or not on a running instance.
Method HasDynamicAutoReadOnly Check if QEMU uses dynamic auto-read-only for block devices
Method HotAddDisk Hot-add a disk
Method HotAddNic Hot-add a NIC
Method HotDelDisk Hot-del a Disk
Method HotDelNic Hot-del a NIC
Method Powerdown Undocumented
Method ResizeBlockDevice Notify the guest about a disk change.
Method SetBalloonMemory Undocumented
Method SetMigrationCapabilities Configure live migration capabilities
Method SetMigrationParameters Configute live migration parameters
Method SetSpicePassword Set Spice password of an instance
Method SetVNCPassword Set VNC password of an instance
Method StartMigration Start migration of an instance
Method StartPostcopyMigration Start postcopy-ram migration
Method StopGuestEmulation Pause the running guest
Constant ACTUAL_KEY Undocumented
Instance Variable package Undocumented
Instance Variable supported_commands Undocumented
Instance Variable version Undocumented
Method _AddFd Wrapper around add-fd qmp command
Method _filter_hvinfo Filter non valid keys of the device's hvinfo (if any).
Method _GetBlockDevices Get the block devices of a running instance.
Method _GetFd Wrapper around the getfd qmp command
Method _GetPCIDevices Get the devices of the first PCI bus of a running instance.
Method _GetSupportedCommands Update the list of supported commands.
Method _HasBlockDevice Check if a specific device ID exists among block devices.
Method _HasPCIDevice Check if a specific device ID exists on the PCI bus.
Method _RemoveFdset Wrapper around remove-fd qmp command
Constant _ACTUAL_KEY Undocumented
Constant _CAPABILITIES_COMMAND Undocumented
Constant _DEVICE_ATTRIBUTES Undocumented
Constant _FIRST_MESSAGE_KEY Undocumented
Constant _MESSAGE_END_TOKEN Undocumented
Constant _PACKAGE_KEY Undocumented
Constant _QEMU_KEY Undocumented
Constant _QMP_TIMEOUT Undocumented
Constant _QUERY_COMMANDS Undocumented
Constant _RETURN_KEY Undocumented
Constant _VERSION_KEY Undocumented
Instance Variable _buffer Undocumented

Inherited from QemuMonitorSocket:

Method get_qmp_response Undocumented
Method recv_qmp Undocumented
Method send_qmp Undocumented
Method wait_for_qmp_event Waits for one of the specified events and returns it. If the timeout is reached, returns None.
Method _read_buffer Undocumented
Constant _ARGUMENTS_KEY Undocumented
Constant _ERROR_CLASS_KEY Undocumented
Constant _ERROR_DESC_KEY Undocumented
Constant _ERROR_KEY Undocumented
Constant _EVENT_KEY Undocumented
Constant _EXECUTE_KEY Undocumented
Constant _SEND_END_TOKEN Undocumented

Inherited from UnixFileSocketConnection (via QemuMonitorSocket):

Method close Undocumented
Method is_connected Undocumented
Method recv Undocumented
Method reset_timeout Reset the timeout to self.timeout
Method send Undocumented
Instance Variable sock Undocumented
Instance Variable socket_path Undocumented
Instance Variable timeout Undocumented
Instance Variable _connected Undocumented
def __exit__(self, exc_type, exc_value, tb):
def __init__(self, socket_path: str):
@_ensure_connection
def CheckDiskHotAddSupport(self):

Check if disk hotplug is possible

Hotplug is *not* supported in case the add-fd and blockdev-add qmp commands are not supported

@_ensure_connection
def CheckNicHotAddSupport(self):

Check if NIC hotplug is possible

Hotplug is *not* supported in case the getfd and netdev_add qmp commands are not supported

def connect(self):

Connects to the QMP monitor.

Connects to the UNIX socket and makes sure that we can actually send and receive data to the kvm instance via QMP.

Raises
errors.HypervisorErrorwhen there are communication errors
errors.ProgrammerErrorwhen there are data serialization errors
@_ensure_connection
def ContinueGuestEmulation(self):

Continue the previously paused guest

def execute_qmp(self, command: str, arguments: dict = None) -> QmpMessage:
@_ensure_connection
def GetCpuInformation(self):

Retrieve CPU/thread information uses the query-cpus-fast which does not interrupt the guest

@_ensure_connection
def GetFreePCISlot(self):

Get the first available PCI slot of a running instance.

@_ensure_connection
def GetMigrationStatus(self):

Retrieve the current migration status

@_ensure_connection
def GetVersion(self):

Return the QMP/qemu version field

Accessing the version attribute directly might result in an error since the socket might not be yet connected. This getter method uses the @_ensure_connection decorator to work around this problem.

@_ensure_connection
def HasDevice(self, devid):

Check if a specific device exists or not on a running instance.

It first checks the PCI devices and then the block devices.

@_ensure_connection
def HasDynamicAutoReadOnly(self):

Check if QEMU uses dynamic auto-read-only for block devices

Use QMP schema introspection (QEMU 2.5+) to check for the dynamic-auto-read-only feature.

@_ensure_connection
def HotAddDisk(self, disk, access_mode, cache_writeback, direct, blockdevice):

Hot-add a disk

@_ensure_connection
def HotAddNic(self, nic, devid, tapfds=None, vhostfds=None, features=None, is_chrooted=False):

Hot-add a NIC

First pass the tapfds, then netdev_add and then device_add

@_ensure_connection
def HotDelDisk(self, devid):

Hot-del a Disk

@_ensure_connection
def HotDelNic(self, devid):

Hot-del a NIC

@_ensure_connection
def Powerdown(self):

Undocumented

@_ensure_connection
def ResizeBlockDevice(self, disk_id: str, new_size: int):

Notify the guest about a disk change.

@_ensure_connection
def SetBalloonMemory(self, memory):

Undocumented

@_ensure_connection
def SetMigrationCapabilities(self, capabilities, state):

Configure live migration capabilities

@_ensure_connection
def SetMigrationParameters(self, max_bandwidth, downtime_limit):

Configute live migration parameters

@_ensure_connection
def SetSpicePassword(self, spice_pwd):

Set Spice password of an instance

@_ensure_connection
def SetVNCPassword(self, vnc_pwd):

Set VNC password of an instance

@_ensure_connection
def StartMigration(self, target, port):

Start migration of an instance

@_ensure_connection
def StartPostcopyMigration(self):

Start postcopy-ram migration

@_ensure_connection
def StopGuestEmulation(self):

Pause the running guest

ACTUAL_KEY: str =

Undocumented

Value
'actual'
package =

Undocumented

supported_commands =

Undocumented

version =

Undocumented

def _AddFd(self, fd):

Wrapper around add-fd qmp command

Send fd to a running process via SCM_RIGHTS and then add-fd qmp command to add it to an fdset so that it can be used later by disk hotplugging.

Parameters
fd:intThe file descriptor to pass
Returns
The fdset ID that the fd has been added to
Raises
errors.HypervisorErrorIf add-fd fails for some reason
def _filter_hvinfo(self, hvinfo):

Filter non valid keys of the device's hvinfo (if any).

def _GetBlockDevices(self):

Get the block devices of a running instance.

The query-block QMP command returns a list of dictionaries including information for each virtual disk. For example:

[{"device": "disk-049f140d", "inserted": {"file": ..., "image": ...}}]

Returns
list of dictsInfo about the virtual disks of the instance.
def _GetFd(self, fd, fdname):

Wrapper around the getfd qmp command

Send an fd to a running process via SCM_RIGHTS and then use the getfd qmp command to name it properly so that it can be used later by NIC hotplugging.

Parameters
fd:intThe file descriptor to pass
fdnameUndocumented
Raises
errors.HypervisorErrorIf getfd fails for some reason
def _GetPCIDevices(self):

Get the devices of the first PCI bus of a running instance.

def _GetSupportedCommands(self):

Update the list of supported commands.

def _HasBlockDevice(self, devid):

Check if a specific device ID exists among block devices.

def _HasPCIDevice(self, devid):

Check if a specific device ID exists on the PCI bus.

def _RemoveFdset(self, fdset):

Wrapper around remove-fd qmp command

Remove the file descriptor previously passed. After qemu has dup'd the fd (e.g. during disk hotplug), it can be safely removed.

_ACTUAL_KEY: str =

Undocumented

Value
'actual'
_CAPABILITIES_COMMAND: str =

Undocumented

Value
'qmp_capabilities'
_DEVICE_ATTRIBUTES: list[str] =

Undocumented

Value
['driver', 'id', 'bus', 'addr', 'channel', 'scsi-id', 'lun']
_FIRST_MESSAGE_KEY: str =

Undocumented

Value
'QMP'
_MESSAGE_END_TOKEN: bytes =
_PACKAGE_KEY: str =

Undocumented

Value
'package'
_QEMU_KEY: str =

Undocumented

Value
'qemu'
_QMP_TIMEOUT: int =

Undocumented

Value
5
_QUERY_COMMANDS: str =

Undocumented

Value
'query-commands'
_RETURN_KEY: str =
_VERSION_KEY: str =

Undocumented

Value
'version'