public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server] fix #2429: allow to specify cloud-init vendor snippet via cicustom
@ 2021-08-12 19:17 Constantin Herold
  2021-08-16 11:46 ` Mira Limbeck
  0 siblings, 1 reply; 3+ messages in thread
From: Constantin Herold @ 2021-08-12 19:17 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Constantin Herold <proxmox8914@herold.me>
---
 PVE/QemuServer.pm           |  8 ++++++++
 PVE/QemuServer/Cloudinit.pm | 18 +++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index cc73af8..90a4496 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -713,6 +713,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 a5474d3..ab5d358 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -227,7 +227,7 @@ EOF
 sub generate_configdrive2 {
     my ($conf, $vmid, $drive, $volname, $storeid) = @_;
 
-    my ($user_data, $network_data, $meta_data) = get_custom_cloudinit_files($conf);
+    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 = configdrive2_network($conf) if !defined($network_data);
 
@@ -237,7 +237,8 @@ sub generate_configdrive2 {
     my $files = {
 	'/openstack/latest/user_data' => $user_data,
 	'/openstack/content/0000' => $network_data,
-	'/openstack/latest/meta_data.json' => $meta_data
+	'/openstack/latest/meta_data.json' => $meta_data,
+	'/openstack/latest/vendor_data.json' => $vendor_data
     };
     commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, $files, 'config-2');
 }
@@ -493,7 +494,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, $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);
 
@@ -504,7 +505,8 @@ sub generate_nocloud {
     my $files = {
 	'/user-data' => $user_data,
 	'/network-config' => $network_data,
-	'/meta-data' => $meta_data
+	'/meta-data' => $meta_data,
+	'/vendor-data' => $vendor_data
     };
     commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, $files, 'cidata');
 }
@@ -518,6 +520,7 @@ sub get_custom_cloudinit_files {
     my $network_volid = $files->{network};
     my $user_volid = $files->{user};
     my $meta_volid = $files->{meta};
+    my $vendor_volid = $files->{vendor};
 
     my $storage_conf = PVE::Storage::config();
 
@@ -536,7 +539,12 @@ sub get_custom_cloudinit_files {
 	$meta_data = read_cloudinit_snippets_file($storage_conf, $meta_volid);
     }
 
-    return ($user_data, $network_data, $meta_data);
+    my $vendor_data;
+    if ($vendor_volid) {
+        $vendor_data = read_cloudinit_snippets_file($storage_conf, $vendor_volid);
+    }
+    
+    return ($user_data, $network_data, $meta_data, $vendor_data);
 }
 
 sub read_cloudinit_snippets_file {
-- 
2.23.0




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] fix #2429: allow to specify cloud-init vendor snippet via cicustom
  2021-08-12 19:17 [pve-devel] [PATCH qemu-server] fix #2429: allow to specify cloud-init vendor snippet via cicustom Constantin Herold
@ 2021-08-16 11:46 ` Mira Limbeck
  2021-08-16 14:50   ` Constantin Herold
  0 siblings, 1 reply; 3+ messages in thread
From: Mira Limbeck @ 2021-08-16 11:46 UTC (permalink / raw)
  To: pve-devel

Thank you for the patch. Sorry that I missed that on friday.

Which distributions and cloud-init versions did you test this on?


The patch looks good to me. One addition I'd make, as we have a hard 
limit of 4MiB currently for the generated ISO, inline.

On 8/12/21 9:17 PM, Constantin Herold wrote:
> Signed-off-by: Constantin Herold <proxmox8914@herold.me>
> ---
>   PVE/QemuServer.pm           |  8 ++++++++
>   PVE/QemuServer/Cloudinit.pm | 18 +++++++++++++-----
>   2 files changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index cc73af8..90a4496 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -713,6 +713,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 a5474d3..ab5d358 100644
> --- a/PVE/QemuServer/Cloudinit.pm
> +++ b/PVE/QemuServer/Cloudinit.pm
> @@ -227,7 +227,7 @@ EOF
>   sub generate_configdrive2 {
>       my ($conf, $vmid, $drive, $volname, $storeid) = @_;
>   
> -    my ($user_data, $network_data, $meta_data) = get_custom_cloudinit_files($conf);
> +    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 = configdrive2_network($conf) if !defined($network_data);
>   
> @@ -237,7 +237,8 @@ sub generate_configdrive2 {

Add a size check for the total amount of bytes to never exceed 3MiB here.

e.g.

+    # 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);

This is taken from my patch sent previously [0].

>       my $files = {
>   	'/openstack/latest/user_data' => $user_data,
>   	'/openstack/content/0000' => $network_data,
> -	'/openstack/latest/meta_data.json' => $meta_data
> +	'/openstack/latest/meta_data.json' => $meta_data,
> +	'/openstack/latest/vendor_data.json' => $vendor_data
>       };
>       commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, $files, 'config-2');
>   }
> @@ -493,7 +494,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, $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);
>   
> @@ -504,7 +505,8 @@ sub generate_nocloud {
>       my $files = {
>   	'/user-data' => $user_data,
>   	'/network-config' => $network_data,
> -	'/meta-data' => $meta_data
> +	'/meta-data' => $meta_data,
> +	'/vendor-data' => $vendor_data
>       };
>       commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, $files, 'cidata');
>   }
> @@ -518,6 +520,7 @@ sub get_custom_cloudinit_files {
>       my $network_volid = $files->{network};
>       my $user_volid = $files->{user};
>       my $meta_volid = $files->{meta};
> +    my $vendor_volid = $files->{vendor};
>   
>       my $storage_conf = PVE::Storage::config();
>   
> @@ -536,7 +539,12 @@ sub get_custom_cloudinit_files {
>   	$meta_data = read_cloudinit_snippets_file($storage_conf, $meta_volid);
>       }
>   
> -    return ($user_data, $network_data, $meta_data);
> +    my $vendor_data;
> +    if ($vendor_volid) {
> +        $vendor_data = read_cloudinit_snippets_file($storage_conf, $vendor_volid);
> +    }
> +
> +    return ($user_data, $network_data, $meta_data, $vendor_data);
>   }
>   
>   sub read_cloudinit_snippets_file {
[0] https://lists.proxmox.com/pipermail/pve-devel/2021-June/049025.html




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] fix #2429: allow to specify cloud-init vendor snippet via cicustom
  2021-08-16 11:46 ` Mira Limbeck
