public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Yuri Konotopov <ykonotopov@gnome.org>
To: pve-devel@lists.proxmox.com
Cc: Yuri Konotopov <ykonotopov@gnome.org>
Subject: [PATCH qemu-server 1/2] cloud-init: factor out generated file preparation
Date: Sat, 25 Apr 2026 16:31:23 +0400	[thread overview]
Message-ID: <20260425123125.797431-2-ykonotopov@gnome.org> (raw)
In-Reply-To: <20260425123125.797431-1-ykonotopov@gnome.org>

Signed-off-by: Yuri Konotopov <ykonotopov@gnome.org>
---
 src/PVE/QemuServer/Cloudinit.pm | 39 ++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/PVE/QemuServer/Cloudinit.pm b/src/PVE/QemuServer/Cloudinit.pm
index c1311da8..67f83d3a 100644
--- a/src/PVE/QemuServer/Cloudinit.pm
+++ b/src/PVE/QemuServer/Cloudinit.pm
@@ -245,24 +245,25 @@ sub configdrive2_metadata {
 EOF
 }
 
+sub configdrive2_network_generator {
+    my ($conf) = @_;
+
+    return PVE::QemuServer::Helpers::windows_version($conf->{ostype})
+        ? \&cloudbase_network_eni
+        : \&configdrive2_network;
+}
+
 sub generate_configdrive2 {
     my ($conf, $vmid, $drive, $volname, $storeid) = @_;
 
-    my ($user_data, $network_data, $meta_data, $vendor_data) = get_custom_cloudinit_files($conf);
+    my ($user_data, $network_data, $meta_data, $vendor_data) =
+        get_cloudinit_files($conf, $vmid, configdrive2_network_generator($conf));
     if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
-        $user_data = cloudinit_userdata($conf, $vmid) if !defined($user_data);
-        $network_data = cloudbase_network_eni($conf) if !defined($network_data);
-        $vendor_data = '' if !defined($vendor_data);
-
         if (!defined($meta_data)) {
             my $instance_id = cloudbase_gen_instance_id($user_data, $network_data);
             $meta_data = cloudbase_configdrive2_metadata($instance_id, $conf);
         }
     } else {
-        $user_data = cloudinit_userdata($conf, $vmid) if !defined($user_data);
-        $network_data = configdrive2_network($conf) if !defined($network_data);
-        $vendor_data = '' if !defined($vendor_data);
-
         if (!defined($meta_data)) {
             $meta_data = configdrive2_gen_metadata($user_data, $network_data);
         }
@@ -592,10 +593,8 @@ sub nocloud_gen_metadata {
 sub generate_nocloud {
     my ($conf, $vmid, $drive, $volname, $storeid) = @_;
 
-    my ($user_data, $network_data, $meta_data, $vendor_data) = get_custom_cloudinit_files($conf);
-    $user_data = cloudinit_userdata($conf, $vmid) if !defined($user_data);
-    $network_data = nocloud_network($conf) if !defined($network_data);
-    $vendor_data = '' if !defined($vendor_data);
+    my ($user_data, $network_data, $meta_data, $vendor_data) =
+        get_cloudinit_files($conf, $vmid, \&nocloud_network);
 
     if (!defined($meta_data)) {
         $meta_data = nocloud_gen_metadata($user_data, $network_data);
@@ -616,6 +615,20 @@ sub generate_nocloud {
     commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, $files, 'cidata');
 }
 
+sub get_cloudinit_files {
+    my ($conf, $vmid, $network_generator) = @_;
+
+    my ($user_data, $network_data, $meta_data, $vendor_data);
+    if ($conf->{cicustom}) {
+        ($user_data, $network_data, $meta_data, $vendor_data) = get_custom_cloudinit_files($conf);
+    }
+    $user_data = cloudinit_userdata($conf, $vmid) if !defined($user_data);
+    $network_data = $network_generator->($conf) if !defined($network_data);
+    $vendor_data = '' if !defined($vendor_data);
+
+    return ($user_data, $network_data, $meta_data, $vendor_data);
+}
+
 sub get_custom_cloudinit_files {
     my ($conf) = @_;
 
-- 
2.47.3




  reply	other threads:[~2026-04-25 12:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-25 12:31 [PATCH qemu-server/pve-manager 0/3] add ci instance-id mode Yuri Konotopov
2026-04-25 12:31 ` Yuri Konotopov [this message]
2026-04-25 12:31 ` [PATCH qemu-server 2/2] fix #1739: cloud-init: add persistent " Yuri Konotopov
2026-04-25 12:31 ` [PATCH pve-manager] fix #1739: ui: qemu: expose cloud-init " Yuri Konotopov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260425123125.797431-2-ykonotopov@gnome.org \
    --to=ykonotopov@gnome.org \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal