[pve-devel] [PATCH v3 qemu-server 08/19] api: use guesthelper method for vm_pending path

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


we can use the shared conf_table_with_pending guesthelper to produce the
config table with the extra delete and pending columns.

Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 PVE/API2/Qemu.pm | 44 ++++----------------------------------------
 1 file changed, 4 insertions(+), 40 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index b18ed8b..6ebcf4a 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -933,47 +933,11 @@ __PACKAGE__->register_method({
 
 	my $pending_delete_hash = PVE::QemuConfig->parse_pending_delete($conf->{pending}->{delete});
 
-	my $res = [];
-
-	foreach my $opt (keys %$conf) {
-	    next if ref($conf->{$opt});
-	    my $item = { key => $opt };
-	    $item->{value} = $conf->{$opt} if defined($conf->{$opt});
-	    $item->{pending} = $conf->{pending}->{$opt} if defined($conf->{pending}->{$opt});
-	    $item->{delete} = ($pending_delete_hash->{$opt} ? 2 : 1) if exists $pending_delete_hash->{$opt};
-
-	    # hide cloudinit password
-	    if ($opt eq 'cipassword') {
-		$item->{value} = '**********' if defined($item->{value});
-		# the trailing space so that the pending string is different
-		$item->{pending} = '********** ' if defined($item->{pending});
-	    }
-	    push @$res, $item;
-	}
-
-	foreach my $opt (keys %{$conf->{pending}}) {
-	    next if $opt eq 'delete';
-	    next if ref($conf->{pending}->{$opt}); # just to be sure
-	    next if defined($conf->{$opt});
-	    my $item = { key => $opt };
-	    $item->{pending} = $conf->{pending}->{$opt};
+	$conf->{cipassword} = '**********' if defined($conf->{cipassword});
+	$conf->{pending}->{cipassword} = '********** ' if defined($conf->{pending}->{cipassword});
 
-	    # hide cloudinit password
-	    if ($opt eq 'cipassword') {
-		$item->{pending} = '**********' if defined($item->{pending});
-	    }
-	    push @$res, $item;
-	}
-
-	while (my ($opt, $force) = each %$pending_delete_hash) {
-	    next if $conf->{pending}->{$opt}; # just to be sure
-	    next if $conf->{$opt};
-	    my $item = { key => $opt, delete => ($force ? 2 : 1)};
-	    push @$res, $item;
-	}
-
-	return $res;
-    }});
+	return PVE::GuestHelpers::conf_table_with_pending($conf, $pending_delete_hash);
+   }});
 
 # POST/PUT {vmid}/config implementation
 #
-- 
2.20.1




More information about the pve-devel mailing list