update fix deadcode, security
This commit is contained in:
@@ -12,7 +12,6 @@ use App\Models\vCenter as VCenterModel;
|
||||
use App\Models\VirtualMachines;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* VmRebuildSwapService
|
||||
@@ -121,40 +120,4 @@ final class VmRebuildSwapService
|
||||
'new_vm_id' => $ctx->newVmId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the old VM from vCenter. Best-effort: the DB is already swapped,
|
||||
* so a leftover ghost VM is recoverable manually and must not throw past
|
||||
* the queue.
|
||||
*/
|
||||
public function deleteOldVm(RebuildContext $ctx): void
|
||||
{
|
||||
if ($ctx->oldVmId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$vcenter = VCenterModel::find($ctx->vcenterId);
|
||||
if (!$vcenter || !$this->vCenter->loginServer($vcenter)) {
|
||||
Log::error('VmRebuildSwapService: cannot login to delete old VM', [
|
||||
'old_vm_id' => $ctx->oldVmId,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Force power-off before delete to avoid "VM is running" rejection.
|
||||
$this->vCenter->PowerOffVirtualMachine($ctx->oldVmId);
|
||||
$res = $this->vCenter->DeleteVirtualMachine($ctx->oldVmId);
|
||||
|
||||
Log::info('VmRebuildSwapService: old VM deleted', [
|
||||
'old_vm_id' => $ctx->oldVmId,
|
||||
'result' => $res,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
Log::error('VmRebuildSwapService: deleteOldVm threw', [
|
||||
'old_vm_id' => $ctx->oldVmId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user