]> git.proxmox.com Git - pve-network.git/commitdiff
sdn: allow deletion of empty subnet with gateway
authorStefan Lendl <s.lendl@proxmox.com>
Fri, 17 Nov 2023 14:02:27 +0000 (15:02 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 22 Nov 2023 14:24:41 +0000 (15:24 +0100)
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

index a5b4fe7d1e51c5aa060f84e798c955dbbef01044..270fb04b205b731ce89ee30d15a76ff9dde6b3f5 100644 (file)
@@ -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};