class QmpConnection(MonitorSocket):
Connection to the QEMU Monitor using the QEMU Monitor Protocol (QMP).
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | __init__ |
Instantiates the MonitorSocket object. |
Method |
|
Check if disk hotplug is possible |
Method |
|
Check if NIC hotplug is possible |
Method | connect |
Connects to the QMP monitor. |
Method |
|
Continue the previously paused guest |
Method |
|
Executes a QMP command and returns the response of the server. |
Method |
|
Retrieve CPU/thread information uses the query-cpus-fast which does not interrupt the guest |
Method |
|
Get the first available PCI slot of a running instance. |
Method |
|
Retrieve the current migration status |
Method |
|
Return the QMP/qemu version field |
Method |
|
Check if a specific device exists or not on a running instance. |
Method |
|
Check if QEMU uses dynamic auto-read-only for block devices |
Method |
|
Hot-add a disk |
Method |
|
Hot-add a NIC |
Method |
|
Hot-del a Disk |
Method |
|
Hot-del a NIC |
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Configure live migration capabilities |
Method |
|
Configute live migration parameters |
Method |
|
Set Spice password of an instance |
Method |
|
Set VNC password of an instance |
Method |
|
Start migration of an instance |
Method |
|
Start postcopy-ram migration |
Method |
|
Pause the running guest |
Constant | ACTUAL |
Undocumented |
Instance Variable | package |
Undocumented |
Instance Variable | supported |
Undocumented |
Instance Variable | version |
Undocumented |
Method | _ |
Wrapper around add-fd qmp command |
Method | _filter |
Filter non valid keys of the device's hvinfo (if any). |
Method | _ |
Get the block devices of a running instance. |
Method | _ |
Wrapper around the getfd qmp command |
Method | _ |
Get the devices of the first PCI bus of a running instance. |
Method | _ |
Parse the QMP response |
Method | _ |
Update the list of supported commands. |
Method | _ |
Check if a specific device ID exists among block devices. |
Method | _ |
Check if a specific device ID exists on the PCI bus. |
Method | _ |
Extract and parse a QMP message from the given buffer. |
Method | _ |
Receives a message from QMP and decodes the received JSON object. |
Method | _ |
Wrapper around remove-fd qmp command |
Method | _ |
Encodes and sends a message to KVM using QMP. |
Constant | _ACTUAL |
Undocumented |
Constant | _ARGUMENTS |
Undocumented |
Constant | _CAPABILITIES |
Undocumented |
Constant | _DEVICE |
Undocumented |
Constant | _ERROR |
Undocumented |
Constant | _ERROR |
Undocumented |
Constant | _ERROR |
Undocumented |
Constant | _EVENT |
Undocumented |
Constant | _EXECUTE |
Undocumented |
Constant | _FIRST |
Undocumented |
Constant | _MESSAGE |
Undocumented |
Constant | _PACKAGE |
Undocumented |
Constant | _QEMU |
Undocumented |
Constant | _QUERY |
Undocumented |
Constant | _RETURN |
Undocumented |
Constant | _VERSION |
Undocumented |
Instance Variable | _buf |
Undocumented |
Instance Variable | _connected |
Undocumented |
Inherited from MonitorSocket
:
Method | close |
Closes the socket |
Method | is |
Return whether there is a connection to the socket or not. |
Instance Variable | monitor |
Undocumented |
Instance Variable | sock |
Undocumented |
Method | _check |
Make sure that the connection is established. |
Method | _check |
Undocumented |
Method | _close |
Undocumented |
Method | _connect |
Connects to the monitor. |
Constant | _SOCKET |
Undocumented |
Instantiates the MonitorSocket object.
Parameters | |
monitor | the filename of the UNIX raw socket on which the monitor (QMP or simple one) is listening |
Check if disk hotplug is possible
Hotplug is *not* supported in case the add-fd and blockdev-add qmp commands are not supported
Check if NIC hotplug is possible
Hotplug is *not* supported in case the getfd and netdev_add qmp commands are not supported
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.HypervisorError | when there are communication errors |
errors.ProgrammerError | when there are data serialization errors |
Executes a QMP command and returns the response of the server.
Parameters | |
command:str | the command to execute |
arguments:dict | dictionary of arguments to be passed to the command |
Returns | |
dict | dictionary representing the received JSON object |
Raises | |
errors.HypervisorError | when there are communication errors |
errors.ProgrammerError | when there are data serialization errors |
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.
Check if a specific device exists or not on a running instance.
It first checks the PCI devices and then the block devices.
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.
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.
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
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:int | The file descriptor to pass |
Returns | |
The fdset ID that the fd has been added to | |
Raises | |
errors.HypervisorError | If add-fd fails for some reason |
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 dicts | Info about the virtual disks of the instance. |
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:int | The file descriptor to pass |
fdname | Undocumented |
Raises | |
errors.HypervisorError | If getfd fails for some reason |
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.
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.ProgrammerError | when there are data serialization errors |
Receives a message from QMP and decodes the received JSON object.
Returns | |
QmpMessage | the received message |
Raises | |
errors.HypervisorError | when there are communication errors |
errors.ProgrammerError | when there are data serialization errors |
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.
Encodes and sends a message to KVM using QMP.
Parameters | |
message:QmpMessage | message to send to KVM |
Raises | |
errors.HypervisorError | when there are communication errors |
errors.ProgrammerError | when there are data serialization errors |