@ 2021-08-16 14:50   ` Constantin Herold
  0 siblings, 0 replies; 3+ messages in thread
From: Constantin Herold @ 2021-08-16 14:50 UTC (permalink / raw)
  To: Mira Limbeck, pve-devel

Just ignore my patch, I did not know that there was already one on 
pve-devel.

I tested both your and mine patch with the generic cloud images from 
debian https://cdimage.debian.org/images/cloud/

Direct link to latest: 
https://cdimage.debian.org/images/cloud/bullseye/daily/latest/debian-11-generic-amd64-daily.qcow2

The bullseye image ships with cloud-init 20.4.1, buster with 20.2


After any of the patches gets merged it would be great to add a example 
to the existing proxmox wiki.

Since the wiki is not in the git repo I can't submit a patch for it.

https://pve.proxmox.com/wiki/Cloud-Init_Support

##Bootstrap Cloud-Init Image##

A vendor config can be used to bootstrap cloud-init images.

For example to install qemu-guest-agent on debian/ubuntu distros after the vm has been deployed create the following snippet.

Note that the vendor config is executed on first boot only !


qm set 9000 --cicustom "vendor=local:snippets/vendor.yaml"

/var/lib/vz/snippets/vendor.yaml:
#cloud-config
runcmd:
     - apt update
     - apt install -y qemu-guest-agent
     - systemctl start qemu-guest-agent

Am 16.08.2021 um 13:46 schrieb Mira Limbeck:
> Thank you for the patch. Sorry that I missed that on friday.
>
> Which distributions and cloud-init versions did you test this on?
>
>
> The patch looks good to me. One addition I'd make, as we have a hard 
> limit of 4MiB currently for the generated ISO, inline.
>
> On 8/12/21 9:17 PM, Constantin Herold wrote:
>> Signed-off-by: Constantin Herold <proxmox8914@herold.me>
>> ---
>>   PVE/QemuServer.pm           |  8 ++++++++
>>   PVE/QemuServer/Cloudinit.pm | 18 +++++++++++++-----
>>   2 files changed, 21 insertions(+), 5 deletions(-)
>>
>> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
>> index cc73af8..90a4496 100644
>> --- a/PVE/QemuServer.pm
>> +++ b/PVE/QemuServer.pm
>> @@ -713,6 +713,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 a5474d3..ab5d358 100644
>> --- a/PVE/QemuServer/Cloudinit.pm
>> +++ b/PVE/QemuServer/Cloudinit.pm
>> @@ -227,7 +227,7 @@ EOF
>>   sub generate_configdrive2 {
>>       my ($conf, $vmid, $drive, $volname, $storeid) = @_;
>>   -    my ($user_data, $network_data, $meta_data) = 
>> get_custom_cloudinit_files($conf);
>> +    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 = configdrive2_network($conf) if 
>> !defined($network_data);
>>   @@ -237,7 +237,8 @@ sub generate_configdrive2 {
>
> Add a size check for the total amount of bytes to never exceed 3MiB here.
>
> e.g.
>
> +    # 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);
>
> This is taken from my patch sent previously [0].
>
>>       my $files = {
>>       '/openstack/latest/user_data' => $user_data,
>>       '/openstack/content/0000' => $network_data,
>> -    '/openstack/latest/meta_data.json' => $meta_data
>> +    '/openstack/latest/meta_data.json' => $meta_data,
>> +    '/openstack/latest/vendor_data.json' => $vendor_data
>>       };
>>       commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, 
>> $files, 'config-2');
>>   }
>> @@ -493,7 +494,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, $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);
>>   @@ -504,7 +505,8 @@ sub generate_nocloud {
>>       my $files = {
>>       '/user-data' => $user_data,
>>       '/network-config' => $network_data,
>> -    '/meta-data' => $meta_data
>> +    '/meta-data' => $meta_data,
>> +    '/vendor-data' => $vendor_data
>>       };
>>       commit_cloudinit_disk($conf, $vmid, $drive, $volname, $storeid, 
>> $files, 'cidata');
>>   }
>> @@ -518,6 +520,7 @@ sub get_custom_cloudinit_files {
>>       my $network_volid = $files->{network};
>>       my $user_volid = $files->{user};
>>       my $meta_volid = $files->{meta};
>> +    my $vendor_volid = $files->{vendor};
>>         my $storage_conf = PVE::Storage::config();
>>   @@ -536,7 +539,12 @@ sub get_custom_cloudinit_files {
>>       $meta_data = read_cloudinit_snippets_file($storage_conf, 
>> $meta_volid);
>>       }
>>   -    return ($user_data, $network_data, $meta_data);
>> +    my $vendor_data;
>> +    if ($vendor_volid) {
>> +        $vendor_data = read_cloudinit_snippets_file($storage_conf, 
>> $vendor_volid);
>> +    }
>> +
>> +    return ($user_data, $network_data, $meta_data, $vendor_data);
>>   }
>>     sub read_cloudinit_snippets_file {
> [0] https://lists.proxmox.com/pipermail/pve-devel/2021-June/049025.html
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-16 14:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 19:17 [pve-devel] [PATCH qemu-server] fix #2429: allow to specify cloud-init vendor snippet via cicustom Constantin Herold
2021-08-16 11:46 ` Mira Limbeck
2021-08-16 14:50   ` Constantin Herold

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