From: Alexandre Derumier Date: Thu, 4 Jan 2024 16:11:36 +0000 (+0100) Subject: ipams : add_next_freeip : return ip not cidr X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=b906257d4a51f1c7d21ff1513a7076cb7013e2d6;p=mirror%2Fpve-network.git ipams : add_next_freeip : return ip not cidr we want same result than add_next_free_range Signed-off-by: Alexandre Derumier --- 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 {