From: Stefan Hanreich <s.hanreich@proxmox.com>
To: nurohman <me@nurohman.com>, pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [PATCH pve-network] Fix #5496: NetBox add ip range
Date: Thu, 12 Dec 2024 14:20:00 +0100 [thread overview]
Message-ID: <f782eb4b-d940-48a9-8e07-0d96807f590d@proxmox.com> (raw)
In-Reply-To: <20241211233832.806187-1-me@nurohman.com>
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
next parent reply other threads:[~2024-12-12 13:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241211233832.806187-1-me@nurohman.com>
2024-12-12 13:20 ` Stefan Hanreich [this message]
2024-12-11 23:38 nurohman via pve-devel
2024-12-12 7:20 ` DERUMIER, Alexandre via pve-devel
2024-12-13 9:55 ` Lou Lecrivain via pve-devel
[not found] ` <b6d41bd46ba97b50da21589f2ea676ab34cac339.camel@groupe-cyllene.com>
2024-12-12 13:17 ` Stefan Hanreich
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=f782eb4b-d940-48a9-8e07-0d96807f590d@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=me@nurohman.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox