all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Lendl <s.lendl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network] sdn: allow deletion of empty subnet with gateway
Date: Thu,  9 Nov 2023 10:37:41 +0100	[thread overview]
Message-ID: <20231109093740.1351365-2-s.lendl@proxmox.com> (raw)

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





             reply	other threads:[~2023-11-09  9:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09  9:37 Stefan Lendl [this message]
2023-11-17 14:02 Stefan Lendl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231109093740.1351365-2-s.lendl@proxmox.com \
    --to=s.lendl@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal