$this->moduleVmwareId, 'vm_id' => $this->vmId, 'os_family' => $this->osFamily, ]); $vcenter = vCenter::first(); if (!$vcenter) { throw new \RuntimeException('No vCenter record found in module_vcenter'); } $output = $ssh->changePasswordCustomer( vmId: $this->vmId, newPassword: $this->newPassword, currentGuestPassword: $this->currentGuestPassword, osFamily: $this->osFamily, vcenterHost: $vcenter->host, vcenterUser: $vcenter->user, vcenterPassword: SignRSA::DecryptFunc($vcenter->password), ); $this->assertSuccess($output); // Persist encrypted password to DB $provision->updatePassword($this->moduleVmwareId, $this->newPassword); $this->notifyCustomer(); Log::info('ChangeVmPasswordJob: password changed successfully', [ 'module_vmware_id' => $this->moduleVmwareId, 'vm_id' => $this->vmId, ]); } public function failed(\Throwable $e): void { Log::error('ChangeVmPasswordJob: all retries exhausted', [ 'module_vmware_id' => $this->moduleVmwareId, 'vm_id' => $this->vmId, 'error' => $e->getMessage(), ]); } private function notifyCustomer(): void { $vm = ModuleVmware::with('customer')->find($this->moduleVmwareId); if (!$vm?->customer?->email) { return; } Mail::to($vm->customer->email)->queue(new VmPasswordChanged([ 'fullname' => $vm->customer->fullname, 'vm_name' => $vm->name, 'newPassword' => $this->newPassword, ])); } private function assertSuccess(string $output): void { if (str_contains(strtoupper(trim($output)), 'SUCCESS')) { return; } throw new \RuntimeException( "Password change script failed for VM {$this->vmId}. Output: " . trim($output) ); } }