public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH network 2/7] api: take partial configs for PUT /cluster/sdn/zones/<id>
Date: Wed, 22 Nov 2023 12:53:45 +0100	[thread overview]
Message-ID: <20231122115350.131255-3-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20231122115350.131255-1-w.bumiller@proxmox.com>

Zones previously expected a complete config, but the API schema
also contains a 'delete' parameter via the SectionConfig's
updateSchema() helper. This was not handled, and instead failed to
validate as part of the config.

The same is true for vnets and subnets, while ipams, dns and
controller entries followed our usual update procedures (but also
ignored the 'delete' parameter).

Since all of our SectionConfig based API endpoints are supposed to
take changes, rather than complete configs, this changes these
endpoints to not replace the full configuration anymore.

This is a major break for automation tools (the web UI already passed
the full config each time).

Cc: Alexandre Derumier <aderumier@odiso.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 src/PVE/API2/Network/SDN/Zones.pm | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/PVE/API2/Network/SDN/Zones.pm b/src/PVE/API2/Network/SDN/Zones.pm
index 1c3356e..b09c9ad 100644
--- a/src/PVE/API2/Network/SDN/Zones.pm
+++ b/src/PVE/API2/Network/SDN/Zones.pm
@@ -261,6 +261,11 @@ __PACKAGE__->register_method ({
 
 	my $id = extract_param($param, 'zone');
 	my $digest = extract_param($param, 'digest');
+	my $delete = extract_param($param, 'delete');
+
+	if ($delete) {
+	    $delete = [ PVE::Tools::split_list($delete) ];
+	}
 
 	PVE::Network::SDN::lock_sdn_config(sub {
 	    my $zone_cfg = PVE::Network::SDN::Zones::config();
@@ -274,8 +279,17 @@ __PACKAGE__->register_method ({
 	    my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($scfg->{type});
 	    my $opts = $plugin->check_config($id, $param, 0, 1);
 
-	    if ($opts->{ipam} && !$scfg->{ipam} || $opts->{ipam} ne $scfg->{ipam}) {
+	    my $old_ipam = $scfg->{ipam};
+
+	    if ($delete) {
+		my $options = $plugin->private()->{options}->{$scfg->{type}};
+		PVE::SectionConfig::delete_from_config($scfg, $options, $opts, $delete);
+	    }
 
+	    $scfg->{$_} = $opts->{$_} for keys $opts->%*;
+
+	    my $new_ipam = $scfg->{ipam};
+	    if (!$new_ipam != !$old_ipam || (($new_ipam//'') ne ($old_ipam//''))) {
 		# don't allow ipam change if subnet are defined for now, need to implement resync ipam content
 		my $subnets_cfg = PVE::Network::SDN::Subnets::config();
 		for my $subnetid (sort keys %{$subnets_cfg->{ids}}) {
@@ -285,8 +299,6 @@ __PACKAGE__->register_method ({
 		}
 	    }
 
-	    $zone_cfg->{ids}->{$id} = $opts;
-
 	    my $dnsserver = $opts->{dns};
 	    raise_param_exc({ dns => "$dnsserver don't exist"}) if $dnsserver && !$dns_cfg->{ids}->{$dnsserver};
 
-- 
2.39.2





  parent reply	other threads:[~2023-11-22 11:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 11:53 [pve-devel] applied-series: [PATCH network 0/7] PUT API endpoint changes Wolfgang Bumiller
2023-11-22 11:53 ` [pve-devel] [PATCH network 1/7] Revert "sdn: require ipam in simple plugin for dhcp" Wolfgang Bumiller
2023-11-22 11:53 ` Wolfgang Bumiller [this message]
2023-11-22 11:53 ` [pve-devel] [PATCH network 3/7] api: take partial configs for PUT /cluster/sdn/vnets/<id> Wolfgang Bumiller
2023-11-22 11:53 ` [pve-devel] [PATCH network 4/7] api: take partial configs for PUT /cluster/sdn/vnets/<n>/subnets/<i> Wolfgang Bumiller
2023-11-22 11:53 ` [pve-devel] [PATCH network 5/7] api: handle delete parameter when updating ipams Wolfgang Bumiller
2023-11-22 11:53 ` [pve-devel] [PATCH network 6/7] api: handle delete parameter when updating dns entries Wolfgang Bumiller
2023-11-22 11:53 ` [pve-devel] [PATCH network 7/7] api: handle delete parameter when updating controllers Wolfgang Bumiller
2023-11-22 12:26 ` [pve-devel] applied-series: [PATCH network 0/7] PUT API endpoint changes Stefan Hanreich

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=20231122115350.131255-3-w.bumiller@proxmox.com \
    --to=w.bumiller@proxmox.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