[pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
Stefan Hanreich
s.hanreich at proxmox.com
Thu Dec 12 14:20:00 CET 2024
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.
More information about the pve-devel
mailing list