[pve-devel] [PATCH v6 11/22] vmconfig_cleanup_pending: new method to clenup setting in [PENDING]
Dietmar Maurer
dietmar at proxmox.com
Tue Nov 25 12:24:18 CET 2014
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
PVE/API2/Qemu.pm | 8 +-------
PVE/QemuServer.pm | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index a8841c2..8c7c076 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1006,14 +1006,8 @@ my $update_vm_api = sub {
}
# remove pending changes when nothing changed
- my $changes;
$conf = PVE::QemuServer::load_config($vmid); # update/reload
- foreach my $opt (keys %{$conf->{pending}}) { # add/change
- if (defined($conf->{$opt}) && ($conf->{pending}->{$opt} eq $conf->{$opt})) {
- $changes = 1;
- delete $conf->{pending}->{$opt};
- }
- }
+ my $changes = PVE::QemuServer::vmconfig_cleanup_pending($conf);
PVE::QemuServer::update_config_nolock($vmid, $conf, 1) if $changes;
return if !scalar(keys %{$conf->{pending}});
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 7219353..2644117 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1442,6 +1442,38 @@ sub vmconfig_register_unused_drive {
}
}
+sub vmconfig_cleanup_pending {
+ my ($conf) = @_;
+
+ # remove pending changes when nothing changed
+ my $changes;
+ foreach my $opt (keys %{$conf->{pending}}) {
+ if (defined($conf->{$opt}) && ($conf->{pending}->{$opt} eq $conf->{$opt})) {
+ $changes = 1;
+ delete $conf->{pending}->{$opt};
+ }
+ }
+
+ # remove delete if option is not set
+ my $pending_delete_hash = {};
+ foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
+ if (defined($conf->{$opt})) {
+ $pending_delete_hash->{$opt} = 1;
+ } else {
+ $changes = 1;
+ }
+ }
+
+ my @keylist = keys %$pending_delete_hash;
+ if (scalar(@keylist)) {
+ $conf->{pending}->{delete} = join(',', @keylist);
+ } else {
+ delete $conf->{pending}->{delete};
+ }
+
+ return $changes;
+}
+
my $valid_smbios1_options = {
manufacturer => '\S+',
product => '\S+',
--
1.7.10.4
More information about the pve-devel
mailing list