class documentation

class QmpConnection(MonitorSocket):

View In Hierarchy

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

Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Instantiates the MonitorSocket object.
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 Executes a QMP command and returns the response of the server.
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 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 _GetResponse Parse the QMP response
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 _ParseMessage Extract and parse a QMP message from the given buffer.
Method _Recv Receives a message from QMP and decodes the received JSON object.
Method _RemoveFdset Wrapper around remove-fd qmp command
Method _Send Encodes and sends a message to KVM using QMP.
Constant _ACTUAL_KEY Undocumented
Constant _ARGUMENTS_KEY Undocumented
Constant _CAPABILITIES_COMMAND Undocumented
Constant _DEVICE_ATTRIBUTES Undocumented
Constant _ERROR_CLASS_KEY Undocumented
Constant _ERROR_DESC_KEY Undocumented
Constant _ERROR_KEY Undocumented
Constant _EVENT_KEY Undocumented
Constant _EXECUTE_KEY Undocumented
Constant _FIRST_MESSAGE_KEY Undocumented
Constant _MESSAGE_END_TOKEN Undocumented
Constant _PACKAGE_KEY Undocumented
Constant _QEMU_KEY Undocumented
Constant _QUERY_COMMANDS Undocumented
Constant _RETURN_KEY Undocumented
Constant _VERSION_KEY Undocumented
Instance Variable _buf Undocumented
Instance Variable _connected Undocumented

Inherited from MonitorSocket:

Method close Closes the socket
Method is_connected Return whether there is a connection to the socket or not.
Instance Variable monitor_filename Undocumented
Instance Variable sock Undocumented
Method _check_connection Make sure that the connection is established.
Method _check_socket Undocumented
Method _close Undocumented
Method _connect Connects to the monitor.
Constant _SOCKET_TIMEOUT Undocumented
def __enter__(self):

Undocumented

def __exit__(self, exc_type, exc_value, tb):

Undocumented

def __init__(self, monitor_filename):

Instantiates the MonitorSocket object.

Parameters
monitor_filename:stringthe filename of the UNIX raw socket on which the monitor (QMP or simple one) is listening
@_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(self, command, arguments=None):

Executes a QMP command and returns the response of the server.

Parameters
command:strthe command to execute
arguments:dictdictionary of arguments to be passed to the command
Returns
dictdictionary representing the received JSON object
Raises
errors.HypervisorErrorwhen there are communication errors
errors.ProgrammerErrorwhen there are data serialization errors
@_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, devid, uri, drive_add_fn=None):

Hot-add a disk

Try opening the device to obtain a fd and pass it with SCM_RIGHTS. This will be omitted in case of userspace access mode (open will fail). Then use blockdev-add QMP command or drive_add_fn() callback if any. The add the guest device.

@_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

Note that drive_del is not supported yet in qmp and thus should be invoked from HMP.

@_ensure_connection
def HotDelNic(self, devid):

Hot-del a NIC

@_ensure_connection
def Powerdown(self):

Undocumented

@_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 _GetResponse(self, command):

Parse the QMP response

If error key found in the response message raise HypervisorError. Ignore any async event and thus return the response message related to command.

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 _ParseMessage(self, buf):

Extract and parse a QMP message from the given buffer.

Seeks for a QMP message in the given buf. If found, it parses it and returns it together with the rest of the characters in the buf. If no message is found, returns None and the whole buffer.

Raises
errors.ProgrammerErrorwhen there are data serialization errors
def _Recv(self):

Receives a message from QMP and decodes the received JSON object.

Returns
QmpMessagethe received message
Raises
errors.HypervisorErrorwhen there are communication errors
errors.ProgrammerErrorwhen there are data serialization errors
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.

def _Send(self, message):

Encodes and sends a message to KVM using QMP.

Parameters
message:QmpMessagemessage to send to KVM
Raises
errors.HypervisorErrorwhen there are communication errors
errors.ProgrammerErrorwhen there are data serialization errors
_ACTUAL_KEY: str =

Undocumented

Value
'actual'
_ARGUMENTS_KEY: str =

Undocumented

Value
'arguments'
_CAPABILITIES_COMMAND: str =

Undocumented

Value
'qmp_capabilities'
_DEVICE_ATTRIBUTES: list[str] =

Undocumented

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

Undocumented

Value
'class'
_ERROR_DESC_KEY: str =

Undocumented

Value
'desc'
_ERROR_KEY: str =

Undocumented

Value
'error'
_EVENT_KEY: str =

Undocumented

Value
'event'
_EXECUTE_KEY: str =

Undocumented

Value
'execute'
_FIRST_MESSAGE_KEY: str =

Undocumented

Value
'QMP'
_MESSAGE_END_TOKEN: bytes =

Undocumented

Value
b'''\r
'''
_PACKAGE_KEY: str =

Undocumented

Value
'package'
_QEMU_KEY: str =

Undocumented

Value
'qemu'
_QUERY_COMMANDS: str =

Undocumented

Value
'query-commands'
_RETURN_KEY: str =

Undocumented

Value
'return'
_VERSION_KEY: str =

Undocumented

Value
'version'
_buf =

Undocumented