FuguVM

App::FuguVM::QMP(3p) Perl Library Manual App::FuguVM::QMP(3p)

App::FuguVM::QMP - the QEMU Machine Protocol command set

    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;

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.

"new" takes the socket path and opens nothing.

"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.

    $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" 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" asks the guest to shut down through the ACPI power button. "quit" stops the QEMU process at once and closes the connection.

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.

Fugu::JSONSocket, App::FuguVM::Guest

Dick Olsson <hi@senzilla.io>

2026-10-16 OpenBSD