allows partial fast plugging of functions as defined in the
$partial_fast_plug_option in qemuserver (and possibly lxc later on)

Signed-off-by: Oguz Bektas <o.bek...@proxmox.com>
---
 PVE/AbstractConfig.pm | 44 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
index b63a744..102b12d 100644
--- a/PVE/AbstractConfig.pm
+++ b/PVE/AbstractConfig.pm
@@ -168,6 +168,50 @@ sub cleanup_pending {
     return $changes;
 }
 
+sub get_partial_fast_plug_map {
+    my ($class) = @_;
+
+    die "abstract method - implement me ";
+}
+
+sub partial_fast_plug {
+    my ($class, $conf, $opt) = @_;
+
+    my $partial_fast_plug_option = $class->get_partial_fast_plug_map();
+    my $format = $partial_fast_plug_option->{$opt}->{fmt};
+    my $fast_pluggable = $partial_fast_plug_option->{$opt}->{properties};
+
+    my $old = {};
+    if (exists($conf->{$opt})) {
+       $old = PVE::JSONSchema::parse_property_string($format, $conf->{$opt});
+    }
+    my $new = PVE::JSONSchema::parse_property_string($format, 
$conf->{pending}->{$opt});
+
+    my $changes_left = 0;
+
+    # merge old and new opts to iterate
+    my @all_keys = keys %{{ %$new, %$old }};
+
+    foreach my $subopt (@all_keys) {
+       my $type = $format->{$subopt}->{type};
+       if (PVE::GuestHelpers::typesafe_ne($old->{$subopt}, $new->{$subopt}, 
$type)) {
+           if ($fast_pluggable->{$subopt}) {
+               $old->{$subopt} = $new->{$subopt};
+           } else {
+               $changes_left = 1;
+           }
+       }
+    }
+
+    # fastplug
+    if (keys %$old) {
+       $conf->{$opt} = PVE::JSONSchema::print_property_string($old, $format);
+    }
+
+    return $changes_left;
+}
+
+
 sub load_snapshot_config {
     my ($class, $vmid, $snapname) = @_;
 
-- 
2.20.1

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to