public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, aderumier@odiso.com
Subject: Re: [pve-devel] [PATCH v6 qemu-server 7/9] api2: add cloudinit config api
Date: Tue, 21 Jun 2022 13:45:06 +0200	[thread overview]
Message-ID: <652b4a40-031a-e3de-33de-1035de61c05a@proxmox.com> (raw)
In-Reply-To: <20220620104502.1239272-8-aderumier@odiso.com>

Am 20.06.22 um 12:45 schrieb Alexandre Derumier:
> diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
> index cdaf4e5..2355953 100644
> --- a/PVE/QemuServer/Cloudinit.pm
> +++ b/PVE/QemuServer/Cloudinit.pm
> @@ -632,4 +633,81 @@ sub dump_cloudinit_config {
>      }
>  }
>  
> +sub get_pending_config {
> +    my ($conf, $vmid) = @_;
> +
> +    my $newconf = dclone($conf);
> +
> +    my $cloudinit_current = $newconf->{cloudinit};
> +    my @cloudinit_opts = keys %{PVE::QemuServer::cloudinit_config_properties()};
> +    push @cloudinit_opts, 'name';
> +
> +    #add cloud-init drive
> +    my $drives = {};
> +    PVE::QemuConfig->foreach_volume($newconf, sub {
> +	my ($ds, $drive) = @_;
> +	$drives->{$ds} = 1 if PVE::QemuServer::drive_is_cloudinit($drive);
> +    });
> +
> +    PVE::QemuConfig->foreach_volume($cloudinit_current, sub {
> +	my ($ds, $drive) = @_;
> +	$drives->{$ds} = 1 if PVE::QemuServer::drive_is_cloudinit($drive);
> +    });
> +    foreach my $ds (keys %{$drives}) {

Style nit: please use for

> +	push @cloudinit_opts, $ds;
> +    }
> +
> +    $newconf->{name} = "VM$vmid" if !$newconf->{name};
> +    $cloudinit_current->{name} = "VM$vmid" if !$cloudinit_current->{name};
> +
> +    #only mac-address is used in cloud-init config. 

Style nit: trailing whitespace

> +    #We don't want to display other pending net changes.
> +    my $print_cloudinit_net = sub {
> +	my ($conf, $opt) = @_;
> +
> +	if (defined($conf->{$opt})) {
> +	    my $net = PVE::QemuServer::parse_net($conf->{$opt});
> +	    $conf->{$opt} = "macaddr=".$net->{macaddr} if $net->{macaddr};
> +	}
> +    };
> +
> +    my $cloudinit_options = {};
> +    for my $opt (@cloudinit_opts) {
> +	if ($opt =~ m/^ipconfig(\d+)/) {
> +	    my $netid = "net$1";
> + 

Style nit: trailing whitespace

> +	    next if !defined($newconf->{$netid}) && !defined($cloudinit_current->{$netid}) &&
> +		    !defined($newconf->{$opt}) && !defined($cloudinit_current->{$opt});
> +
> +	    &$print_cloudinit_net($newconf, $netid);
> +	    &$print_cloudinit_net($cloudinit_current, $netid);
> +	    $cloudinit_options->{$netid} = 1;
> +	}
> +	$cloudinit_options->{$opt} = 1;
> +    }
> +
> +    my $res = [];
> +
> +    for my $opt (keys %{$cloudinit_options}) {
> +
> +	my $item = {
> +	    key => $opt,
> +	};
> +	if ($cloudinit_current->{$opt}) {
> +	    $item->{value} = $cloudinit_current->{$opt};
> +	    if (defined($newconf->{$opt})) {
> +		$item->{pending} = $newconf->{$opt} if $newconf->{$opt} ne $cloudinit_current->{$opt};

Style nit: line too long

> +	    } else {
> +		$item->{delete} = 1;
> +	    }
> +	} else {
> +	    $item->{pending} = $newconf->{$opt} if $newconf->{$opt}
> +	}
> +
> +	push @$res, $item;
> +   }
> +
> +   return $res;
> +}
> +
>  1;




  reply	other threads:[~2022-06-21 11:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 10:44 [pve-devel] [PATCH v6 qemu-server 0/9] cloudinit pending behaviour change Alexandre Derumier
2022-06-20 10:44 ` [pve-devel] [PATCH v6 qemu-server 1/9] qemuconfig: load_current_config : delete cloudinit value Alexandre Derumier
2022-06-20 10:44 ` [pve-devel] [PATCH v6 qemu-server 2/9] vzdump : skip special:cloudinit section Alexandre Derumier
2022-06-20 10:44 ` [pve-devel] [PATCH v6 qemu-server 3/9] migration: test targetnode min version for cloudinit section Alexandre Derumier
2022-06-21 11:45   ` Fabian Ebner
2022-06-20 10:44 ` [pve-devel] [PATCH v6 qemu-server 4/9] cloudinit: add cloudinit section for current generated config Alexandre Derumier
2022-06-21 11:45   ` Fabian Ebner
2022-06-20 10:44 ` [pve-devel] [PATCH v6 qemu-server 5/9] generate cloudinit drive on offline plug Alexandre Derumier
2022-06-20 10:44 ` [pve-devel] [PATCH v6 qemu-server 6/9] cloudinit: make cloudnit options fastplug Alexandre Derumier
2022-06-20 10:45 ` [pve-devel] [PATCH v6 qemu-server 7/9] api2: add cloudinit config api Alexandre Derumier
2022-06-21 11:45   ` Fabian Ebner [this message]
2022-06-20 10:45 ` [pve-devel] [PATCH v6 qemu-server 8/9] api2: add cloudinit_update Alexandre Derumier
2022-06-20 10:45 ` [pve-devel] [PATCH v6 qemu-server 9/9] add cloudinit hotplug Alexandre Derumier
2022-06-21 11:44 ` [pve-devel] [PATCH v6 qemu-server 0/9] cloudinit pending behaviour change Fabian Ebner

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=652b4a40-031a-e3de-33de-1035de61c05a@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=aderumier@odiso.com \
    --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