Refactor VM creation and configuration process
- Updated VpsServiceResource to return product UUID instead of ID. - Modified VirtualMachineService to utilize product data for CPU, RAM, and disk settings. - Replaced AssignIpToGuestJob with UpdateVmConfigJob in CreateVirtualMachineJob to streamline VM configuration after cloning. - Adjusted AssignIpToGuestJob to remove unnecessary UpdateVmConfigJob dispatch and focus on IP assignment. - Enhanced UpdateVmConfigJob to handle CPU/RAM configuration and power cycling more effectively. - Introduced ChangeIpVMJob for handling customer-initiated IP changes asynchronously. - Updated InvoiceRepository to set invoice due date based on maximum months instead of a fixed 7 days. - Improved web design quote PDF layout for better readability. - Added Times-Roman font metrics for PDF generation.
This commit is contained in:
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Jobs\VirtualMachine\Create;
|
||||
|
||||
use App\Http\Services\vCenter;
|
||||
use App\Jobs\VirtualMachine\Provision\AssignIpToGuestJob;
|
||||
use App\Jobs\VirtualMachine\Provision\UpdateVmConfigJob;
|
||||
use App\Models\OrderItem;
|
||||
use App\Models\VmProvisionLock;
|
||||
use App\Services\VirtualMachine\VmAddonResolver;
|
||||
@@ -13,7 +13,6 @@ use App\Services\VirtualMachine\VmInfrastructureResolver;
|
||||
use App\Services\VirtualMachine\VmIpReservationService;
|
||||
use App\Services\VirtualMachine\VmModuleService;
|
||||
use App\Services\VirtualMachine\VmNotificationService;
|
||||
use App\Services\VirtualMachine\VmPowerService;
|
||||
use App\Services\VirtualMachine\VmProvisionLogger;
|
||||
use App\Services\VirtualMachine\VmServiceSyncService;
|
||||
use App\Services\VirtualMachine\VmVcenterErrorTranslator;
|
||||
@@ -47,7 +46,6 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
VmProvisionLogger $vmLogger,
|
||||
VmInfrastructureResolver $infraResolver,
|
||||
VmAddonResolver $addonResolver,
|
||||
VmPowerService $powerService,
|
||||
VmModuleService $moduleService,
|
||||
VmServiceSyncService $serviceSync,
|
||||
VmNotificationService $notification,
|
||||
@@ -131,6 +129,7 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
$result = $vCenter->CreateVirtualMachine([
|
||||
'item' => $this->item,
|
||||
'product' => $product,
|
||||
'host' => $infra->host,
|
||||
'datacenter' => $infra->datacenter,
|
||||
'vcenter' => $infra->vcenter,
|
||||
@@ -162,21 +161,6 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
'vm_id' => $vmId,
|
||||
]);
|
||||
|
||||
$vmLogger->step('VM start started', ['vm_id' => $vmId]);
|
||||
|
||||
$startResult = $powerService->start($vCenter, $vmId);
|
||||
|
||||
if (is_array($startResult) && ($startResult['error'] ?? false)) {
|
||||
throw new RuntimeException(
|
||||
'Start VM thất bại: ' . json_encode($startResult['data'] ?? null)
|
||||
);
|
||||
}
|
||||
if ($startResult === 'Login_Again') {
|
||||
throw new RuntimeException('Start VM thất bại: cần đăng nhập lại vCenter.');
|
||||
}
|
||||
|
||||
$vmLogger->success('VM start success', ['vm_id' => $vmId]);
|
||||
|
||||
$moduleVmware = $moduleService->create($this->item, $infra, $vmId);
|
||||
|
||||
$vmLogger->success('ModuleVmware created', [
|
||||
@@ -191,16 +175,19 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
'order_item_id' => $this->item->id,
|
||||
]);
|
||||
|
||||
AssignIpToGuestJob::dispatch(
|
||||
// VM is left powered off after clone. UpdateVmConfigJob owns power-on:
|
||||
// if the order has a CPU/RAM addon it powers off (no-op, already off),
|
||||
// resizes, then powers on; otherwise it just powers on. Either way it
|
||||
// dispatches AssignIpToGuestJob next, which needs the VM running.
|
||||
UpdateVmConfigJob::dispatch(
|
||||
$moduleVmware->id,
|
||||
(string) $vmId,
|
||||
$infra->isWindows ? VmProvisionService::OS_WINDOWS : VmProvisionService::OS_LINUX,
|
||||
VmProvisionService::TEMPLATE_PASSWORD,
|
||||
$reservation->id,
|
||||
$ipPoolId,
|
||||
reservationId: $reservation->id,
|
||||
reservedIpPoolId: $ipPoolId,
|
||||
)->onQueue('default');
|
||||
|
||||
$vmLogger->success('AssignIpToGuestJob dispatched', [
|
||||
$vmLogger->success('UpdateVmConfigJob dispatched', [
|
||||
'module_vmware_id' => $moduleVmware->id,
|
||||
'vm_id' => $vmId,
|
||||
'os_family' => $infra->isWindows ? 'WINDOWS' : 'LINUX',
|
||||
|
||||
Reference in New Issue
Block a user