update rm deadcode

This commit is contained in:
baodev0
2026-09-27 11:42:40 +07:00
parent 82a71244ca
commit 3af59bd9c5
129 changed files with 5194 additions and 2698 deletions
+28 -2
View File
@@ -7,6 +7,7 @@ namespace App\Jobs\VirtualMachine;
use App\Actions\VM\ChangeIpVMAction;
use App\Http\Services\Telegram;
use App\Models\ModuleVmware;
use App\Services\VirtualMachine\VmIpReservationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@@ -38,9 +39,11 @@ class ChangeIpVMJob implements ShouldQueue
public readonly string $dns,
public readonly string $guestUser,
public readonly string $guestPassword,
public readonly ?int $newIpPoolId = null,
public readonly ?int $oldIpPoolId = null,
) {}
public function handle(ChangeIpVMAction $action): void
public function handle(ChangeIpVMAction $action, VmIpReservationService $ipReservation): void
{
$vm = ModuleVmware::with([
'vCenter',
@@ -49,6 +52,9 @@ class ChangeIpVMJob implements ShouldQueue
if (!$vm) {
Log::error('[ChangeIpVMJob] ModuleVmware not found', ['module_vmware_id' => $this->moduleVmwareId]);
if ($this->newIpPoolId) {
$ipReservation->releaseByPoolId($this->newIpPoolId);
}
return;
}
@@ -62,6 +68,22 @@ class ChangeIpVMJob implements ShouldQueue
$this->guestPassword,
);
$failed = $raw === 'Login_Again'
|| $raw === 'vCenter_Not_Found'
|| str_starts_with((string) $raw, 'Error:')
|| str_contains((string) $raw, '[STDERR]');
if ($failed) {
if ($this->newIpPoolId) {
$ipReservation->releaseByPoolId($this->newIpPoolId);
}
} else {
$vm->update(['ip' => $this->ipAddress, 'dns' => $this->dns]);
if ($this->oldIpPoolId) {
$ipReservation->releaseByPoolId($this->oldIpPoolId);
}
}
Log::channel('Custom')->info('[ChangeIpVMJob] raw output', [
'module_vmware_id' => $this->moduleVmwareId,
'ip_address' => $this->ipAddress,
@@ -88,7 +110,7 @@ class ChangeIpVMJob implements ShouldQueue
return;
}
if (str_starts_with((string) $raw, 'Error:') || str_contains((string) $raw, '[STDERR]')) {
if ($failed) {
$telegram->SendErrorMessage("❌ Đổi IP thất bại [{$this->osType}]\n"
. "🖥 VM: {$vm->name} ({$vm->vmware_id})\n"
. "📍 IP mới: {$this->ipAddress}\n"
@@ -116,5 +138,9 @@ class ChangeIpVMJob implements ShouldQueue
'ip_address' => $this->ipAddress,
'error' => $e->getMessage(),
]);
if ($this->newIpPoolId) {
app(VmIpReservationService::class)->releaseByPoolId($this->newIpPoolId);
}
}
}