api: use shared methods in config GET

in config GET call, we can now use the new shared methods from
guest-common, namely load_current_config and load_snapshot_config.

the correct method is called depending on the parameters 'current' or
'snapshot'

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
This commit is contained in:
Oguz Bektas 2019-10-14 10:28:37 +02:00 committed by Thomas Lamprecht
parent f73ed6d10f
commit d3179e1c36

View File

@ -865,40 +865,19 @@ __PACKAGE__->register_method({
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
my $conf = PVE::QemuConfig->load_config($param->{vmid}); raise_param_exc({ snapshot => "cannot use 'snapshot' parameter with 'current'",
current => "cannot use 'snapshot' parameter with 'current'"})
if ($param->{snapshot} && $param->{current});
if (my $snapname = $param->{snapshot}) { my $conf;
my $snapshot = $conf->{snapshots}->{$snapname}; if ($param->{snapshot}) {
die "snapshot '$snapname' does not exist\n" if !defined($snapshot); $conf = PVE::QemuConfig->load_snapshot_config($param->{vmid}, $param->{snapshot});
} else {
$snapshot->{digest} = $conf->{digest}; # keep file digest for API $conf = PVE::QemuConfig->load_current_config($param->{vmid}, $param->{current});
$conf = $snapshot;
} }
$conf->{cipassword} = '**********' if $conf->{cipassword};
delete $conf->{snapshots};
if (!$param->{current}) {
foreach my $opt (keys %{$conf->{pending}}) {
next if $opt eq 'delete';
my $value = $conf->{pending}->{$opt};
next if ref($value); # just to be sure
$conf->{$opt} = $value;
}
my $pending_delete_hash = PVE::QemuServer::split_flagged_list($conf->{pending}->{delete});
foreach my $opt (keys %$pending_delete_hash) {
delete $conf->{$opt} if $conf->{$opt};
}
}
delete $conf->{pending};
# hide cloudinit password
if ($conf->{cipassword}) {
$conf->{cipassword} = '**********';
}
return $conf; return $conf;
}}); }});
__PACKAGE__->register_method({ __PACKAGE__->register_method({