From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 535147068B for ; Thu, 24 Jun 2021 13:22:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4B1BDA6E1 for ; Thu, 24 Jun 2021 13:22:35 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 475EFA6CE for ; Thu, 24 Jun 2021 13:22:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2B9694678F for ; Thu, 24 Jun 2021 13:14:49 +0200 (CEST) From: Mira Limbeck To: pve-devel@lists.proxmox.com Date: Thu, 24 Jun 2021 13:14:46 +0200 Message-Id: <20210624111446.18800-2-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210624111446.18800-1-m.limbeck@proxmox.com> References: <20210624111446.18800-1-m.limbeck@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.570 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH qemu-server 2/2] cloud-init: add vendor-data X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 11:22:35 -0000 Vendor data can contain the same config options as user data. When user data is supplied that conflicts with vendor data, the user data is chosen instead. This can help in creating a base for multiple VMs with the same vendor data, but different user data for customization. [0] Support for vendor data is implemented via snippets only. [0] https://cloudinit.readthedocs.io/en/latest/topics/vendordata.html Signed-off-by: Mira Limbeck --- PVE/QemuServer.pm | 8 ++++++++ PVE/QemuServer/Cloudinit.pm | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 25282b7..1fe1f5c 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -711,6 +711,14 @@ my $cicustom_fmt = { format => 'pve-volume-id', format_description => 'volume', }, + vendor => { + type => 'string', + optional => 1, + description => 'Specify a custom file containing all vendor data passed to the VM via' + .' cloud-init.', + format => 'pve-volume-id', + format_description => 'volume', + }, }; PVE::JSONSchema::register_format('pve-qm-cicustom', $cicustom_fmt); diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index 1163915..f428995 100644 --- a/PVE/QemuServer/Cloudinit.pm +++ b/PVE/QemuServer/Cloudinit.pm @@ -491,7 +491,7 @@ sub nocloud_gen_metadata { sub generate_nocloud { my ($conf, $vmid, $drive, $volname, $storeid) = @_; - my ($user_data, $network_data, $meta_data) = get_custom_cloudinit_files($conf); + my ($user_data, $vendor_data, $network_data, $meta_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); @@ -499,8 +499,14 @@ sub generate_nocloud { $meta_data = nocloud_gen_metadata($user_data, $network_data); } + # we always allocate a 4MiB disk for cloudinit and with the overhead of the ISO + # make sure we always stay below it by keeping the sum of all files below 3 MiB + my $sum = length($user_data) + length($vendor_data) + length($network_data) + length($meta_data); + die "Cloud-Init sum of snippets too big (> 3 MiB)\n" if $sum > (3 * 1024 * 1024); + my $files = { '/user-data' => $user_data, + '/vendor-data' => $vendor_data, '/network-config' => $network_data, '/meta-data' => $meta_data }; @@ -515,6 +521,7 @@ sub get_custom_cloudinit_files { my $network_volid = $files->{network}; my $user_volid = $files->{user}; + my $vendor_volid = $files->{vendor}; my $meta_volid = $files->{meta}; my $storage_conf = PVE::Storage::config(); @@ -529,12 +536,17 @@ sub get_custom_cloudinit_files { $user_data = read_cloudinit_snippets_file($storage_conf, $user_volid); } + my $vendor_data; + if ($vendor_volid) { + $vendor_data = read_cloudinit_snippets_file($storage_conf, $vendor_volid); + } + my $meta_data; if ($meta_volid) { $meta_data = read_cloudinit_snippets_file($storage_conf, $meta_volid); } - return ($user_data, $network_data, $meta_data); + return ($user_data, $vendor_data, $network_data, $meta_data); } sub read_cloudinit_snippets_file { -- 2.30.2