* [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options
@ 2025-04-08 13:25 Stefan Hanreich
2025-04-08 13:29 ` Thomas Lamprecht
2025-04-08 13:37 ` Thomas Lamprecht
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Hanreich @ 2025-04-08 13:25 UTC (permalink / raw)
To: pve-devel
The hostname provided to the methods in the IPAM plugins is empty for
VMs that do not have a name set. We always included the dns_name key
in the request, even if it was undefined, which leads Netbox to return
a 400 Bad Request error. With this patch we omit the dns_name
parameter if it isn't set, so the call succeeds.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/Network/SDN/Ipams/NetboxPlugin.pm | 36 +++++++++++++++--------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index a691323..97a0c3f 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -206,11 +206,14 @@ sub add_ip {
}
eval {
- netbox_api_request($plugin_config, "POST", "/ipam/ip-addresses/", {
+ my $params = {
address => "$ip/$mask",
- dns_name => $hostname,
description => $description,
- });
+ };
+
+ $params->{dns_name} = $hostname if $hostname;
+
+ netbox_api_request($plugin_config, "POST", "/ipam/ip-addresses/", $params);
};
if ($@) {
@@ -244,11 +247,14 @@ sub update_ip {
}
eval {
- netbox_api_request($plugin_config, "PATCH", "/ipam/ip-addresses/$ip_id/", {
+ my $params = {
address => "$ip/$mask",
- dns_name => $hostname,
description => $description,
- });
+ };
+
+ $params->{dns_name} = $hostname if $hostname;
+
+ netbox_api_request($plugin_config, "PATCH", "/ipam/ip-addresses/$ip_id/", $params);
};
if ($@) {
die "error update ip $ip : $@" if !$noerr;
@@ -272,10 +278,13 @@ sub add_next_freeip {
$description = "mac:$mac" if $mac;
my $ip = eval {
- my $result = netbox_api_request($plugin_config, "POST", "/ipam/prefixes/$internalid/available-ips/", {
- dns_name => $hostname,
+ my $params = {
description => $description,
- });
+ };
+
+ $params->{dns_name} = $hostname if $hostname;
+
+ my $result = netbox_api_request($plugin_config, "POST", "/ipam/prefixes/$internalid/available-ips/", $params);
my ($ip, undef) = split(/\//, $result->{address});
return $ip;
@@ -303,10 +312,13 @@ sub add_range_next_freeip {
$description = "mac:$data->{mac}" if $data->{mac};
my $ip = eval {
- my $result = netbox_api_request($plugin_config, "POST", "/ipam/ip-ranges/$internalid/available-ips/", {
- dns_name => $data->{hostname},
+ my $params = {
description => $description,
- });
+ };
+
+ $params->{dns_name} = $data->{hostname} if $data->{hostname};
+
+ my $result = netbox_api_request($plugin_config, "POST", "/ipam/ip-ranges/$internalid/available-ips/", $params);
my ($ip, undef) = split(/\//, $result->{address});
print "found ip free $ip in range $range->{'start-address'}-$range->{'end-address'}\n" if $ip;
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options
2025-04-08 13:25 [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options Stefan Hanreich
@ 2025-04-08 13:29 ` Thomas Lamprecht
2025-04-08 13:32 ` Stefan Hanreich
2025-04-08 13:37 ` Thomas Lamprecht
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Lamprecht @ 2025-04-08 13:29 UTC (permalink / raw)
To: Proxmox VE development discussion, Stefan Hanreich
Am 08.04.25 um 15:25 schrieb Stefan Hanreich:
> The hostname provided to the methods in the IPAM plugins is empty for
> VMs that do not have a name set. We always included the dns_name key
> in the request, even if it was undefined, which leads Netbox to return
> a 400 Bad Request error. With this patch we omit the dns_name
> parameter if it isn't set, so the call succeeds.
We default to "CT${VMID}" and "VM${VMID}" in that case though everywhere
such a hostname is required, that does not make sense here, or?
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options
2025-04-08 13:29 ` Thomas Lamprecht
@ 2025-04-08 13:32 ` Stefan Hanreich
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hanreich @ 2025-04-08 13:32 UTC (permalink / raw)
To: Thomas Lamprecht, Proxmox VE development discussion
On 4/8/25 15:29, Thomas Lamprecht wrote:
> Am 08.04.25 um 15:25 schrieb Stefan Hanreich:
>> The hostname provided to the methods in the IPAM plugins is empty for
>> VMs that do not have a name set. We always included the dns_name key
>> in the request, even if it was undefined, which leads Netbox to return
>> a 400 Bad Request error. With this patch we omit the dns_name
>> parameter if it isn't set, so the call succeeds.
>
> We default to "CT${VMID}" and "VM${VMID}" in that case though everywhere
> such a hostname is required, that does not make sense here, or?
That doesn't seem to be the case currently, at least during my tests. I
could look into solving it that way, if that's preferred.
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options
2025-04-08 13:25 [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options Stefan Hanreich
2025-04-08 13:29 ` Thomas Lamprecht
@ 2025-04-08 13:37 ` Thomas Lamprecht
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2025-04-08 13:37 UTC (permalink / raw)
To: pve-devel, Stefan Hanreich
On Tue, 08 Apr 2025 15:25:17 +0200, Stefan Hanreich wrote:
> The hostname provided to the methods in the IPAM plugins is empty for
> VMs that do not have a name set. We always included the dns_name key
> in the request, even if it was undefined, which leads Netbox to return
> a 400 Bad Request error. With this patch we omit the dns_name
> parameter if it isn't set, so the call succeeds.
>
>
> [...]
Applied, thanks!
[1/1] ipam: netbox: fix adding vms without a name set in the options
commit: 3ede261b255263ba79a63446305ba0a0f408592c
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-08 13:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-08 13:25 [pve-devel] [PATCH pve-network 1/1] ipam: netbox: fix adding vms without a name set in the options Stefan Hanreich
2025-04-08 13:29 ` Thomas Lamprecht
2025-04-08 13:32 ` Stefan Hanreich
2025-04-08 13:37 ` Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal