Refactor VM provisioning pipeline into focused services and add IP pool
management
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\VirtualMachine;
|
||||
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\OrderItem;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class VmServiceSyncService
|
||||
{
|
||||
/**
|
||||
* Sync module_vmware → services table.
|
||||
* Initial status is `provisioning`. Final `active` is set after IP + password
|
||||
* provisioning succeed, by downstream jobs.
|
||||
*/
|
||||
public function sync(ModuleVmware $moduleVmware, OrderItem $item): void
|
||||
{
|
||||
try {
|
||||
$months = (int) ($item->months ?? 0);
|
||||
$updated = Service::where('order_item_id', $item->id)
|
||||
->update([
|
||||
'vm_id' => $moduleVmware->id,
|
||||
'status' => 'provisioning',
|
||||
'expires_at' => $months > 0 ? now()->addMonths($months) : null,
|
||||
]);
|
||||
|
||||
Log::info('VmServiceSyncService: synced', [
|
||||
'module_vmware_id' => $moduleVmware->id,
|
||||
'order_item_id' => $item->id,
|
||||
'rows_updated' => $updated,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
Log::error('VmServiceSyncService: exception — ' . $e->getMessage(), [
|
||||
'module_vmware_id' => $moduleVmware->id,
|
||||
'order_item_id' => $item->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user