]> git.proxmox.com Git - pve-container.git/commitdiff
adapt CT config parser for pending changes
authorOguz Bektas <o.bektas@proxmox.com>
Mon, 14 Oct 2019 08:28:41 +0000 (10:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 18:39:07 +0000 (20:39 +0200)
config parser can now read/write [pve:pending] section. this was named
such, instead of [PENDING], after on- and offline discussion regarding
namespacing the pending section and snapshots.

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
src/PVE/LXC/Config.pm

index 44330daea6c7776f9a92b62fe7ec24cab625ad2b..91c1d816918bab11379cacc54f8cc3d68261b5f0 100644 (file)
@@ -751,6 +751,7 @@ sub parse_pct_config {
     my $res = {
        digest => Digest::SHA::sha1_hex($raw),
        snapshots => {},
+       pending => {},
     };
 
     $filename =~ m|/lxc/(\d+).conf$|
@@ -766,7 +767,13 @@ sub parse_pct_config {
     foreach my $line (@lines) {
        next if $line =~ m/^\s*$/;
 
-       if ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
+       if ($line =~ m/^\[pve:pending\]\s*$/i) {
+           $section = 'pending';
+           $conf->{description} = $descr if $descr;
+           $descr = '';
+           $conf = $res->{$section} = {};
+           next;
+       } elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
            $section = $1;
            $conf->{description} = $descr if $descr;
            $descr = '';
@@ -794,6 +801,13 @@ sub parse_pct_config {
            $descr .= PVE::Tools::decode_text($2);
        } elsif ($line =~ m/snapstate:\s*(prepare|delete)\s*$/) {
            $conf->{snapstate} = $1;
+       } elsif ($line =~ m/^delete:\s*(.*\S)\s*$/) {
+           my $value = $1;
+           if ($section eq 'pending') {
+               $conf->{delete} = $value;
+           } else {
+               warn "vm $vmid - property 'delete' is only allowed in [pve:pending]\n";
+           }
        } elsif ($line =~ m/^([a-z][a-z_]*\d*):\s*(\S.*)\s*$/) {
            my $key = $1;
            my $value = $2;
@@ -839,7 +853,7 @@ sub write_pct_config {
        # add description as comment to top of file
        my $descr = $conf->{description} || '';
        foreach my $cl (split(/\n/, $descr)) {
-           $raw .= '#' .  PVE::Tools::encode_text($cl) . "\n";
+           $raw .= '#' . PVE::Tools::encode_text($cl) . "\n";
        }
 
        foreach my $key (sort keys %$conf) {
@@ -864,6 +878,11 @@ sub write_pct_config {
 
     my $raw = &$generate_raw_config($conf);
 
+    if (scalar(keys %{$conf->{pending}})){
+       $raw .= "\n[pve: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});