[pve-devel] [PATCH v2 pve-network 1/6] ipams : add_next_freeip : return ip not cidr

Alexandre Derumier aderumier at odiso.com
Tue Feb 13 09:48:53 CET 2024


we want same result than add_next_free_range

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/Network/SDN/Ipams/NetboxPlugin.pm  | 13 ++++---------
 src/PVE/Network/SDN/Ipams/PVEPlugin.pm     |  2 +-
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm |  2 +-
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index 91010bb..14a69d9 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -151,17 +151,15 @@ sub add_next_freeip {
 
     my $params = { dns_name => $hostname, description => $description };
 
-    my $ip = undef;
     eval {
 	my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
-	$ip = $result->{address};
+	my ($ip, undef) = split(/\//, $result->{address});
+	return $ip;
     };
 
     if ($@) {
 	die "can't find free ip in subnet $cidr: $@" if !$noerr;
     }
-
-    return $ip;
 }
 
 sub add_range_next_freeip {
@@ -176,19 +174,16 @@ sub add_range_next_freeip {
 
     my $params = { dns_name => $data->{hostname}, description => $description };
 
-    my $ip = undef;
     eval {
 	my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/ip-ranges/$internalid/available-ips/", $headers, $params);
-	$ip = $result->{address};
+	my ($ip, undef) = split(/\//, $result->{address});
 	print "found ip free $ip in range $range->{'start-address'}-$range->{'end-address'}\n" if $ip;
+	return $ip;
     };
 
     if ($@) {
 	die "can't find free ip in range $range->{'start-address'}-$range->{'end-address'}: $@" if !$noerr;
     }
-
-    return $ip;
-
 }
 
 sub del_ip {
diff --git a/src/PVE/Network/SDN/Ipams/PVEPlugin.pm b/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
index 270fb04..651acfb 100644
--- a/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PVEPlugin.pm
@@ -176,7 +176,7 @@ sub add_next_freeip {
     });
     die "$@" if $@;
 
-    return "$freeip/$mask";
+    return $freeip;
 }
 
 sub add_range_next_freeip {
diff --git a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
index 1b7b666..7b3168d 100644
--- a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
@@ -181,7 +181,7 @@ sub add_next_freeip {
         die "can't find free ip in subnet $cidr: $@" if !$noerr;
     }
 
-    return "$ip/$mask" if $ip && $mask;
+    return $ip;
 }
 
 sub del_ip {
-- 
2.39.2




More information about the pve-devel mailing list