[pve-devel] [PATCH v3 qemu-server 1/7] cloudinit: add vm config to cloudinit drive

Fabian Ebner f.ebner at proxmox.com
Thu Mar 31 15:01:15 CEST 2022


Am 09.06.21 um 13:54 schrieb Alexandre Derumier:
> To have current running cloudinit config.
> 
> An improvement could be to implement parsing of config drive format,
> and also compare cicustom snippets content
> 
> Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
> ---
>  PVE/QemuServer/Cloudinit.pm | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
> index a5474d3..abc62b7 100644
> --- a/PVE/QemuServer/Cloudinit.pm
> +++ b/PVE/QemuServer/Cloudinit.pm
> @@ -19,6 +19,7 @@ sub commit_cloudinit_disk {
>  
>      my $path = "/run/pve/cloudinit/$vmid/";
>      mkpath $path;
> +
>      foreach my $filepath (keys %$files) {
>  	if ($filepath !~ m@^(.*)\/[^/]+$@) {
>  	    die "internal error: bad file name in cloud-init image: $filepath\n";
> @@ -30,6 +31,15 @@ sub commit_cloudinit_disk {
>  	file_set_contents("$path/$filepath", $contents);
>      }
>  
> +    mkpath "$path/proxmox";
> +    my $confcontent = "";
> +    foreach my $opt (keys %$conf) {
> +	next if $opt =~ m/^(pending|snapshots|digest)$/;
> +	$confcontent .= "$opt: $conf->{$opt}\n";
> +    }

For consistency, I'd use write_vm_config() (after dclone() and removing
the snapshots, pending) to generate the contents of the file.

> +
> +    file_set_contents("$path/proxmox/vmconf", $confcontent);
> +
>      my $storecfg = PVE::Storage::config();
>      my $iso_path = PVE::Storage::path($storecfg, $drive->{file});
>      my $scfg = PVE::Storage::storage_config($storecfg, $storeid);





More information about the pve-devel mailing list