Sorry, I didn't have time. I will try next week.@spirit Have you had a chance to test with 4.X yet?
Sorry, I didn't have time. I will try next week.@spirit Have you had a chance to test with 4.X yet?
ip
value from the add_range_next_freeip
subroutine.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 theip
value from theadd_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!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 theip
value from theadd_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 {
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.
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.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.
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 theip
value from theadd_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 {