fix(vm): khôi phục lọc network khi giữ IP cho VM
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
62596d9063
commit
1d40dfbb44
@@ -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', '!=', '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user