public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [pve-network 0/5] external ipams fixes
@ 2024-01-04 16:11 Alexandre Derumier
  2024-01-04 16:11 ` [pve-devel] [pve-network 1/5] sdn: add proxy support for api calls Alexandre Derumier
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:11 UTC (permalink / raw)
  To: pve-devel

This patch serie is fixing multiple bug in phpipam,
and dd_next_freeip in differents ipams

Alexandre Derumier (5):
  sdn: add proxy support for api calls
  ipams : add_next_freeip : return ip not cidr
  ipam: phpipam: fix subnet create
  ipam: phpipam: fix get_ip_from_mac
  ipam: phpipam: add_range_next_freeip

 src/PVE/Network/SDN.pm                     |  7 +++----
 src/PVE/Network/SDN/Ipams/NetboxPlugin.pm  | 13 ++++--------
 src/PVE/Network/SDN/Ipams/PVEPlugin.pm     |  2 +-
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 24 ++++++++++++++++++----
 4 files changed, 28 insertions(+), 18 deletions(-)

-- 
2.39.2




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

* [pve-devel] [pve-network 1/5] sdn: add proxy support for api calls
  2024-01-04 16:11 [pve-devel] [pve-network 0/5] external ipams fixes Alexandre Derumier
@ 2024-01-04 16:11 ` Alexandre Derumier
  2024-01-04 16:11 ` [pve-devel] [pve-network 2/5] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:11 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN.pm | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm
index 3af09b5..b8f27d9 100644
--- a/src/PVE/Network/SDN.pm
+++ b/src/PVE/Network/SDN.pm
@@ -264,10 +264,9 @@ sub api_request {
     my $req = HTTP::Request->new($method,$url, $headers, $encoded_data);
 
     my $ua = LWP::UserAgent->new(protocols_allowed => ['http', 'https'], timeout => 30);
-    my $proxy = undef;
-
-    if ($proxy) {
-        $ua->proxy(['http', 'https'], $proxy);
+    my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+    if ($dccfg->{http_proxy}) {
+	$ua->proxy(['http', 'https'], $dccfg->{http_proxy});
     } else {
         $ua->env_proxy;
     }
-- 
2.39.2




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

* [pve-devel] [pve-network 2/5] ipams : add_next_freeip : return ip not cidr
  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
  2024-01-04 16:11 ` [pve-devel] [pve-network 3/5] ipam: phpipam: fix subnet create Alexandre Derumier
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:11 UTC (permalink / raw)
  To: pve-devel

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




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

* [pve-devel] [pve-network 3/5] ipam: phpipam: fix subnet create
  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 ` [pve-devel] [pve-network 2/5] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
@ 2024-01-04 16:11 ` Alexandre Derumier
  2024-01-04 16:11 ` [pve-devel] [pve-network 4/5] ipam: phpipam: fix get_ip_from_mac Alexandre Derumier
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:11 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
index 7b3168d..f3f22b5 100644
--- a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
@@ -51,7 +51,8 @@ sub add_subnet {
     my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
 
     #search subnet
-    my $internalid = get_prefix_id($url, $cidr, $headers);
+    my $internalid;
+    eval { $internalid = get_prefix_id($url, $cidr, $headers) };
 
     #create subnet
     if (!$internalid) {
-- 
2.39.2




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

* [pve-devel] [pve-network 4/5] ipam: phpipam: fix get_ip_from_mac
  2024-01-04 16:11 [pve-devel] [pve-network 0/5] external ipams fixes Alexandre Derumier
                   ` (2 preceding siblings ...)
  2024-01-04 16:11 ` [pve-devel] [pve-network 3/5] ipam: phpipam: fix subnet create Alexandre Derumier
@ 2024-01-04 16:11 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:11 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
index f3f22b5..bb9f322 100644
--- a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
@@ -215,8 +215,11 @@ sub get_ips_from_mac {
 
     my $ip4 = undef;
     my $ip6 = undef;
-
-    my $ips = PVE::Network::SDN::api_request("GET", "$url/addresses/search_mac/$mac", $headers);
+    my $ips = undef;
+    eval {
+	$ips = PVE::Network::SDN::api_request("GET", "$url/addresses/search_mac/$mac", $headers);
+    };
+    return if $@;
 
     #fixme
     die "parsing of result not yet implemented";
-- 
2.39.2




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

* [pve-devel] [pve-network 5/5] ipam: phpipam: add_range_next_freeip
  2024-01-04 16:11 [pve-devel] [pve-network 0/5] external ipams fixes Alexandre Derumier
                   ` (3 preceding siblings ...)
  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 ` Alexandre Derumier
  2024-01-19 11:54 ` [pve-devel] [pve-network 0/5] external ipams fixes DERUMIER, Alexandre
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:11 UTC (permalink / raw)
  To: pve-devel

Currently is not possible in phpipam to search in specific range,
fallback to full subnet search

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
index bb9f322..1c6159c 100644
--- a/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
@@ -185,6 +185,18 @@ sub add_next_freeip {
     return $ip;
 }
 
+sub add_range_next_freeip {
+    my ($class, $plugin_config, $subnet, $range, $data, $noerr) = @_;
+
+    #not implemented in phpipam, we search in the full subnet
+
+    my $vmid = $data->{vmid};
+    my $mac = $data->{mac};
+    my $hostname = $data->{hostname};
+
+    return $class->add_next_freeip($plugin_config, undef, $subnet, $hostname, $mac, $vmid);
+}
+
 sub del_ip {
     my ($class, $plugin_config, $subnetid, $subnet, $ip, $noerr) = @_;
 
-- 
2.39.2




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

* Re: [pve-devel] [pve-network 0/5] external ipams fixes
  2024-01-04 16:11 [pve-devel] [pve-network 0/5] external ipams fixes Alexandre Derumier
                   ` (4 preceding siblings ...)
  2024-01-04 16:11 ` [pve-devel] [pve-network 5/5] ipam: phpipam: add_range_next_freeip Alexandre Derumier
@ 2024-01-19 11:54 ` DERUMIER, Alexandre
  5 siblings, 0 replies; 7+ messages in thread
From: DERUMIER, Alexandre @ 2024-01-19 11:54 UTC (permalink / raw)
  To: pve-devel

Hi,
could it be possible to a applied this patches serie ?

a forum user just have reported a related but with netbox && dhcp

https://forum.proxmox.com/threads/ipam-netbox-integration.140043/


-------- Message initial --------
De: Alexandre Derumier <aderumier@odiso.com>
Répondre à: Proxmox VE development discussion <pve-
devel@lists.proxmox.com>
À: pve-devel@lists.proxmox.com
Objet: [pve-devel] [pve-network 0/5] external ipams fixes
Date: 04/01/2024 17:11:34

This patch serie is fixing multiple bug in phpipam,
and dd_next_freeip in differents ipams

Alexandre Derumier (5):
  sdn: add proxy support for api calls
  ipams : add_next_freeip : return ip not cidr
  ipam: phpipam: fix subnet create
  ipam: phpipam: fix get_ip_from_mac
  ipam: phpipam: add_range_next_freeip

 src/PVE/Network/SDN.pm                     |  7 +++----
 src/PVE/Network/SDN/Ipams/NetboxPlugin.pm  | 13 ++++--------
 src/PVE/Network/SDN/Ipams/PVEPlugin.pm     |  2 +-
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 24 ++++++++++++++++++----
 4 files changed, 28 insertions(+), 18 deletions(-)



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

end of thread, other threads:[~2024-01-19 11:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [pve-devel] [pve-network 2/5] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
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

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