all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-network] ipam: improve update / delete behavior
@ 2023-11-22 12:29 Stefan Hanreich
  2023-11-22 12:29 ` [pve-devel] [PATCH pve-manager] ipam: send ip to delete endpoint Stefan Hanreich
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Stefan Hanreich @ 2023-11-22 12:29 UTC (permalink / raw)
  To: pve-devel

Currently when updating or deleting a mapping in the IPAM we would
delete all existing entries in the IPAM with that mac address. Now we
only delete the specific entry we are updating / deleting.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 src/PVE/API2/Network/SDN/Ips.pm | 20 +++++++++++++-------
 src/PVE/Network/SDN/Subnets.pm  |  3 +++
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/PVE/API2/Network/SDN/Ips.pm b/src/PVE/API2/Network/SDN/Ips.pm
index 6989b9b..0003b2a 100644
--- a/src/PVE/API2/Network/SDN/Ips.pm
+++ b/src/PVE/API2/Network/SDN/Ips.pm
@@ -28,6 +28,11 @@ __PACKAGE__->register_method ({
 	    zone => get_standard_option('pve-sdn-zone-id'),
 	    vnet => get_standard_option('pve-sdn-vnet-id'),
 	    mac => get_standard_option('mac-addr'),
+	    ip => {
+		type => 'string',
+		format => 'ip',
+		description => 'The IP address to delete',
+	    },
 	},
     },
     returns => { type => 'null' },
@@ -36,13 +41,12 @@ __PACKAGE__->register_method ({
 
 	my $vnet = extract_param($param, 'vnet');
 	my $mac = extract_param($param, 'mac');
+	my $ip = extract_param($param, 'ip');
 
 	eval {
-	    PVE::Network::SDN::Vnets::del_ips_from_mac($vnet, $mac);
+	    PVE::Network::SDN::Vnets::del_ip($vnet, $ip, '', $mac);
 	};
-	my $error = $@;
-
-	die "$error\n" if $error;
+	die "$@\n" if $@;
 
 	return undef;
     },
@@ -117,7 +121,10 @@ __PACKAGE__->register_method ({
 	my $vmid = extract_param($param, 'vmid');
 	my $ip = extract_param($param, 'ip');
 
-	my ($old_ip4, $old_ip6) = PVE::Network::SDN::Vnets::del_ips_from_mac($vnet, $mac, '');
+	my ($old_ip4, $old_ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnet, $mac);
+	my $old_ip = (Net::IP::ip_get_version($ip) == 4) ? $old_ip4 : $old_ip6;
+
+	PVE::Network::SDN::Vnets::del_ip($vnet, $old_ip, '', $mac);
 
 	eval {
 	    PVE::Network::SDN::Vnets::add_ip($vnet, $ip, '', $mac, $vmid);
@@ -125,8 +132,7 @@ __PACKAGE__->register_method ({
 	my $error = $@;
 
 	if ($error) {
-	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip4, '', $mac, $vmid) if $old_ip4;
-	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip6, '', $mac, $vmid) if $old_ip6;
+	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip, '', $mac, $vmid);
 	}
 
 	die "$error\n" if $error;
diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index 8e2a6aa..8f113b4 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -305,6 +305,9 @@ sub add_ip {
 	    $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway);
 	};
 	die $@ if $@;
+
+	eval { PVE::Network::SDN::Ipams::add_cache_mac_ip($mac, $ip) if $mac; };
+	warn $@ if $@;
     }
 
     eval {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-22 13:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-22 12:29 [pve-devel] [PATCH pve-network] ipam: improve update / delete behavior Stefan Hanreich
2023-11-22 12:29 ` [pve-devel] [PATCH pve-manager] ipam: send ip to delete endpoint Stefan Hanreich
2023-11-22 13:36   ` [pve-devel] applied: " Thomas Lamprecht
2023-11-22 13:18 ` [pve-devel] [PATCH pve-network] ipam: improve update / delete behavior Thomas Lamprecht
     [not found]   ` <55cfaf0f-b4c9-4698-89a5-faaf8ca6a000@proxmox.com>
2023-11-22 13:26     ` [pve-devel] applied: " Thomas Lamprecht
2023-11-22 13:45 ` [pve-devel] " Stefan Lendl

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