From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [pve-network 3/4] subnets: call add_range_next_freeip only if dhcp is defined
Date: Thu, 4 Jan 2024 17:27:32 +0100 [thread overview]
Message-ID: <20240104162733.4152467-6-aderumier@odiso.com> (raw)
In-Reply-To: <20240104162733.4152467-1-aderumier@odiso.com>
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
src/PVE/Network/SDN/Subnets.pm | 13 +++++++++----
src/PVE/Network/SDN/Vnets.pm | 4 ++--
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index 3b08dcd..4767850 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -206,7 +206,7 @@ sub del_subnet {
}
sub add_next_free_ip {
- my ($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns, $dhcprange) = @_;
+ my ($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns) = @_;
my $cidr = undef;
my $ip = undef;
@@ -227,15 +227,18 @@ sub add_next_free_ip {
my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
eval {
- if ($dhcprange) {
+
+ my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
+ if ($zone->{dhcp}) {
+
+ die "no dhcp_range are defined" if @$dhcp_ranges == 0;
+
my $data = {
mac => $mac,
hostname => $hostname,
vmid => $vmid,
};
- my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
-
foreach my $range (@$dhcp_ranges) {
$ip = $plugin->add_range_next_freeip($plugin_config, $subnet, $range, $data);
last if $ip;
@@ -247,6 +250,8 @@ sub add_next_free_ip {
die $@ if $@;
+ die "Can't find any free ip" if !$ip;
+
eval { PVE::Network::SDN::Ipams::add_cache_mac_ip($mac, $ip); };
warn $@ if $@;
}
diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 0268684..83b79dd 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -95,7 +95,7 @@ sub get_subnet_from_vnet_ip {
}
sub add_next_free_cidr {
- my ($vnetid, $hostname, $mac, $vmid, $skipdns, $dhcprange) = @_;
+ my ($vnetid, $hostname, $mac, $vmid, $skipdns) = @_;
my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
return if !$vnet;
@@ -121,7 +121,7 @@ sub add_next_free_cidr {
$subnetcount++;
eval {
- $ip = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns, $dhcprange);
+ $ip = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns);
};
die $@ if $@;
--
2.39.2
next prev parent reply other threads:[~2024-01-04 16:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [qemu-server 1/1] add_next_free_cidr: remove old dhcprange param Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-manager 1/1] sdn: zones: add ipam reservation option Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-network 1/4] vnets: use ipam without dhcp Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-network 2/4] vnets: add_next_free_cidr : skip if ipamreservation is not defined Alexandre Derumier
2024-01-04 16:27 ` Alexandre Derumier [this message]
2024-01-04 16:27 ` [pve-devel] [pve-network 4/4] api2: ipam status: display ipam zones without dhcp flag Alexandre Derumier
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=20240104162733.4152467-6-aderumier@odiso.com \
--to=aderumier@odiso.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