public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [pve-network 2/5] ipams : add_next_freeip : return ip not cidr
Date: Thu,  4 Jan 2024 17:11:36 +0100	[thread overview]
Message-ID: <20240104161139.4142994-3-aderumier@odiso.com> (raw)
In-Reply-To: <20240104161139.4142994-1-aderumier@odiso.com>

we want same result than add_next_free_range

Signed-off-by: Alexandre Derumier <aderumier@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




  parent reply	other threads:[~2024-01-04 16:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04 16:11 [pve-devel] [pve-network 0/5] external ipams fixes Alexandre Derumier
2024-01-04 16:11 ` [pve-devel] [pve-network 1/5] sdn: add proxy support for api calls Alexandre Derumier
2024-01-04 16:11 ` Alexandre Derumier [this message]
2024-01-04 16:11 ` [pve-devel] [pve-network 3/5] ipam: phpipam: fix subnet create Alexandre Derumier
2024-01-04 16:11 ` [pve-devel] [pve-network 4/5] ipam: phpipam: fix get_ip_from_mac Alexandre Derumier
2024-01-04 16:11 ` [pve-devel] [pve-network 5/5] ipam: phpipam: add_range_next_freeip Alexandre Derumier
2024-01-19 11:54 ` [pve-devel] [pve-network 0/5] external ipams fixes DERUMIER, Alexandre

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=20240104161139.4142994-3-aderumier@odiso.com \
    --to=aderumier@odiso.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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal