all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Trygve Laugstøl via pve-devel" <pve-devel@lists.proxmox.com>
To: "Fiona Ebner" <f.ebner@proxmox.com>,
	"Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Cc: "Trygve Laugstøl" <trygvis@inamo.no>
Subject: Re: [pve-devel] [PATCH pve-network 1/1] fix #6569: ipam: netbox: better prefix lookup
Date: Wed, 17 Sep 2025 20:03:25 +0200	[thread overview]
Message-ID: <mailman.130.1758132676.390.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <25ea7224-3d59-453c-8ecb-bf354b62b73f@proxmox.com>

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

From: "Trygve Laugstøl" <trygvis@inamo.no>
To: "Fiona Ebner" <f.ebner@proxmox.com>, "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH pve-network 1/1] fix #6569: ipam: netbox: better prefix lookup
Date: Wed, 17 Sep 2025 20:03:25 +0200
Message-ID: <b77fd4bf-7045-47c4-bed8-5d450cb61187@app.fastmail.com>

On Wed, Sep 17, 2025, at 15:15, Fiona Ebner wrote:
> Sorry about the very late response and thank you for the contribution!
>
> Am 30.07.25 um 11:36 PM schrieb Trygve Laugstøl via pve-devel:
>> The problem description in #6569 is correct, but instead of depending on the
>> freetext query parameter "q", this uses the "prefix" parameter for an explicit
>> lookup.
>> 
>> This also checks if there are multiple prefixes that matched. This will happen
>> if the same prefix is registered in multiple VRFs.
>> 
>> Signed-off-by: Trygve Laugstøl <trygvis@inamo.no>
>> ---
>>  src/PVE/Network/SDN/Ipams/NetboxPlugin.pm | 21 ++++++++++++++-------
>>  1 file changed, 14 insertions(+), 7 deletions(-)
>> 
>> diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
>> index e118d03..3799e47 100644
>> --- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
>> +++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
>> @@ -423,18 +423,25 @@ sub on_update_hook {
>>  sub get_prefix_id {
>>      my ($config, $cidr, $noerr) = @_;
>>  
>> -    # we need to supply any IP inside the prefix, without supplying the mask, so
>> -    # just take the one from the cidr
>> -    my ($ip, undef) = split(/\//, $cidr);
>> -
>> -    my $result = eval { netbox_api_request($config, "GET", "/ipam/prefixes/?q=$ip") };
>> +    # look up the prefix by matching the prefix exactly.
>> +    my $result = eval { netbox_api_request($config, "GET", "/ipam/prefixes/?prefix=$cidr") };
>>      if ($@) {
>>          return if $noerr;
>>          die "could not obtain ID for prefix $cidr: $@";
>>      }
>>  
>> -    my $data = @{ $result->{results} }[0];
>> -    return $data->{id};
>> +    # we can get multiple prefixes returned if the netbox configuration allows
>> +    # it, or if the prefix is registered in different VRFs.
>> +    my $count = $result->{count} || 0;
>> +    if ($count > 1) {
>> +        die "ambiguous prefix lookup for $cidr: found $count matches";
>
> Can't this break existing setups where there are multiple prefixes?
> Because the old code would just pick the first, but the new code would
> die rather than also picking the first.
>
> If we really want this, it should honor the $noerr parameter and return
> instead of die if $noerr is set.

The current one would pick the first, but also a random, inconsistent one. A better solution here would be to somehow include the VRF as a part of the lookup, but that requires a bigger expansion of the Netbox support than I'm prepared to do.

Also, the code doesn't handle missing prefixes well so if the prefix is removed on the Netbox side the current code will just not allow you to remove the subnet at all. But I guess that is another issue.

-- 
Trygve

>> +    }
>> +
>> +    if ($count == 0) {
>> +        return;
>> +    }
>> +
>> +    return $result->{results}[0]{id};
>>  }
>>  
>>  sub get_iprange_id {
>> -- 
>> 2.47.2
>> 
>>


[-- 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

  reply	other threads:[~2025-09-17 18:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250730212614.1264010-1-trygvis@inamo.no>
2025-07-30 21:26 ` Trygve Laugstøl via pve-devel
2025-09-17 13:15   ` Fiona Ebner
2025-09-17 18:03     ` Trygve Laugstøl via pve-devel [this message]
     [not found]     ` <b77fd4bf-7045-47c4-bed8-5d450cb61187@app.fastmail.com>
2025-09-18 10:07       ` Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mailman.130.1758132676.390.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=f.ebner@proxmox.com \
    --cc=trygvis@inamo.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal