* [pve-devel] [PATCH pve-network] sdn: allow deletion of empty subnet with gateway
@ 2023-11-09 9:37 Stefan Lendl
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Lendl @ 2023-11-09 9:37 UTC (permalink / raw)
To: pve-devel
If the gateway IP is last remaining IP in the subnet (in IPAM), allow
deleting the subnet.
Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
---
src/PVE/Network/SDN/Ipams/PVEPlugin.pm | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/Ipams/PVEPlugin.pm b/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
index 3e8ffc5..c5ad260 100644
--- a/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
@@ -56,6 +56,16 @@ sub add_subnet {
die "$@" if $@;
}
+sub only_gateway_remains {
+ my ($ips) = @_;
+
+ if (keys %{$ips} == 1 &&
+ (values %{$ips})[0]->{gateway} == 1) {
+ return 1;
+ }
+ return 0;
+};
+
sub del_subnet {
my ($class, $plugin_config, $subnetid, $subnet) = @_;
@@ -71,7 +81,11 @@ sub del_subnet {
my $dbsubnet = $dbzone->{subnets}->{$cidr};
die "subnet '$cidr' doesn't exist in IPAM DB\n" if !$dbsubnet;
- die "cannot delete subnet '$cidr', not empty\n" if keys %{$dbsubnet->{ips}} > 0;
+ my $ips = $dbsubnet->{ips};
+
+ if (keys %{$ips} > 0 && !only_gateway_remains($ips)) {
+ die "cannot delete subnet '$cidr', not empty\n";
+ }
delete $dbzone->{subnets}->{$cidr};
--
2.41.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pve-devel] [PATCH pve-network] sdn: allow deletion of empty subnet with gateway
@ 2023-11-17 14:02 Stefan Lendl
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Lendl @ 2023-11-17 14:02 UTC (permalink / raw)
To: pve-devel
If the gateway IP is last remaining IP in the subnet (in IPAM), allow
deleting the subnet.
Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
---
src/PVE/Network/SDN/Ipams/PVEPlugin.pm | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/Ipams/PVEPlugin.pm b/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
index a5b4fe7..270fb04 100644
--- a/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
@@ -56,6 +56,16 @@ sub add_subnet {
die "$@" if $@;
}
+sub only_gateway_remains {
+ my ($ips) = @_;
+
+ if (keys %{$ips} == 1 &&
+ (values %{$ips})[0]->{gateway} == 1) {
+ return 1;
+ }
+ return 0;
+};
+
sub del_subnet {
my ($class, $plugin_config, $subnetid, $subnet) = @_;
@@ -71,7 +81,11 @@ sub del_subnet {
my $dbsubnet = $dbzone->{subnets}->{$cidr};
die "subnet '$cidr' doesn't exist in IPAM DB\n" if !$dbsubnet;
- die "cannot delete subnet '$cidr', not empty\n" if keys %{$dbsubnet->{ips}} > 0;
+ my $ips = $dbsubnet->{ips};
+
+ if (keys %{$ips} > 0 && !only_gateway_remains($ips)) {
+ die "cannot delete subnet '$cidr', not empty\n";
+ }
delete $dbzone->{subnets}->{$cidr};
--
2.42.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-17 14:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 9:37 [pve-devel] [PATCH pve-network] sdn: allow deletion of empty subnet with gateway Stefan Lendl
2023-11-17 14:02 Stefan Lendl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox