public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
       [not found] <20241211233832.806187-1-me@nurohman.com>
@ 2024-12-12 13:20 ` Stefan Hanreich
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hanreich @ 2024-12-12 13:20 UTC (permalink / raw)
  To: nurohman, pve-devel

On 12/12/24 00:38, nurohman wrote:
> diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
> index d923269..5591b0b 100644
> --- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
> +++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
> @@ -151,7 +151,7 @@ sub add_next_freeip {
>  
>      my $params = { dns_name => $hostname, description => $description };
>  
> -    eval {
> +    my $ip = eval {
>  	my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
>  	my ($ip, undef) = split(/\//, $result->{address});
>  	return $ip;
> @@ -160,6 +160,8 @@ sub add_next_freeip {
>      if ($@) {
>  	die "can't find free ip in subnet $cidr: $@" if !$noerr;
>      }
> +
> +    return $ip;
>  }
>  
>  sub add_range_next_freeip {
> @@ -170,11 +172,14 @@ sub add_range_next_freeip {
>      my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"];
>  
>      my $internalid = get_iprange_id($url, $range, $headers);
> +    if ($internalid eq "") {
> +	$internalid = add_iprange($url, $range, $subnet, $headers);
> +    }
>      my $description = "mac:$data->{mac}" if $data->{mac};
>  
>      my $params = { dns_name => $data->{hostname}, description => $description };
>  
> -    eval {
> +    my $ip = eval {
>  	my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/ip-ranges/$internalid/available-ips/", $headers, $params);
>  	my ($ip, undef) = split(/\//, $result->{address});
>  	print "found ip free $ip in range $range->{'start-address'}-$range->{'end-address'}\n" if $ip;
> @@ -184,6 +189,8 @@ sub add_range_next_freeip {
>      if ($@) {
>  	die "can't find free ip in range $range->{'start-address'}-$range->{'end-address'}: $@" if !$noerr;
>      }
> +
> +    return $ip;
>  }

This part is already added in another patch series by Lou Lecrivain, so
we just need a patch that creates the IP Range in Netbox. As mentioned
in my high-level mail this should happen in the create / update call
rather than when trying to allocate the IP.



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
  2024-12-12  7:20 ` DERUMIER, Alexandre via pve-devel
@ 2024-12-13  9:55   ` Lou Lecrivain via pve-devel
  0 siblings, 0 replies; 5+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-12-13  9:55 UTC (permalink / raw)
  To: pve-devel; +Cc: Lou.Lecrivain, me

[-- Attachment #1: Type: message/rfc822, Size: 12849 bytes --]

From: <Lou.Lecrivain@wdz.de>
To: <pve-devel@lists.proxmox.com>
Cc: <alexandre.derumier@groupe-cyllene.com>, <me@nurohman.com>
Subject: RE:  Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
Date: Fri, 13 Dec 2024 09:55:18 +0000
Message-ID: <BE1P281MB21167501F2324FB4980D1E82853F2@BE1P281MB2116.DEUP281.PROD.OUTLOOK.COM>

Re,

> but shouldn't theses ranges be added when the dhcp ranges are submitted
> on subnet create/update api call ? (I'm not 100% sure, but I think it
> was missing a hook to call the sdn api when submitting the dhcp ranges)
Yes, I do think this should be the case too.

BR

________________________________________
De : pve-devel <pve-devel-bounces@lists.proxmox.com> de la part de DERUMIER, Alexandre via pve-devel <pve-devel@lists.proxmox.com>
Envoyé : jeudi 12 décembre 2024 08:20
À : pve-devel@lists.proxmox.com <pve-devel@lists.proxmox.com>
Cc : DERUMIER, Alexandre <alexandre.derumier@groupe-cyllene.com>; me@nurohman.com <me@nurohman.com>
Objet : [!!ACHTUNG extern!!] - Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
 
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

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

* Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
       [not found] ` <b6d41bd46ba97b50da21589f2ea676ab34cac339.camel@groupe-cyllene.com>
@ 2024-12-12 13:17   ` Stefan Hanreich
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hanreich @ 2024-12-12 13:17 UTC (permalink / raw)
  To: DERUMIER, Alexandre, pve-devel; +Cc: me

On 12/12/24 08:20, DERUMIER, Alexandre wrote:
> but shouldn't theses ranges be added when the dhcp ranges are submitted
> on subnet create/update api call ? (I'm not 100% sure, but I think it
> was missing a hook to call the sdn api when submitting the dhcp ranges
> )

Yes, I also think this should be handled in the create / update call
rather than doing it when trying to allocate the IP.


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
  2024-12-11 23:38 nurohman via pve-devel
@ 2024-12-12  7:20 ` DERUMIER, Alexandre via pve-devel
  2024-12-13  9:55   ` Lou Lecrivain via pve-devel
       [not found] ` <b6d41bd46ba97b50da21589f2ea676ab34cac339.camel@groupe-cyllene.com>
  1 sibling, 1 reply; 5+ messages in thread
