- VmProvisionException/VmProvisionRefund xử lý lỗi cấp phát VM - QueueJobInspector + QueueMonitorController xem chi tiết job - Thêm service uuid cho ticket, thời lượng cho activity_logs - Migration chuẩn hoá RAM addon sang MB, trạng thái deleting cho snapshot Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
2.0 KiB
PHP
52 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\VirtualMachine;
|
|
|
|
use App\Models\ModuleVmware;
|
|
use App\Models\OrderItem;
|
|
use App\Services\VirtualMachine\Dto\VmInfrastructureContext;
|
|
use App\Services\VmProvisionService;
|
|
|
|
class VmModuleService
|
|
{
|
|
/**
|
|
* Create ModuleVmware shell. IP and final password are filled in later
|
|
* by AssignIpToGuestJob → ChangePasswordViaVsphereJob.
|
|
*/
|
|
public function create(OrderItem $item, VmInfrastructureContext $infra, string $vmId, array $specs = []): ModuleVmware
|
|
{
|
|
$customer = $item->order->customer;
|
|
$serverName = $item->server_name ?? ('VM-' . $vmId);
|
|
|
|
$months = (int) ($item->months ?? 0);
|
|
$firstPayment = (int) $item->price * ($months ?: 1);
|
|
$nextDueDate = $months > 0 ? now()->addMonths($months)->timestamp : null;
|
|
|
|
return ModuleVmware::create([
|
|
'name' => $serverName,
|
|
'module_ip_address' => null,
|
|
'ip' => null,
|
|
'port' => $infra->vmPort,
|
|
'order_id' => $item->order->id,
|
|
'first_payment' => $firstPayment,
|
|
'next_payment' => $firstPayment,
|
|
'next_due_date' => $nextDueDate,
|
|
'next_invoice' => $nextDueDate,
|
|
'user' => $infra->vmUser,
|
|
'password' => VmProvisionService::templatePassword(),
|
|
'plain_password' => VmProvisionService::templatePassword(),
|
|
'hostname' => $serverName,
|
|
'vmware_id' => $vmId,
|
|
'vcenter_id' => $infra->vcenter->id,
|
|
'os_id' => $item->os_id ?? 1,
|
|
'customer_id' => $customer->id,
|
|
'status' => 1,
|
|
'cpu' => $specs['cpu'] ?? null,
|
|
'ram_mb' => $specs['ram_mb'] ?? null,
|
|
'disk_gb' => $specs['disk_gb'] ?? null,
|
|
]);
|
|
}
|
|
}
|