From 1d40dfbb4452dec8baee33f66b818798c7d76bf8 Mon Sep 17 00:00:00 2001 From: baodev0 Date: Fri, 30 Oct 2026 11:56:35 +0700 Subject: [PATCH] =?UTF-8?q?fix(vm):=20kh=C3=B4i=20ph=E1=BB=A5c=20l?= =?UTF-8?q?=E1=BB=8Dc=20network=20khi=20gi=E1=BB=AF=20IP=20cho=20VM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reserve() không còn lấy IP ngoài network được chọn hoặc IP chưa gán network. Co-Authored-By: Claude Sonnet 5.5 --- app/Services/VirtualMachine/VmIpReservationService.php | 3 +++ 1 file changed, 3 insertions(+) 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', '!=', ''); }