From: DERUMIER, Alexandre via pve-devel @ 2024-12-12  7:20 UTC (permalink / raw)
  To: pve-devel; +Cc: DERUMIER, Alexandre, me

[-- Attachment #1: Type: message/rfc822, Size: 16912 bytes --]

From: "DERUMIER, Alexandre" <alexandre.derumier@groupe-cyllene.com>
To: "pve-devel@lists.proxmox.com" <pve-devel@lists.proxmox.com>
Cc: "me@nurohman.com" <me@nurohman.com>
Subject: Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
Date: Thu, 12 Dec 2024 07:20:02 +0000
Message-ID: <b6d41bd46ba97b50da21589f2ea676ab34cac339.camel@groupe-cyllene.com>

Hi,

I don't remember exactly when I have done the code (because dhcp range
has been added after my initial implementation, where I was looking
only the full prefix) 

but shouldn't theses ranges be added when the dhcp ranges are submitted
on subnet create/update api call ? (I'm not 100% sure, but I think it
was missing a hook to call the sdn api when submitting the dhcp ranges
)


-------- Message initial --------
De: nurohman via pve-devel <pve-devel@lists.proxmox.com>
Répondre à: Proxmox VE development discussion <pve-
devel@lists.proxmox.com>
À: pve-devel@lists.proxmox.com
Cc: nurohman <me@nurohman.com>
Objet: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
Date: 12/12/2024 00:38:04

when ip range not available in the NetBox, function response "can't
find free ip in range". 
Add new ip range if can't find ip range ID and response new ip range
ID.  

