mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-01 04:51:50 +00:00
api: factor out common vm_is_paused code in private helper
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
11c601e9ad
commit
009cbf61bc
@ -2401,6 +2401,16 @@ __PACKAGE__->register_method({
|
|||||||
return $rpcenv->fork_worker('qmreset', $vmid, $authuser, $realcmd);
|
return $rpcenv->fork_worker('qmreset', $vmid, $authuser, $realcmd);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
my sub vm_is_paused {
|
||||||
|
my ($vmid) = @_;
|
||||||
|
my $qmpstatus = eval {
|
||||||
|
PVE::QemuConfig::assert_config_exists_on_node($vmid);
|
||||||
|
mon_cmd($vmid, "query-status");
|
||||||
|
};
|
||||||
|
warn "$@\n" if $@;
|
||||||
|
return $qmpstatus && $qmpstatus->{status} eq "paused";
|
||||||
|
}
|
||||||
|
|
||||||
__PACKAGE__->register_method({
|
__PACKAGE__->register_method({
|
||||||
name => 'vm_shutdown',
|
name => 'vm_shutdown',
|
||||||
path => '{vmid}/status/shutdown',
|
path => '{vmid}/status/shutdown',
|
||||||
@ -2469,13 +2479,7 @@ __PACKAGE__->register_method({
|
|||||||
#
|
#
|
||||||
# checking the qmp status here to get feedback to the gui/cli/api
|
# checking the qmp status here to get feedback to the gui/cli/api
|
||||||
# and the status query should not take too long
|
# and the status query should not take too long
|
||||||
my $qmpstatus = eval {
|
if (vm_is_paused($vmid)) {
|
||||||
PVE::QemuConfig::assert_config_exists_on_node($vmid);
|
|
||||||
mon_cmd($vmid, "query-status");
|
|
||||||
};
|
|
||||||
my $err = $@ if $@;
|
|
||||||
|
|
||||||
if (!$err && $qmpstatus->{status} eq "paused") {
|
|
||||||
if ($param->{forceStop}) {
|
if ($param->{forceStop}) {
|
||||||
warn "VM is paused - stop instead of shutdown\n";
|
warn "VM is paused - stop instead of shutdown\n";
|
||||||
$shutdown = 0;
|
$shutdown = 0;
|
||||||
@ -2551,15 +2555,7 @@ __PACKAGE__->register_method({
|
|||||||
my $node = extract_param($param, 'node');
|
my $node = extract_param($param, 'node');
|
||||||
my $vmid = extract_param($param, 'vmid');
|
my $vmid = extract_param($param, 'vmid');
|
||||||
|
|
||||||
my $qmpstatus = eval {
|
die "VM is paused - cannot shutdown\n" if vm_is_paused($vmid);
|
||||||
PVE::QemuConfig::assert_config_exists_on_node($vmid);
|
|
||||||
mon_cmd($vmid, "query-status");
|
|
||||||
};
|
|
||||||
my $err = $@ if $@;
|
|
||||||
|
|
||||||
if (!$err && $qmpstatus->{status} eq "paused") {
|
|
||||||
die "VM is paused - cannot shutdown\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
|
die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user