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 B3D498DD7 for ; Wed, 16 Nov 2022 18:14:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 94494232A6 for ; Wed, 16 Nov 2022 18:14:12 +0100 (CET) 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 for ; Wed, 16 Nov 2022 18:14:11 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 45A9544D72; Wed, 16 Nov 2022 18:14:10 +0100 (CET) From: Wolfgang Bumiller To: pve-devel@lists.proxmox.com Date: Wed, 16 Nov 2022 18:14:08 +0100 Message-Id: <20221116171408.216775-7-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221116171408.216775-1-w.bumiller@proxmox.com> References: <20221116171408.216775-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL 0.231 Adjusted score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=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 =?UTF-8?Q?Alignment=0A=09?=SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF =?UTF-8?Q?record=0A=09?=TVD_PH_BODY_ACCOUNTS_PRE 0.001 The body matches phrases such as "accounts suspended", "account credited", "account verification" URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [cloudinit.pm, qemu.pm] Subject: [pve-devel] [PATCH qemu-server 6/6] drop get_pending_changes and simplify cloudinit_pending api call 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: Wed, 16 Nov 2022 17:14:12 -0000 - The forced-remove flag wasn't really used AFAICT and makes no sense IMO. - Whether or not we care about non-MAC changes does not belong here, but should instead taken into account in the actual hotplug path recording the cloud-init state (iow. into $cloudinit_record_changed().) (This is not done here atm.) - It seems much simpler to just have: * 'old' = the old value if it's not a new value * 'new' = the new value unless it's being deleted * If only one of them is set it's an addition or removal. Signed-off-by: Wolfgang Bumiller --- PVE/API2/Qemu.pm | 44 +++++++++++---------- PVE/QemuServer/Cloudinit.pm | 78 ------------------------------------- 2 files changed, 24 insertions(+), 98 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 30348e6..edb495b 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1338,24 +1338,16 @@ __PACKAGE__->register_method({ description => "Configuration option name.", type => 'string', }, - value => { - description => "Current value.", + old => { + description => "Value as it was used to generate the current cloudinit image.", type => 'string', optional => 1, }, - pending => { - description => "Pending value.", + new => { + description => "The new pending value.", type => 'string', optional => 1, }, - delete => { - description => "Indicates a pending delete request if present and not 0. " . - "The value 2 indicates a force-delete request.", - type => 'integer', - minimum => 0, - maximum => 2, - optional => 1, - }, }, }, }, @@ -1365,17 +1357,29 @@ __PACKAGE__->register_method({ my $vmid = $param->{vmid}; my $conf = PVE::QemuConfig->load_config($vmid); - if (defined($conf->{cipassword}) && - defined($conf->{cloudinit}->{cipassword}) && - $conf->{cipassword} ne $conf->{cloudinit}->{cipassword}) { - $conf->{cipassword} = '********** '; - } elsif (defined($conf->{cipassword})) { - $conf->{cipassword} = '**********'; + my $ci = $conf->{cloudinit}; + + my $res = {}; + my $added = delete($ci->{added}) // ''; + for my $key (PVE::Tools::split_list($added)) { + $res->{$key} = { new => $conf->{$key} }; } - $conf->{cloudinit}->{cipassword} = '**********' if defined($conf->{cloudinit}->{cipassword}); + for my $key (keys %$ci) { + if (!exists($conf->{$key})) { + $res->{$key} = { old => $ci->{$key} }; + } else { + $res->{$key} = { + old => $ci->{$key}, + new => $conf->{$key}, + }; + } + } - my $res = PVE::QemuServer::Cloudinit::get_pending_config($conf, $vmid); + if (defined(my $pw = $res->{cipassword})) { + $pw->{old} = '**********' if exists $pw->{old}; + $pw->{new} = '**********' if exists $pw->{new}; + } return $res; }}); diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index 24725e7..a0c3d60 100644 --- a/PVE/QemuServer/Cloudinit.pm +++ b/PVE/QemuServer/Cloudinit.pm @@ -627,82 +627,4 @@ 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); - }); - for my $ds (keys %{$drives}) { - 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. - #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"; - - 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}; - } else { - $item->{delete} = 1; - } - } else { - $item->{pending} = $newconf->{$opt} if $newconf->{$opt} - } - - push @$res, $item; - } - - return $res; -} - 1; -- 2.30.2