feat(vm): hoàn tiền khi cấp VM lỗi, theo dõi job queue, uuid dịch vụ cho ticket, chuẩn hoá RAM addon
- 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>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
7136bec265
commit
62596d9063
@@ -51,90 +51,59 @@ class VMJobs implements ShouldQueue
|
||||
|
||||
$vcenter = $product->IpAddress->Host->Datacenter->vCenter;
|
||||
$serviceVCenter->setConnection($vcenter->host, $vcenter->token);
|
||||
$vmwareId = $product->vmware_id;
|
||||
$VirtualMachineStatus = null;
|
||||
$status = 1;
|
||||
|
||||
switch ($this->action) {
|
||||
case "Suspend":
|
||||
$VirtualMachineStatus = $serviceVCenter->SuspendVirtualMachine($product->vmware_id);
|
||||
if ($VirtualMachineStatus === "Login_Again") {
|
||||
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
|
||||
if ($token) {
|
||||
vCenter::where('id', $product->IpAddress->Host->Datacenter->vCenter->id)->update(['token' => $token]);
|
||||
$serviceVCenter->token = $token;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->SuspendVirtualMachine($product->vmware_id);
|
||||
$call = function (callable $action) use ($serviceVCenter, $vcenter) {
|
||||
$result = $action();
|
||||
if ($result === 'Login_Again') {
|
||||
$token = $serviceVCenter->loginServer($vcenter);
|
||||
if ($token) {
|
||||
vCenter::where('id', $vcenter->id)->update(['token' => $token]);
|
||||
$serviceVCenter->token = $token;
|
||||
}
|
||||
$result = $action();
|
||||
}
|
||||
|
||||
return $result;
|
||||
};
|
||||
|
||||
$powerState = fn () => $call(fn () => $serviceVCenter->CheckVirtualMachine($vmwareId))['power_state'] ?? null;
|
||||
|
||||
switch ($this->action) {
|
||||
case 'Suspend':
|
||||
$VirtualMachineStatus = $call(fn () => $serviceVCenter->SuspendVirtualMachine($vmwareId));
|
||||
$status = 2;
|
||||
break;
|
||||
|
||||
case "Reboot":
|
||||
$VirtualMachineStatus = $serviceVCenter->RebootVirtualMachine($product->vmware_id);
|
||||
if ($VirtualMachineStatus === "Login_Again") {
|
||||
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
|
||||
if ($token) {
|
||||
vCenter::where('id', $product->IpAddress->Host->Datacenter->vCenter->id)->update(['token' => $token]);
|
||||
$serviceVCenter->token = $token;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->RebootVirtualMachine($product->vmware_id);
|
||||
case 'Reboot':
|
||||
$VirtualMachineStatus = $call(fn () => $serviceVCenter->RebootVirtualMachine($product, $vmwareId));
|
||||
break;
|
||||
|
||||
case 'Start':
|
||||
if ($powerState() !== 'POWERED_ON') {
|
||||
$VirtualMachineStatus = $call(fn () => $serviceVCenter->StartVirtualMachine($product, $vmwareId));
|
||||
}
|
||||
break;
|
||||
|
||||
case "Start":
|
||||
$VirtualMachineStatus = $serviceVCenter->CheckVirtualMachine($product->vmware_id);
|
||||
if ($VirtualMachineStatus === "Login_Again") {
|
||||
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
|
||||
if ($token) {
|
||||
vCenter::where('id', $product->IpAddress->Host->Datacenter->vCenter->id)->update(['token' => $token]);
|
||||
$serviceVCenter->token = $token;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->CheckVirtualMachine($product->vmware_id);
|
||||
}
|
||||
if ($VirtualMachineStatus['data']['operations_ready'] === true) {
|
||||
break;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->StartVirtualMachine($product->vmware_id);
|
||||
break;
|
||||
|
||||
case "ShutdownGuest":
|
||||
$VirtualMachineStatus = $serviceVCenter->CheckVirtualMachine($product->vmware_id);
|
||||
if ($VirtualMachineStatus === "Login_Again") {
|
||||
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
|
||||
if ($token) {
|
||||
vCenter::where('id', $product->IpAddress->Host->Datacenter->vCenter->id)->update(['token' => $token]);
|
||||
$serviceVCenter->token = $token;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->CheckVirtualMachine($product->vmware_id);
|
||||
}
|
||||
if ($VirtualMachineStatus['data']['operations_ready'] === false) {
|
||||
$status = 0;
|
||||
break;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->ShutdownGuestVirtualMachine($product->vmware_id);
|
||||
case 'ShutdownGuest':
|
||||
$status = 0;
|
||||
if ($powerState() !== 'POWERED_OFF') {
|
||||
$VirtualMachineStatus = $call(fn () => $serviceVCenter->ShutdownGuestVirtualMachine($product, $vmwareId));
|
||||
}
|
||||
break;
|
||||
|
||||
case "PowerOff":
|
||||
$VirtualMachineStatus = $serviceVCenter->CheckVirtualMachine($product->vmware_id);
|
||||
if ($VirtualMachineStatus === "Login_Again") {
|
||||
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
|
||||
if ($token) {
|
||||
vCenter::where('id', $product->IpAddress->Host->Datacenter->vCenter->id)->update(['token' => $token]);
|
||||
$serviceVCenter->token = $token;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->CheckVirtualMachine($product->vmware_id);
|
||||
}
|
||||
if ($VirtualMachineStatus['data']['operations_ready'] === false) {
|
||||
$status = 0;
|
||||
break;
|
||||
}
|
||||
$VirtualMachineStatus = $serviceVCenter->PowerOffVirtualMachine($product->vmware_id);
|
||||
case 'PowerOff':
|
||||
$status = 0;
|
||||
if ($powerState() !== 'POWERED_OFF') {
|
||||
$VirtualMachineStatus = $call(fn () => $serviceVCenter->PowerOffVirtualMachine($vmwareId));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($VirtualMachineStatus && $VirtualMachineStatus['error']) {
|
||||
throw new \Exception(json_encode($VirtualMachineStatus['data']));
|
||||
if (is_array($VirtualMachineStatus) && ($VirtualMachineStatus['error'] ?? false)) {
|
||||
throw new \Exception(json_encode($VirtualMachineStatus['data'] ?? $VirtualMachineStatus));
|
||||
}
|
||||
|
||||
if ($this->update) {
|
||||
|
||||
Reference in New Issue
Block a user