5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-25 06:03:52 +03:00
Thomas Lamprecht ae1f94e158 mon_cmd: add explicit return
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-11-30 17:24:55 +01:00

64 lines
1.2 KiB
Perl

package PVE::QemuServer::Monitor;
use strict;
use warnings;
use PVE::SafeSyslog;
use PVE::QemuServer::Helpers;
use PVE::QMPClient;
use base 'Exporter';
our @EXPORT_OK = qw(
mon_cmd
);
sub qmp_cmd {
my ($vmid, $cmd) = @_;
my $res;
my $timeout;
if ($cmd->{arguments}) {
$timeout = delete $cmd->{arguments}->{timeout};
}
eval {
die "VM $vmid not running\n" if !PVE::QemuServer::Helpers::vm_running_locally($vmid);
my $sname = PVE::QemuServer::Helpers::qmp_socket($vmid);
if (-e $sname) { # test if VM is reasonably new and supports qmp/qga
my $qmpclient = PVE::QMPClient->new();
$res = $qmpclient->cmd($vmid, $cmd, $timeout);
} else {
die "unable to open monitor socket\n";
}
};
if (my $err = $@) {
syslog("err", "VM $vmid qmp command failed - $err");
die $err;
}
return $res;
}
sub mon_cmd {
my ($vmid, $execute, %params) = @_;
my $cmd = { execute => $execute, arguments => \%params };
return qmp_cmd($vmid, $cmd);
}
sub hmp_cmd {
my ($vmid, $cmdline) = @_;
my $cmd = {
execute => 'human-monitor-command',
arguments => { 'command-line' => $cmdline },
};
return qmp_cmd($vmid, $cmd);
}
1;