Co-authored-by: Jacob Green <jacobgreen at corporatetools.com>
Co-authored-by: Lou Lecrivain <lou.lecrivain at wdz.de>
Signed-off-by: Nurohman <me at nurohman.com>
---
 src/PVE/Network/SDN/Ipams/NetboxPlugin.pm | 34 +++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..5591b0b 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -151,7 +151,7 @@ sub add_next_freeip {
 
     my $params = { dns_name => $hostname, description => $description
};
 
-    eval {
+    my $ip = eval {
 
 my $result = PVE::Network::SDN::api_request("POST",
"$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
 
 my ($ip, undef) = split(/\//, $result->{address});
 
 return $ip;
@@ -160,6 +160,8 @@ sub add_next_freeip {
     if ($@) {
 
 die "can't find free ip in subnet $cidr: $@" if !$noerr;
     }
+
+    return $ip;
 }
 
 sub add_range_next_freeip {
@@ -170,11 +172,14 @@ sub add_range_next_freeip {
     my $headers = ['Content-Type' => 'application/json; charset=UTF-
8', 'Authorization' => "token $token"];
 
     my $internalid = get_iprange_id($url, $range, $headers);
+    if ($internalid eq "") {
+
 $internalid = add_iprange($url, $range, $subnet, $headers);
+    }
     my $description = "mac:$data->{mac}" if $data->{mac};
 
     my $params = { dns_name => $data->{hostname}, description =>
$description };
 
-    eval {
+    my $ip = eval {
 
 my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/ip-
ranges/$internalid/available-ips/", $headers, $params);
 
 my ($ip, undef) = split(/\//, $result->{address});
 
 print "found ip free $ip in range $range->{'start-address'}-$range-
>{'end-address'}\n" if $ip;
@@ -184,6 +189,8 @@ sub add_range_next_freeip {
     if ($@) {
 
 die "can't find free ip in range $range->{'start-address'}-$range-
>{'end-address'}: $@" if !$noerr;
     }
+
+    return $ip;
 }
 
 sub del_ip {
@@ -290,6 +297,29 @@ sub is_ip_gateway {
     return $is_gateway;
 }
 
+sub add_iprange {
+    my ($url, $range, $subnet, $headers) = @_;
+
+    my ($start, $smask)= split('/', $range->{'start-address'});
+    my ($end, $emask)= split('/', $range->{'end-address'});
+    my $params = {
+
 start_address => "$start/$subnet->{mask}",
+
 end_address => "$end/$subnet->{mask}",
+
 description => "prefix:$subnet->{cidr}"
+    };
+
+    my $data = eval {
+        my $result = PVE::Network::SDN::api_request("POST",
"$url/ipam/ip-ranges/", $headers, $params);
+
 return $result;
+    };
+
+    if ($@) {
+        die "Can't add ip range $start/$subnet->{mask} ->
$end/$subnet->{mask} $@";
+    }
+
+    return $data->{id};
+}
+
 1;
 
 


[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

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

* [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
@ 2024-12-11 23:38 nurohman via pve-devel
  2024-12-12  7:20 ` DERUMIER, Alexandre via pve-devel
       [not found] ` <b6d41bd46ba97b50da21589f2ea676ab34cac339.camel@groupe-cyllene.com>
  0 siblings, 2 replies; 5+ messages in thread
From: nurohman via pve-devel @ 2024-12-11 23:38 UTC (permalink / raw)
  To: pve-devel; +Cc: nurohman

[-- Attachment #1: Type: message/rfc822, Size: 6541 bytes --]

From: nurohman <me@nurohman.com>
To: pve-devel@lists.proxmox.com
Cc: nurohman <me@nurohman.com>
Subject: [PATCH pve-network] Fix #5496: NetBox add ip range
Date: Thu, 12 Dec 2024 06:38:04 +0700
Message-ID: <20241211233832.806187-1-me@nurohman.com>

when ip range not available in the NetBox, function response "can't find free ip in range". 
Add new ip range if can't find ip range ID and response new ip range ID.  

Co-authored-by: Jacob Green <jacobgreen at corporatetools.com>
Co-authored-by: Lou Lecrivain <lou.lecrivain at wdz.de>
Signed-off-by: Nurohman <me at nurohman.com>
---
 src/PVE/Network/SDN/Ipams/NetboxPlugin.pm | 34 +++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..5591b0b 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -151,7 +151,7 @@ sub add_next_freeip {
 
     my $params = { dns_name => $hostname, description => $description };
 
-    eval {
+    my $ip = eval {
 	my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
 	my ($ip, undef) = split(/\//, $result->{address});
 	return $ip;
@@ -160,6 +160,8 @@ sub add_next_freeip {
     if ($@) {
 	die "can't find free ip in subnet $cidr: $@" if !$noerr;
     }
+
+    return $ip;
 }
 
 sub add_range_next_freeip {
@@ -170,11 +172,14 @@ sub add_range_next_freeip {
     my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"];
 
     my $internalid = get_iprange_id($url, $range, $headers);
+    if ($internalid eq "") {
+	$internalid = add_iprange($url, $range, $subnet, $headers);
+    }
     my $description = "mac:$data->{mac}" if $data->{mac};
 
     my $params = { dns_name => $data->{hostname}, description => $description };
 
-    eval {
+    my $ip = eval {
 	my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/ip-ranges/$internalid/available-ips/", $headers, $params);
 	my ($ip, undef) = split(/\//, $result->{address});
 	print "found ip free $ip in range $range->{'start-address'}-$range->{'end-address'}\n" if $ip;
@@ -184,6 +189,8 @@ sub add_range_next_freeip {
     if ($@) {
 	die "can't find free ip in range $range->{'start-address'}-$range->{'end-address'}: $@" if !$noerr;
     }
+
+    return $ip;
 }
 
 sub del_ip {
@@ -290,6 +297,29 @@ sub is_ip_gateway {
     return $is_gateway;
 }
 
+sub add_iprange {
+    my ($url, $range, $subnet, $headers) = @_;
+
+    my ($start, $smask)= split('/', $range->{'start-address'});
+    my ($end, $emask)= split('/', $range->{'end-address'});
+    my $params = {
+	start_address => "$start/$subnet->{mask}",
+	end_address => "$end/$subnet->{mask}",
+	description => "prefix:$subnet->{cidr}"
+    };
+
+    my $data = eval {
+        my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/ip-ranges/", $headers, $params);
+	return $result;
+    };
+
+    if ($@) {
+        die "Can't add ip range $start/$subnet->{mask} -> $end/$subnet->{mask} $@";
+    }
+
+    return $data->{id};
+}
+
 1;
 
 
-- 
2.47.1



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

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

end of thread, other threads:[~2024-12-13  9:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20241211233832.806187-1-me@nurohman.com>
2024-12-12 13:20 ` [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range Stefan Hanreich
2024-12-11 23:38 nurohman via pve-devel
2024-12-12  7:20 ` DERUMIER, Alexandre via pve-devel
2024-12-13  9:55   ` Lou Lecrivain via pve-devel
     [not found] ` <b6d41bd46ba97b50da21589f2ea676ab34cac339.camel@groupe-cyllene.com>
2024-12-12 13:17   ` Stefan Hanreich

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