SDN problems with Netbox as IPAM

Hi @WarmEthernet, @spirit,

I'm currently using Proxmox 8.2.4 and NetBox 4.1.1 running in a Docker container. I noticed that the NetboxPlugin.pmfile has been patched, but the issue seems to persist. It appears that NetBox is still returning the full CIDR (e.g., 192.168.1.1/24), but I'm not entirely sure what the plugin expects in terms of IP format.

Has anyone found a workaround for this bug, or could you provide more details on what the Proxmox plugin is looking for? Any insights would be appreciated!

Thanks!

1726767427734.png
 
I did a little debugging and I think the bug is caused because this return statement has the wrong scope.
I'm by no means a perl expert but from what I understand this doesn't actually returns the ip value from the add_range_next_freeip subroutine.

This should fix it:
Git:
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..124c355 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 {
@@ -174,7 +176,7 @@ sub add_range_next_freeip {
 
     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 +186,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 {
 
I did a little debugging and I think the bug is caused because this return statement has the wrong scope.
I'm by no means a perl expert but from what I understand this doesn't actually returns the ip value from the add_range_next_freeip subroutine.

This should fix it:
Git:
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..124c355 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 {
@@ -174,7 +176,7 @@ sub add_range_next_freeip {
 
     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 +186,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 {
THANK YOU!! This definitely helped and now Netbox IPAM works, I had to restart the GUI before I was able to use the Netbox patch you made. I hope this gets into the next update/patch release.
 
I did a little debugging and I think the bug is caused because this return statement has the wrong scope.
I'm by no means a perl expert but from what I understand this doesn't actually returns the ip value from the add_range_next_freeip subroutine.

This should fix it:
Git:
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..124c355 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 {
@@ -174,7 +176,7 @@ sub add_range_next_freeip {
 
     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 +186,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 {
Thanks @jon4hz this is the actual fix!
 
Any way we can get this thread's title change to have [SOLVED] prepended, and possibly the original post updated to include an edit stating that the fix is contained in reply #? Just a thought.

Also, are the PVE packages going to include this in an update soon, or is there a dev cycle that has to complete before we get the fix into the package? Only asking out of curiosity, definitely not trying to make your lives difficult.

Thanks for the hard work and diligent bug squashing!

Ronin
Resident Forum Lurker and Mental Patient
 
Also, are the PVE packages going to include this in an update soon, or is there a dev cycle that has to complete before we get the fix into the package?

Yeah, me too! I also submitted my patch to the bugzilla issue but unfortunately I didn't receive any feedback yet. To be fair, my patch doesn't fix the full issue, since there is still the problem that Proxmox doesn't add the IP range automatically. I'll see if I get a free minute in the near future and patch that as well. From what I saw, it should be fairly simple by extending the add_subnet subroutine to also create an IP range.

Also, this is my first time contributing to Proxmox. So if submitting the patch to bugzilla isn't the way to go, please let me know! I saw that there is a mailing list, but to be honest, I have to research what the proper etiquette is to submit patches there first.
 
Last edited:
  • Like
Reactions: msvronin
Yeah, me too! I also submitted my patch to the bugzilla issue but unfortunately I didn't receive any feedback yet. To be fair, my patch doesn't fix the full issue, since there is still the problem that Proxmox doesn't add the IP range automatically. I'll see if I get a free minute in the near future and patch that as well. From what I saw, it should be fairly simple by extending the add_subnet subroutine to also create an IP range.

Also, this is my first time contributing to Proxmox. So if submitting the patch to bugzilla isn't the way to go, please let me know! I saw that there is a mailing list, but to be honest, I have to research what the proper etiquette is to submit patches there first.

Sorry for the silence, I wasn't really available the last few days / weeks. I'll look into reviewing the patch. Submitting to the mailing list would be the preferred way of posting patches, we have a guideline for submitting patches in our wiki [1]. It might look intimidating at first, but it really isn't ;)

[1] https://pve.proxmox.com/wiki/Developer_Documentation#Sending_Patches
 
  • Like
Reactions: msvronin and jon4hz
Yeah, me too! I also submitted my patch to the bugzilla issue but unfortunately I didn't receive any feedback yet. To be fair, my patch doesn't fix the full issue, since there is still the problem that Proxmox doesn't add the IP range automatically. I'll see if I get a free minute in the near future and patch that as well. From what I saw, it should be fairly simple by extending the add_subnet subroutine to also create an IP range.

Also, this is my first time contributing to Proxmox. So if submitting the patch to bugzilla isn't the way to go, please let me know! I saw that there is a mailing list, but to be honest, I have to research what the proper etiquette is to submit patches there first.
Hey @jon4hz , thanks for the helping with the issue. You are correct, it does not automatically create the ip range, but I also noticed something else while testing your changes. When I deploy a new VM, it grabs 2 different IPs from netbox. One upon creation of the VM, then another once I start the VM. The second one that it grabs is the one that the VM ends up using, and disappears from netbox once I remove the VM. But the initial IP that it grabs when the VM is created, needs to be manually removed from netbox to free up an address. Otherwise its falsely taking up an IP that otherwise should be free to use from the pool.

I'm not sure what versions of PVE or Netbox you are using, but I just updated mine -
PVE: 8.2.7
Netbox: 4.1.1
 
I did a little debugging and I think the bug is caused because this return statement has the wrong scope.
I'm by no means a perl expert but from what I understand this doesn't actually returns the ip value from the add_range_next_freeip subroutine.

This should fix it:
Git:
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..124c355 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 {
@@ -174,7 +176,7 @@ sub add_range_next_freeip {
 
     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 +186,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 {

We still have to manually add IP Ranges to Netbox right?

Thanks
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!