NAME
App::FuguVM::QMP - the QEMU Machine Protocol command set
SYNOPSIS
use App::FuguVM::QMP;
my $qmp = App::FuguVM::QMP->new('/path/to/qmp.sock');
$qmp->open_connection or die "QEMU is not listening\n";
if ($qmp->is_running) {
$qmp->powerdown;
}
$qmp->disconnect;
DESCRIPTION
QEMU serves a machine-protocol socket that answers questions about the guest and takes lifecycle commands. The transport is Fugu::JSONSocket: one JSON object for each line, with a wall-clock deadline on every read. This module holds only the command set.
QMP sends a greeting and then refuses every command until qmp_capabilities succeeds. open_connection does both.
METHODS
new
new takes the socket path and opens nothing.
open_connection, disconnect
open_connection connects, reads the greeting and negotiates capabilities. It returns 1 on success and 0 on failure. A second call on an open connection is a success that does nothing.
run_command
$qmp->run_command($command, \%arguments)
Run one command and return the whole reply, so a caller can tell an error reply from a missing one.
query_status, is_running
query_status returns a hash reference with running and status, or undef when QEMU answered with an error. is_running reduces that to 1 or 0.
powerdown, quit
powerdown asks the guest to shut down through the ACPI power button. quit stops the QEMU process at once and closes the connection.
CAVEATS
An error reply is not an answer. Every method here tells the two apart, because a caller that reads an error as "not running" would stop a VM that is up.
SEE ALSO
Fugu::JSONSocket, App::FuguVM::Guest
AUTHOR
Dick Olsson <hi@senzilla.io>