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: Fri, 17 Nov 2023 15:02:27 +0100 [thread overview]
Message-ID: <20231117140225.3233389-3-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 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
next reply other threads:[~2023-11-17 14:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-17 14:02 Stefan Lendl [this message]
2023-11-22 14:45 ` [pve-devel] applied: " Wolfgang Bumiller
-- strict thread matches above, loose matches on Subject: below --
2023-11-09 9:37 [pve-devel] " 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=20231117140225.3233389-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox