[pve-devel] [PATCH v3 4/9] write_vm_config : write pending change

Dietmar Maurer dietmar at proxmox.com
Mon Nov 17 10:47:20 CET 2014


example:

$conf->{pending}->{virtio1}
$conf->{pending}->{delete} = "net0,net1"

[PENDING]
virtio1: ...
delete: net0,net1

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/QemuServer.pm |   32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a83c971..26b0efc 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1826,10 +1826,12 @@ sub parse_vm_config {
 	    my $key = $1;
 	    my $value = $2;
 	    $conf->{$key} = $value;
-	} elsif (($section eq 'pending') && ($line =~ m/^delete:\s*(.*\S)\s*$/)) {
+	} elsif ($line =~ m/^delete:\s*(.*\S)\s*$/) {
 	    my $value = $1;
-	    foreach my $opt (split(/,/, $value)) {
-		$conf->{del}->{$opt} = 1;
+	    if ($section eq 'pending') {
+		$conf->{delete} = $value; # we parse this later
+	    } else {
+		warn "vm $vmid - propertry 'delete' is only allowed in [PENDING]\n";
 	    }
 	} elsif ($line =~ m/^([a-z][a-z_]*\d*):\s*(\S+)\s*$/) {
 	    my $key = $1;
@@ -1893,12 +1895,18 @@ sub write_vm_config {
     my $used_volids = {};
 
     my $cleanup_config = sub {
-	my ($cref, $snapname) = @_;
+	my ($cref, $pending, $snapname) = @_;
 
 	foreach my $key (keys %$cref) {
 	    next if $key eq 'digest' || $key eq 'description' || $key eq 'snapshots' ||
-		$key eq 'snapstate';
+		$key eq 'snapstate' || $key eq 'pending';
 	    my $value = $cref->{$key};
+	    if ($key eq 'delete') {
+		die "propertry 'delete' is only allowed in [PENDING]\n"
+		    if !$pending;
+		# fixme: check syntax?
+		next;
+	    }
 	    eval { $value = check_type($key, $value); };
 	    die "unable to parse value of '$key' - $@" if $@;
 
@@ -1912,8 +1920,12 @@ sub write_vm_config {
     };
 
     &$cleanup_config($conf);
+
+    &$cleanup_config($conf->{pending}, 1);
+
     foreach my $snapname (keys %{$conf->{snapshots}}) {
-	&$cleanup_config($conf->{snapshots}->{$snapname}, $snapname);
+	die "internal error" if $snapname eq 'pending';
+	&$cleanup_config($conf->{snapshots}->{$snapname}, undef, $snapname);
     }
 
     # remove 'unusedX' settings if we re-add a volume
@@ -1936,13 +1948,19 @@ sub write_vm_config {
 	}
 
 	foreach my $key (sort keys %$conf) {
-	    next if $key eq 'digest' || $key eq 'description' || $key eq 'snapshots';
+	    next if $key eq 'digest' || $key eq 'description' || $key eq 'pending' || $key eq 'snapshots';
 	    $raw .= "$key: $conf->{$key}\n";
 	}
 	return $raw;
     };
 
     my $raw = &$generate_raw_config($conf);
+    
+    if (scalar(keys %{$conf->{pending}})){
+	$raw .= "\n[PENDING]\n";
+	$raw .= &$generate_raw_config($conf->{pending});
+    }
+ 
     foreach my $snapname (sort keys %{$conf->{snapshots}}) {
 	$raw .= "\n[$snapname]\n";
 	$raw .= &$generate_raw_config($conf->{snapshots}->{$snapname});
-- 
1.7.10.4




More information about the pve-devel mailing list