]> git.proxmox.com Git - pve-guest-common.git/commitdiff
helpers: add method to represent config as a table
authorOguz Bektas <o.bektas@proxmox.com>
Mon, 14 Oct 2019 08:28:36 +0000 (10:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 15:48:03 +0000 (17:48 +0200)
in vm_pending API, this method is used to represent the configuration as
a table with current, pending and delete columns.

by adding it as a guesthelper, we can also use it for container pending
changes.

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

index a36b9bc66b6a29969873a63c88db238acc107081..a1ec76f50f7bba165e546266669776fc7a5ed8cb 100644 (file)
@@ -142,4 +142,39 @@ sub format_pending {
     }
 }
 
+sub conf_table_with_pending {
+    my ($conf, $pending_delete_hash) = @_;
+
+    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}->{force} ? 2 : 1) if exists $pending_delete_hash->{$opt};
+
+       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};
+
+       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;
+}
+
 1;