1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-12-04 20:23:46 +03:00

Implement virDomainQemuMonitorCommandWithFiles() override

With libvirt-8.2.0 there's a new API:
virDomainQemuMonitorCommandWithFiles(). Since the API has both
input and output arguments we need to provide an alternative
implementation. Moreover, since FD passing works only on
UNIX-like systems we can query the returned FDs for their flags
and construct mode for python File object.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik
2022-03-04 10:09:46 +01:00
parent a80412bf8c
commit 050ed3e629
3 changed files with 149 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
# Manually written part of python bindings for libvirt-qemu
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, List, IO
def _dispatchQemuMonitorEventCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, event: str, seconds: int, micros: int, details: str, cbData: Dict[str, Any]) -> int:
@@ -38,3 +38,32 @@ def qemuMonitorEventRegister(conn: libvirt.virConnect, dom: libvirt.virDomain, e
raise libvirt.libvirtError('virConnectDomainQemuMonitorEventRegister() failed')
conn.qemuMonitorEventCallbackID[ret] = opaque # type: ignore
return ret
def qemuMonitorCommandWithFiles(domain: libvirt.virDomain, cmd: str, files: List[int] = [], flags: int = 0) -> (str, List[IO]):
"""This API is QEMU specific, so it will only work with hypervisor
connections to the QEMU driver with local connections using the unix
socket.
Send an arbitrary monitor command @cmd with file descriptors @files to
domain through the QEMU monitor and optionally return a list of files
in the returned tuple. There are several requirements to safely
and successfully use this API:
- A @cmd that queries state without making any modifications is safe
- A @cmd that alters state that is also tracked by libvirt is unsafe,
and may cause libvirtd to crash
- A @cmd that alters state not tracked by the current version of
libvirt is possible as a means to test new qemu features before
they have support in libvirt, but no guarantees are made to safety
If VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP is set, the command is considered to
be a human monitor command and libvirt will automatically convert it into
QMP if needed. In that case the @result will also be converted back from
QMP.
Returns a tuple consisting of the string output from @cmd and a list of
files respectively."""
ret = libvirtmod_qemu.virDomainQemuMonitorCommandWithFiles(domain._o, cmd, files, flags)
if ret is None:
raise libvirt.libvirtError('virDomainQemuMonitorCommandWithFiles() failed')
return ret