alpy.qemu¶
This module contains functions for generating QEMU command line arguments and managing QEMU process.
- alpy.qemu.OVMF_VARS_COPY_FILENAME = 'OVMF_VARS.fd'¶
OVMF variables store filename
- alpy.qemu.QMP_SOCKET_FILENAME = 'qmp.sock'¶
Path to unix domain socket for QMP
- alpy.qemu.close(process, timeout)[source]¶
Stop QEMU.
Wait for QEMU process to stop. If the process does not stop, kill it. Check exit code. Log process output and the exit code via Python
logging
module.- Parameters:
process (
subprocess.Popen
) – QEMU processtimeout (int) – maximum number of seconds to wait
- Raises:
alpy.utils.NonZeroExitCode – if the process exited with non-zero code or was killed by a signal
- alpy.qemu.get_network_interface_args(interface_index, interface_name)[source]¶
Get QEMU command line arguments which add network interface.
The arguments also instruct QEMU to capture packets on the interface. The packets are captured to file “link{interface_index}.pcap”.
- alpy.qemu.get_network_interfaces_args(tap_interfaces)[source]¶
Get QEMU command line arguments which add network interfaces.
The arguments also instruct QEMU to capture packets on the interfaces. The packets are captured to files “link0.pcap”, “link1.pcap”, etc.
- alpy.qemu.get_qmp_args()[source]¶
Get QMP-related QEMU command line arguments.
The arguments instruct QEMU to connect to QMP server at startup.
The connection is made to unix socket. The path is specified by
alpy.qemu.QMP_SOCKET_FILENAME
.
- alpy.qemu.get_serial_port_args(tcp_port=2023)[source]¶
Get QEMU command line arguments which add serial port.
QEMU listens on and redirects virtual serial port to 127.0.0.1 port tcp_port.
The arguments also instruct QEMU to capture serial port output. The output is captured to file “console.log”.
- alpy.qemu.get_uefi_firmware_args()[source]¶
Get UEFI-related QEMU command line arguments.
See also Open Virtual Machine Firmware (OVMF) Status Report:
The 128 KB firmware volume with the variable store, discussed under (1), is also built as a separate host-side file, named “OVMF_VARS.fd”. The “rest” is built into a third file, “OVMF_CODE.fd”, which is only 1920 KB in size. The variable store is mapped into its usual location, at 4 GB - 2 MB = 0xFFE0_0000, through the following qemu options:
-drive if=pflash,format=raw,readonly,file=OVMF_CODE.fd -drive if=pflash,format=raw,file=fedora.varstore.fd
See also #764918 - Please split into OVMF_VARS.fd and OVMF_CODE.fd - Debian Bug report logs.
- alpy.qemu.read_events(qmp)[source]¶
Read and log QEMU events.
- Parameters:
qmp (QEMUMonitorProtocol) – QMP handle
- alpy.qemu.run(qemu_args, timeout)[source]¶
QEMU process context manager.
On entering context the manager starts a QMP server and a QEMU process. QEMU connects to the QMP server. On exiting the context the quit QMP command is issued, QEMU process stops.
- Parameters:
qemu_args (list(str)) – QEMU command line arguments. The arguments must include QMP-related arguments returned by
alpy.qemu.get_qmp_args()
.timeout (int) – number of seconds to wait for QEMU to stop after issuing the quit QMP command
- Returns:
QMP handle
- Return type:
QEMUMonitorProtocol
- alpy.qemu.start_virtual_cpu(qmp)[source]¶
Start virtual CPU.
- Parameters:
qmp (QEMUMonitorProtocol) – QMP handle
- alpy.qemu.temporary_copy_ovmf_vars()[source]¶
Make a temporary file to store OVMF variables.
On entering context this context manager makes a file to store OVMF variables in. The path is specified by
alpy.qemu.OVMF_VARS_COPY_FILENAME
. The file is a copy of “/usr/share/OVMF/OVMF_VARS.fd”. On exiting the context the file is removed.See also
alpy.qemu.get_uefi_firmware_args()
.