diff --git a/app/Services/VirtualMachine/VmIpReservationService.php b/app/Services/VirtualMachine/VmIpReservationService.php index f1da6c9..b999181 100644 --- a/app/Services/VirtualMachine/VmIpReservationService.php +++ b/app/Services/VirtualMachine/VmIpReservationService.php @@ -31,6 +31,7 @@ class VmIpReservationService return DB::transaction(function () use ($networkId, $hostId, $dns) { // ip_pools.status is the single source of truth for availability. $ipPool = $this->availableIps() + ->where('module_network_id', $networkId) ->lockForUpdate() ->inRandomOrder() ->first(); @@ -48,6 +49,7 @@ class VmIpReservationService // module_ip_address mirrors ip_pools — update the existing synced row // (created when the IP was added to ip_pools) instead of inserting a new one. $reservation = ModuleIpAddress::where('ip', $ipPool->ip_address) + ->where('module_network_id', $networkId) ->lockForUpdate() ->first(); @@ -107,6 +109,7 @@ class VmIpReservationService private function availableIps() { return IpPool::whereIn('status', ['free', 'reserved']) + ->whereNotNull('module_network_id') ->whereNotNull('gateway') ->where('gateway', '!=', ''); }