From: Fiona Ebner <f.ebner@proxmox.com>
To: 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 15:15:17 +0200 [thread overview]
Message-ID: <25ea7224-3d59-453c-8ecb-bf354b62b73f@proxmox.com> (raw)
In-Reply-To: <mailman.418.1753911405.367.pve-devel@lists.proxmox.com>
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.
> + }
> +
> + if ($count == 0) {
> + return;
> + }
> +
> + return $result->{results}[0]{id};
> }
>
> sub get_iprange_id {
> --
> 2.47.2
>
>
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-09-17 13:15 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 [this message]
2025-09-17 18:03 ` Trygve Laugstøl via pve-devel
[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=25ea7224-3d59-453c-8ecb-bf354b62b73f@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/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.