From 94ec5e7c3017614a114879fa804fcc295ee8e687 Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Wed, 22 Jun 2022 13:52:05 +0200 Subject: [PATCH] add cloudinit hotplug This allow to regenerate config drive if pending values exist when we change vm options. Signed-off-by: Alexandre Derumier Reviewed-by: Fiona Ebner --- PVE/QemuServer.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 77e1484..cce8e21 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -297,7 +297,7 @@ my $confdesc = { optional => 1, type => 'string', format => 'pve-hotplug-features', description => "Selectively enable hotplug features. This is a comma separated list of" - ." hotplug features: 'network', 'disk', 'cpu', 'memory' and 'usb'. Use '0' to disable" + ." hotplug features: 'network', 'disk', 'cpu', 'memory', 'usb' and 'cloudinit'. Use '0' to disable" ." hotplug completely. Using '1' as value is an alias for the default `network,disk,usb`.", default => 'network,disk,usb', }, @@ -1350,7 +1350,7 @@ sub parse_hotplug_features { $data = $confdesc->{hotplug}->{default} if $data eq '1'; foreach my $feature (PVE::Tools::split_list($data)) { - if ($feature =~ m/^(network|disk|cpu|memory|usb)$/) { + if ($feature =~ m/^(network|disk|cpu|memory|usb|cloudinit)$/) { $res->{$1} = 1; } else { die "invalid hotplug feature '$feature'\n"; @@ -4987,8 +4987,16 @@ sub vmconfig_hotplug_pending { delete $conf->{pending}->{$opt}; } } - PVE::QemuConfig->write_config($vmid, $conf); + + if($hotplug_features->{cloudinit}) { + my $pending = PVE::QemuServer::Cloudinit::get_pending_config($conf, $vmid); + my $regenerate = undef; + for my $item (@$pending) { + $regenerate = 1 if defined($item->{delete}) or defined($item->{pending}); + } + PVE::QemuServer::vmconfig_update_cloudinit_drive($storecfg, $conf, $vmid) if $regenerate; + } } sub try_deallocate_drive { -- 2.39.2