add and use get_qga_key

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-11-20 12:39:45 +01:00
parent e5b18771b8
commit a2af1bbe89
2 changed files with 14 additions and 6 deletions

View 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") };
}

View 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");