* [pve-devel] [PATCH qemu-server] add clouinit hotplug feature
@ 2021-03-06 4:09 Alexandre Derumier
0 siblings, 0 replies; only message in thread
From: Alexandre Derumier @ 2021-03-06 4:09 UTC (permalink / raw)
To: pve-devel
This add a new cloudinit hotplug feature,
to auto-regenerate the cloudinit drive when cloudinit options are changed.
Signed-off-by: Alexandre Derumier <aderumier@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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-03-06 4:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-06 4:09 [pve-devel] [PATCH qemu-server] add clouinit hotplug feature Alexandre Derumier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox