Signed-off-by: Alexandre Derumier <[email protected]>
---
 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


_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to