]> git.proxmox.com Git - pve-network.git/commitdiff
api: take partial configs for PUT /cluster/sdn/zones/<id>
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 22 Nov 2023 10:08:21 +0000 (11:08 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 22 Nov 2023 11:21:38 +0000 (12:21 +0100)
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

index 1c3356ee31fa2b528a8b65c79eda4a74b23f9979..b09c9addb5600248ef4d88b4b14b1b5a2f39dfd9 100644 (file)
@@ -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};