[pve-devel] [PATCH v3 qemu-server] adapt /config and /pending API calls to force-delete

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Aug 18 09:36:09 CEST 2015


---
 Changes: min/max (0/2) for delete, improved description
 PVE/API2/Qemu.pm | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 2d8dbbd..d4fb353 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -676,7 +676,8 @@ __PACKAGE__->register_method({
 		next if ref($value); # just to be sure
 		$conf->{$opt} = $value;
 	    }
-	    foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
+	    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};
 	    }
 	}
@@ -722,8 +723,11 @@ __PACKAGE__->register_method({
 		    optional => 1,
 		},
 		delete => {
-		    description => "Indicated a pending delete request.",
-		    type => 'boolean',
+		    description => "Indicates a pending delete request if present and not 0. " .
+		                   "The value 2 indicates a force-delete request.",
+		    type => 'integer',
+		    minimum => 0,
+		    maximum => 2,
 		    optional => 1,
 		},
 	    },
@@ -734,10 +738,7 @@ __PACKAGE__->register_method({
 
 	my $conf = PVE::QemuServer::load_config($param->{vmid});
 
-	my $pending_delete_hash = {};
-	foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
-	    $pending_delete_hash->{$opt} = 1;
-	}
+	my $pending_delete_hash = PVE::QemuServer::split_flagged_list($conf->{pending}->{delete});
 
 	my $res = [];
 
@@ -746,7 +747,7 @@ __PACKAGE__->register_method({
 	    my $item = { key => $opt };
 	    $item->{value} = $conf->{$opt} if defined($conf->{$opt});
 	    $item->{pending} = $conf->{pending}->{$opt} if defined($conf->{pending}->{$opt});
-	    $item->{delete} = 1 if $pending_delete_hash->{$opt};
+	    $item->{delete} = ($pending_delete_hash->{$opt} ? 2 : 1) if exists $pending_delete_hash->{$opt};
 	    push @$res, $item;
 	}
 
@@ -759,10 +760,10 @@ __PACKAGE__->register_method({
 	    push @$res, $item;
 	}
 
-	foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
+	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 => 1};
+	    my $item = { key => $opt, delete => ($force ? 2 : 1)};
 	    push @$res, $item;
 	}
 
-- 
2.1.4





More information about the pve-devel mailing list