]> git.proxmox.com Git - qemu-server.git/commitdiff
add and use get_qga_key
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 20 Nov 2020 11:39:45 +0000 (12:39 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 25 Nov 2020 13:18:23 +0000 (14:18 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuServer.pm

index bef83df7f1381dd5dd45479ac10e2e551874d9ec..09c15f46b3698d30e8394c1df50198be706f487c 100644 (file)
@@ -2099,7 +2099,7 @@ __PACKAGE__->register_method({
        $status->{ha} = PVE::HA::Config::get_service_status("vm:$param->{vmid}");
 
        $status->{spice} = 1 if PVE::QemuServer::vga_conf_has_spice($conf->{vga});
-       $status->{agent} = 1 if (PVE::QemuServer::parse_guest_agent($conf)->{enabled});
+       $status->{agent} = 1 if PVE::QemuServer::get_qga_key($conf, 'enabled');
 
        return $status;
     }});
@@ -3298,7 +3298,7 @@ __PACKAGE__->register_method({
 
                    PVE::QemuConfig->write_config($vmid, $conf);
 
-                   my $do_trim = PVE::QemuServer::parse_guest_agent($conf)->{fstrim_cloned_disks};
+                   my $do_trim = PVE::QemuServer::get_qga_key($conf, 'fstrim_cloned_disks');
                    if ($running && $do_trim && PVE::QemuServer::qga_check_running($vmid)) {
                        eval { mon_cmd($vmid, "guest-fstrim") };
                    }
index 0103386e760bcf46222357893fbcbeed2cb0d567..6fa23fe6ee14310746608b2550a5f64177d69972 100644 (file)
@@ -1966,11 +1966,11 @@ sub parse_watchdog {
 }
 
 sub parse_guest_agent {
-    my ($value) = @_;
+    my ($conf) = @_;
 
-    return {} if !defined($value->{agent});
+    return {} if !defined($conf->{agent});
 
-    my $res = eval { parse_property_string($agent_fmt, $value->{agent}) };
+    my $res = eval { parse_property_string($agent_fmt, $conf->{agent}) };
     warn $@ if $@;
 
     # if the agent is disabled ignore the other potentially set properties
@@ -1978,6 +1978,14 @@ sub parse_guest_agent {
     return $res;
 }
 
+sub get_qga_key {
+    my ($conf, $key) = @_;
+    return undef if !defined($conf->{agent});
+
+    my $agent = parse_guest_agent($conf);
+    return $agent->{$key};
+}
+
 sub parse_vga {
     my ($value) = @_;
 
@@ -5359,7 +5367,7 @@ sub _do_vm_stop {
 
     eval {
        if ($shutdown) {
-           if (defined($conf) && parse_guest_agent($conf)->{enabled}) {
+           if (defined($conf) && get_qga_key($conf, 'enabled')) {
                mon_cmd($vmid, "guest-shutdown", timeout => $timeout);
            } else {
                mon_cmd($vmid, "system_powerdown");