[pve-devel] [PATCH 02/12] write_vm_config : write pending change

Alexandre Derumier aderumier at odiso.com
Thu Oct 30 13:40:23 CET 2014


example:

$conf->{pending}->{virtio1}
$conf->{pending}->{del}->{net0}
$conf->{pending}->{del}->{net1}

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

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 3c70ac1..4916b8f 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1863,8 +1863,8 @@ sub parse_vm_config {
     return $res;
 }
 
-sub write_vm_config {
-    my ($filename, $conf) = @_;
+sub write_vm_config_cleanup {
+    my ($conf) = @_;
 
     delete $conf->{snapstate}; # just to be sure
 
@@ -1894,7 +1894,17 @@ sub write_vm_config {
 
 	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' || $key eq 'delete';
+
+	    if($key eq 'del'){
+		my $delete = [];
+		foreach my $deleteoption (keys %{$conf->{del}}) {
+		     push @$delete, $deleteoption;
+		}
+		delete $conf->{delete};
+		$conf->{delete} = join(",", @$delete) if scalar(@$delete);
+		next;
+	    }
 	    my $value = $cref->{$key};
 	    eval { $value = check_type($key, $value); };
 	    die "unable to parse value of '$key' - $@" if $@;
@@ -1921,6 +1931,14 @@ sub write_vm_config {
 	}
     }
 
+}
+
+sub write_vm_config {
+    my ($filename, $conf) = @_;
+
+    write_vm_config_cleanup($conf);
+    write_vm_config_cleanup($conf->{pending});
+
     my $generate_raw_config = sub {
 	my ($conf) = @_;
 
@@ -1933,18 +1951,25 @@ 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 'snapshots' || $key eq 'pending' || $key eq 'del';
 	    $raw .= "$key: $conf->{$key}\n";
 	}
 	return $raw;
     };
 
     my $raw = &$generate_raw_config($conf);
+
+    if(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});
     }
 
+
     return $raw;
 }
 
-- 
1.7.10.4




More information about the pve-devel mailing list