[pve-devel] [PATCH v3 qemu-server 05/19] api: use shared methods in config GET

Oguz Bektas o.bektas at proxmox.com
Mon Oct 14 10:28:37 CEST 2019


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 at proxmox.com>
---
 PVE/API2/Qemu.pm | 41 ++++++++++-------------------------------
 1 file changed, 10 insertions(+), 31 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 267a08e..ba6de27 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -865,40 +865,19 @@ __PACKAGE__->register_method({
     code => sub {
 	my ($param) = @_;
 
-	my $conf = PVE::QemuConfig->load_config($param->{vmid});
-
-	if (my $snapname = $param->{snapshot}) {
-	    my $snapshot = $conf->{snapshots}->{$snapname};
-	    die "snapshot '$snapname' does not exist\n" if !defined($snapshot);
-
-	    $snapshot->{digest} = $conf->{digest}; # keep file digest for API
-
-	    $conf = $snapshot;
-	}
-
-	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};
+	raise_param_exc({ snapshot => "cannot use 'snapshot' parameter with 'current'",
+	                  current => "cannot use 'snapshot' parameter with 'current'"})
+	    if ($param->{snapshot} && $param->{current});
 
-	# hide cloudinit password
-	if ($conf->{cipassword}) {
-	    $conf->{cipassword} = '**********';
+	my $conf;
+	if ($param->{snapshot}) {
+	    $conf = PVE::QemuConfig->load_snapshot_config($param->{vmid}, $param->{snapshot});
+	} else {
+	    $conf = PVE::QemuConfig->load_current_config($param->{vmid}, $param->{current});
 	}
-
+	$conf->{cipassword} = '**********' if $conf->{cipassword};
 	return $conf;
+
     }});
 
 __PACKAGE__->register_method({
-- 
2.20.1




More information about the pve-devel mailing list