[pve-devel] [PATCH qemu-server] add clouinit hotplug feature

Alexandre Derumier aderumier at odiso.com
Sat Mar 6 05:09:42 CET 2021


This add a new cloudinit hotplug feature,

to auto-regenerate the cloudinit drive when cloudinit options are changed.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0ac4fcf..1394545 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -287,7 +287,7 @@ my $confdesc = {
     hotplug => {
         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 completely. Value '1' is an alias for the default 'network,disk,usb'.",
+        description => "Selectively enable hotplug features. This is a comma separated list of hotplug features: 'network', 'disk', 'cpu', 'memory', 'usb' and 'cloudinit'. Use '0' to disable hotplug completely. Value '1' is an alias for the default 'network,disk,usb'.",
         default => 'network,disk,usb',
     },
     reboot => {
@@ -1298,7 +1298,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";
@@ -4438,6 +4438,27 @@ sub vmconfig_hotplug_pending {
 
     my $hotplug_features = parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
 
+    if($hotplug_features->{cloudinit}) {
+
+	my $regenerate_cloudinit = undef;
+	foreach my $opt (keys %{$selection}) {
+	    $regenerate_cloudinit = 1 if $opt =~ m/^(hostname|net(\d+)|ipconfig(\d+)|searchdomain|nameserver|sshkeys|citype|ciuser|cipassword|cicustom)/; 
+	}
+
+	if ($regenerate_cloudinit) {
+
+	    PVE::QemuConfig->foreach_volume($conf, sub {
+		my ($ds, $drive) = @_;
+		if (drive_is_cloudinit($drive)) {
+
+		    $conf->{pending}->{delete}->{$ds} = 1;
+		    $conf->{pending}->{$ds} = print_drive($drive);
+		    $selection->{$ds} = 1;
+		}
+	    });
+	}
+    }
+
     my $cgroup = PVE::QemuServer::CGroup->new($vmid);
     my $pending_delete_hash = PVE::QemuConfig->parse_pending_delete($conf->{pending}->{delete});
     foreach my $opt (sort keys %$pending_delete_hash) {
-- 
2.20.1





More information about the pve-devel mailing list