Refactor deployment process and enhance VM IP reservation logic; update email template for VM creation failure notifications
This commit is contained in:
@@ -24,18 +24,18 @@ class VmIpReservationService
|
||||
public function reserve(int $networkId, int $hostId, string $dns): ?array
|
||||
{
|
||||
return DB::transaction(function () use ($networkId, $hostId, $dns) {
|
||||
// ponytail: exclude only IPs with an actual VM assigned, not stale __pending__ reservations
|
||||
$usedIps = ModuleIpAddress::where('module_network_id', $networkId)
|
||||
->where('vm_name', '!=', '__pending__')
|
||||
// Exclude IPs that have any active reservation (real VM or pending).
|
||||
// Also accept status='reserved' in ip_pools so stale reservations
|
||||
// (ip_pool row stuck as 'reserved' with no matching module_ip_addresses row)
|
||||
// are recoverable without manual DB cleanup.
|
||||
$allUsedIps = ModuleIpAddress::where('module_network_id', $networkId)
|
||||
->lockForUpdate()
|
||||
->pluck('ip')
|
||||
->toArray();
|
||||
|
||||
$ipPool = IpPool::where('module_network_id', $networkId)
|
||||
->where('status', 'free')
|
||||
->whereNotNull('gateway')
|
||||
->where('gateway', '!=', '')
|
||||
->whereNotIn('ip_address', $usedIps)
|
||||
->whereIn('status', ['free', 'reserved'])
|
||||
->whereNotIn('ip_address', $allUsedIps)
|
||||
->lockForUpdate()
|
||||
->inRandomOrder()
|
||||
->first();
|
||||
|
||||
Reference in New Issue
Block a user