update rm deadcode
This commit is contained in:
@@ -74,6 +74,53 @@ class VmIpReservationService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve a specific, still-free IP within a network (customer-picked change-IP flow).
|
||||
*
|
||||
* @return array{ip_pool_id:int, gateway:string}|null
|
||||
*/
|
||||
public function reserveInNetwork(int $networkId, string $ipAddress, int $serviceId): ?array
|
||||
{
|
||||
return DB::transaction(function () use ($networkId, $ipAddress, $serviceId) {
|
||||
$ipPool = IpPool::where('module_network_id', $networkId)
|
||||
->where('ip_address', $ipAddress)
|
||||
->where('status', 'free')
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if (!$ipPool) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ipPool->update(['status' => 'assigned', 'service_id' => $serviceId]);
|
||||
|
||||
return [
|
||||
'ip_pool_id' => $ipPool->id,
|
||||
'gateway' => (string) ($ipPool->gateway ?? ''),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function freeIpsInNetwork(int $networkId)
|
||||
{
|
||||
return IpPool::where('module_network_id', $networkId)
|
||||
->where('status', 'free')
|
||||
->orderBy('ip_address')
|
||||
->get(['id', 'ip_address', 'gateway']);
|
||||
}
|
||||
|
||||
public function releaseByPoolId(int $ipPoolId): void
|
||||
{
|
||||
try {
|
||||
IpPool::where('id', $ipPoolId)->update(['status' => 'free', 'service_id' => null]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('VmIpReservationService: releaseByPoolId failed', [
|
||||
'ip_pool_id' => $ipPoolId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function release(ModuleIpAddress $reservation, ?int $ipPoolId): void
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user