public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes
@ 2024-02-13  8:48 Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 1/6] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 UTC (permalink / raw)
  To: pve-devel

multiples ipam fixes

v2:
add netbox ipam ip_is_gateway fix



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

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

-- 
2.39.2




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

* [pve-devel] [PATCH v2 pve-network 1/6] ipams : add_next_freeip : return ip not cidr
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
@ 2024-02-13  8:48 ` Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 2/6] sdn: add proxy support for api calls Alexandre Derumier
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 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] 8+ messages in thread

* [pve-devel] [PATCH v2 pve-network 2/6] sdn: add proxy support for api calls
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 1/6] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
@ 2024-02-13  8:48 ` Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 3/6] ipam: phpipam: fix subnet create Alexandre Derumier
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 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] 8+ messages in thread

* [pve-devel] [PATCH v2 pve-network 3/6] ipam: phpipam: fix subnet create
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 1/6] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 2/6] sdn: add proxy support for api calls Alexandre Derumier
@ 2024-02-13  8:48 ` Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 4/6] ipam: phpipam: fix get_ip_from_mac Alexandre Derumier
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 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] 8+ messages in thread

* [pve-devel] [PATCH v2 pve-network 4/6] ipam: phpipam: fix get_ip_from_mac
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
                   ` (2 preceding siblings ...)
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 3/6] ipam: phpipam: fix subnet create Alexandre Derumier
@ 2024-02-13  8:48 ` Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 5/6] ipam: phpipam: add_range_next_freeip Alexandre Derumier
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 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] 8+ messages in thread

* [pve-devel] [PATCH v2 pve-network 5/6] ipam: phpipam: add_range_next_freeip
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
                   ` (3 preceding siblings ...)
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 4/6] ipam: phpipam: fix get_ip_from_mac Alexandre Derumier
@ 2024-02-13  8:48 ` Alexandre Derumier
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 6/6] ipam: netbox : fix ip_is_gateway Alexandre Derumier
  2024-02-20 14:07 ` [pve-devel] applied: [PATCH v2 pve-network 0/6] external ipams fixes Thomas Lamprecht
  6 siblings, 0 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 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] 8+ messages in thread

* [pve-devel] [PATCH v2 pve-network 6/6] ipam: netbox : fix ip_is_gateway
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
                   ` (4 preceding siblings ...)
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 5/6] ipam: phpipam: add_range_next_freeip Alexandre Derumier
@ 2024-02-13  8:48 ` Alexandre Derumier
  2024-02-20 14:07 ` [pve-devel] applied: [PATCH v2 pve-network 0/6] external ipams fixes Thomas Lamprecht
  6 siblings, 0 replies; 8+ messages in thread
From: Alexandre Derumier @ 2024-02-13  8:48 UTC (permalink / raw)
  To: pve-devel

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

diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index 14a69d9..d923269 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -283,7 +283,7 @@ sub get_ip_id {
 
 sub is_ip_gateway {
     my ($url, $ip, $headers) = @_;
-    my $result = PVE::Network::SDN::api_request("GET", "$url/addresses/search/$ip", $headers);
+    my $result = PVE::Network::SDN::api_request("GET", "$url/ipam/ip-addresses/?q=$ip", $headers);
     my $data = @{$result->{data}}[0];
     my $description = $data->{description};
     my $is_gateway = 1 if $description eq 'gateway';
-- 
2.39.2




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

* [pve-devel] applied: [PATCH v2 pve-network 0/6] external ipams fixes
  2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
                   ` (5 preceding siblings ...)
  2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 6/6] ipam: netbox : fix ip_is_gateway Alexandre Derumier
@ 2024-02-20 14:07 ` Thomas Lamprecht
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Lamprecht @ 2024-02-20 14:07 UTC (permalink / raw)
  To: Proxmox VE development discussion, Alexandre Derumier

Am 13/02/2024 um 09:48 schrieb Alexandre Derumier:
> multiples ipam fixes
> 
> v2:
> add netbox ipam ip_is_gateway fix
> 
> 
> 
> Alexandre Derumier (6):
>   ipams : add_next_freeip : return ip not cidr
>   sdn: add proxy support for api calls
>   ipam: phpipam: fix subnet create
>   ipam: phpipam: fix get_ip_from_mac
>   ipam: phpipam: add_range_next_freeip
>   ipam: netbox : fix ip_is_gateway
> 
>  src/PVE/Network/SDN.pm                     |  7 +++----
>  src/PVE/Network/SDN/Ipams/NetboxPlugin.pm  | 15 +++++---------
>  src/PVE/Network/SDN/Ipams/PVEPlugin.pm     |  2 +-
>  src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 24 ++++++++++++++++++----
>  4 files changed, 29 insertions(+), 19 deletions(-)
> 


applied series, thanks!

note though that the "get_ips_from_mac" is not really fixed, as
parsing is not implemented there yet, so I reworded the commit
message a bit.





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

end of thread, other threads:[~2024-02-20 14:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13  8:48 [pve-devel] [PATCH v2 pve-network 0/6] external ipams fixes Alexandre Derumier
2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 1/6] ipams : add_next_freeip : return ip not cidr Alexandre Derumier
2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 2/6] sdn: add proxy support for api calls Alexandre Derumier
2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 3/6] ipam: phpipam: fix subnet create Alexandre Derumier
2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 4/6] ipam: phpipam: fix get_ip_from_mac Alexandre Derumier
2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 5/6] ipam: phpipam: add_range_next_freeip Alexandre Derumier
2024-02-13  8:48 ` [pve-devel] [PATCH v2 pve-network 6/6] ipam: netbox : fix ip_is_gateway Alexandre Derumier
2024-02-20 14:07 ` [pve-devel] applied: [PATCH v2 pve-network 0/6] external ipams fixes Thomas Lamprecht

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