From 3e3cafabaf955d53c4c2d4e346bf5c3a5c6d1852 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 22 Nov 2023 11:08:21 +0100 Subject: [PATCH] api: take partial configs for PUT /cluster/sdn/zones/ 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 Signed-off-by: Wolfgang Bumiller --- 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.5