From d4c9897507f3eacf25da030629653299cdca719f Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 22 Nov 2023 11:14:38 +0100 Subject: [PATCH] api: take partial configs for PUT /cluster/sdn/vnets/ Handle 'delete' parameter and partial updates. See previous commit for explanation. Cc: Alexandre Derumier Signed-off-by: Wolfgang Bumiller --- src/PVE/API2/Network/SDN/Vnets.pm | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/PVE/API2/Network/SDN/Vnets.pm b/src/PVE/API2/Network/SDN/Vnets.pm index a32df8c..57de295 100644 --- a/src/PVE/API2/Network/SDN/Vnets.pm +++ b/src/PVE/API2/Network/SDN/Vnets.pm @@ -244,21 +244,37 @@ __PACKAGE__->register_method ({ my $id = extract_param($param, 'vnet'); my $digest = extract_param($param, 'digest'); + my $delete = extract_param($param, 'delete'); my $privs = [ 'SDN.Allocate' ]; &$check_vnet_access($id, $privs); + if ($delete) { + $delete = [ PVE::Tools::split_list($delete) ]; + } + PVE::Network::SDN::lock_sdn_config(sub { my $cfg = PVE::Network::SDN::Vnets::config(); PVE::SectionConfig::assert_if_modified($cfg, $digest); my $opts = PVE::Network::SDN::VnetPlugin->check_config($id, $param, 0, 1); - raise_param_exc({ zone => "missing zone"}) if !$opts->{zone}; - my $subnets = PVE::Network::SDN::Vnets::get_subnets($id); - raise_param_exc({ zone => "can't change zone if subnets exists"}) if($subnets && $opts->{zone} ne $cfg->{ids}->{$id}->{zone}); - $cfg->{ids}->{$id} = $opts; + my $data = $cfg->{ids}->{$id}; + my $old_zone = $data->{zone}; + + if ($delete) { + my $options = PVE::Network::SDN::VnetPlugin->private()->{options}->{$data->{type}}; + PVE::SectionConfig::delete_from_config($data, $options, $opts, $delete); + } + + $data->{$_} = $opts->{$_} for keys $opts->%*; + + my $new_zone = $data->{zone}; + raise_param_exc({ zone => "cannot delete zone"}) if !$new_zone; + my $subnets = PVE::Network::SDN::Vnets::get_subnets($id); + raise_param_exc({ zone => "can't change zone if subnets exist"}) + if $subnets && $old_zone ne $new_zone; my $zone_cfg = PVE::Network::SDN::Zones::config(); my $zoneid = $cfg->{ids}->{$id}->{zone}; -- 2.39.5