guest_agent

Interacting with the QEMU Guest Agent.

class compute.instance.guest_agent.GuestAgent(domain: virDomain, timeout: int = 60)

Class for interacting with QEMU guest agent.

__init__(domain: virDomain, timeout: int = 60)

Initialise GuestAgent.

Parameters:
  • domain – Libvirt domain object

  • timeout – QEMU timeout

execute(command: dict) dict

Execute QEMU guest agent command.

See: https://qemu-project.gitlab.io/qemu/interop/qemu-ga-ref.html

Parameters:

command – QEMU guest agent command as dict

Returns:

Command output

Return type:

dict

get_supported_commands() set[str]

Return set of supported guest agent commands.

guest_exec(path: str, args: list[str] | None = None, env: list[str] | None = None, stdin: str | None = None, *, capture_output: bool = False, decode_output: bool = False, poll: bool = False) GuestExecOutput

Execute qemu-exec command and return output.

Parameters:
  • path – Path ot executable on guest.

  • arg – List of arguments to pass to executable.

  • env – List of environment variables to pass to executable. For example: ['LANG=C', 'TERM=xterm']

  • stdin – Data to pass to executable STDIN.

  • capture_output – Capture command output.

  • decode_output – Use base64_decode() to decode command output. Affects only if capture_output is True.

  • poll – Poll command output. Uses self.timeout and POLL_INTERVAL constant.

Returns:

Command output

Return type:

GuestExecOutput

guest_exec_status(pid: int, *, poll: bool = False, poll_interval: float = 0.3) dict

Execute guest-exec-status and return output.

Parameters:
  • pid – PID in guest.

  • poll – If True poll command status.

  • poll_interval – Time between attempts to obtain command status.

Returns:

Command output

Return type:

dict

is_available() bool

Execute guest-ping.

Returns:

True or False if guest agent is unreachable.

Return type:

bool

raise_for_commands(commands: list[str]) None

Raise exception if QEMU GA command is not available.

Parameters:

commands – List of required commands

Raise:

GuestAgentCommandNotSupportedError

class compute.instance.guest_agent.GuestExecOutput(exited: bool | None = None, exitcode: int | None = None, stdout: str | None = None, stderr: str | None = None)

QEMU guest-exec command output.

exitcode: int | None

Alias for field number 1

exited: bool | None

Alias for field number 0

stderr: str | None

Alias for field number 3

stdout: str | None

Alias for field number 2