mirror of
https://git.proxmox.com/git/pve-guest-common
synced 2025-08-16 10:15:34 +00:00
refactor config_with_pending_array
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
43c899e407
commit
daf8fca57a
@ -82,7 +82,6 @@ sub parse_pending_delete {
|
|||||||
my $pending_deletions = {};
|
my $pending_deletions = {};
|
||||||
for my $entry (split(/\s+/, $data)) {
|
for my $entry (split(/\s+/, $data)) {
|
||||||
my ($force, $key) = $entry =~ /^(!?)(.*)$/;
|
my ($force, $key) = $entry =~ /^(!?)(.*)$/;
|
||||||
|
|
||||||
$pending_deletions->{$key} = {
|
$pending_deletions->{$key} = {
|
||||||
force => $force ? 1 : 0,
|
force => $force ? 1 : 0,
|
||||||
};
|
};
|
||||||
|
@ -201,40 +201,43 @@ sub format_pending {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# returns the config as an array of hashes, each hash can have the following keys:
|
# returns the config as an array of hashes, each hash can have the following keys:
|
||||||
# key (the config property name, non-optional)
|
# key: the config property name, non-optional
|
||||||
# value (the current value in effect - if any)
|
# value: the current value in effect - if any
|
||||||
# pending (a new, still pending, value - if any)
|
# pending: a new, still pending, value - if any
|
||||||
# delete (when deletions are pending, this is set to either 2 (force) or 1 (graceful))
|
# delete: when deletions are pending, this is set to either 2 (force) or 1 (graceful)
|
||||||
sub config_with_pending_array {
|
sub config_with_pending_array {
|
||||||
my ($conf, $pending_delete_hash) = @_;
|
my ($conf, $pending_delete_hash) = @_;
|
||||||
|
|
||||||
my $res = [];
|
my $pending = delete $conf->{pending};
|
||||||
|
# we don't care for snapshots in pending and it makes our loops throw up
|
||||||
|
delete $conf->{snapshots};
|
||||||
|
|
||||||
|
my $res = [];
|
||||||
foreach my $opt (keys %$conf) {
|
foreach my $opt (keys %$conf) {
|
||||||
next if ref($conf->{$opt});
|
my $item = {
|
||||||
my $item = { key => $opt };
|
key => $opt,
|
||||||
$item->{value} = $conf->{$opt} if defined($conf->{$opt});
|
value => $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};
|
$item->{pending} = delete $pending->{$opt} if defined($conf->{pending}->{$opt});
|
||||||
|
my $delete = delete $pending_delete_hash->{$opt};
|
||||||
|
$item->{delete} = $delete->{force} ? 2 : 1 if defined($delete);
|
||||||
|
|
||||||
push @$res, $item;
|
push @$res, $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $opt (keys %{$conf->{pending}}) {
|
foreach my $opt (keys %$pending) {
|
||||||
next if $opt eq 'delete';
|
next if $opt eq 'delete';
|
||||||
next if ref($conf->{pending}->{$opt}); # just to be sure
|
push @$res, {
|
||||||
next if defined($conf->{$opt});
|
key => $opt,
|
||||||
my $item = { key => $opt };
|
pending => $pending->{$opt},
|
||||||
$item->{pending} = $conf->{pending}->{$opt};
|
};
|
||||||
|
|
||||||
push @$res, $item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (my ($opt, $force) = each %$pending_delete_hash) {
|
while (my ($opt, $force) = each %$pending_delete_hash) {
|
||||||
next if defined($conf->{pending}->{$opt});
|
push @$res, {
|
||||||
next if defined($conf->{$opt});
|
key => $opt,
|
||||||
my $item = { key => $opt, delete => ($force ? 2 : 1)};
|
delete => $force ? 2 : 1,
|
||||||
push @$res, $item;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
|
Loading…
Reference in New Issue
Block a user