]> git.proxmox.com Git - qemu-server.git/commitdiff
api: factor out common vm_is_paused code in private helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 16 Oct 2020 15:51:24 +0000 (17:51 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 16 Oct 2020 15:51:24 +0000 (17:51 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Qemu.pm

index 2418b7c3cd7a0c34c6bf170b14cb2e37c6527980..e8de4eac9a659e40070d8f0c344a0306976272e2 100644 (file)
@@ -2401,6 +2401,16 @@ __PACKAGE__->register_method({
        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({
     name => 'vm_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
        # and the status query should not take too long
-       my $qmpstatus = eval {
-           PVE::QemuConfig::assert_config_exists_on_node($vmid);
-           mon_cmd($vmid, "query-status");
-       };
-       my $err = $@ if $@;
-
-       if (!$err && $qmpstatus->{status} eq "paused") {
+       if (vm_is_paused($vmid)) {
            if ($param->{forceStop}) {
                warn "VM is paused - stop instead of shutdown\n";
                $shutdown = 0;
@@ -2551,15 +2555,7 @@ __PACKAGE__->register_method({
        my $node = extract_param($param, 'node');
        my $vmid = extract_param($param, 'vmid');
 
-       my $qmpstatus = eval {
-           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 is paused - cannot shutdown\n" if vm_is_paused($vmid);
 
        die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);