From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id ECDBA1FF16B for ; Thu, 12 Dec 2024 14:20:00 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 94A251C21B; Thu, 12 Dec 2024 14:20:07 +0100 (CET) Message-ID: Date: Thu, 12 Dec 2024 14:20:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: nurohman , pve-devel@lists.proxmox.com References: <20241211233832.806187-1-me@nurohman.com> Content-Language: en-US From: Stefan Hanreich In-Reply-To: <20241211233832.806187-1-me@nurohman.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.660 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "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