diff --git a/app/Services/VsphereHostSshService.php b/app/Services/VsphereHostSshService.php index 4c8eb1e..2299cc7 100644 --- a/app/Services/VsphereHostSshService.php +++ b/app/Services/VsphereHostSshService.php @@ -58,24 +58,13 @@ final class VsphereHostSshService : self::SCRIPT_LINUX; $powerCliVmId = $this->powerCliVmId($vmId); - $remoteCmd = strtoupper($osFamily) === VmProvisionService::OS_WINDOWS - ? $this->windowsPowerShellCommand(self::SCRIPT_DIR, $script, [ - $powerCliVmId, - $newPassword, - $vcenterHost, - $vcenterUser, - $vcenterPassword, - ]) - : sprintf( - 'cd %s && powershell -ExecutionPolicy Bypass -NonInteractive -File %s %s %s %s %s %s', - self::SCRIPT_DIR, - $script, - $this->warg($powerCliVmId), - $this->warg($newPassword), - $this->warg($vcenterHost), - $this->warg($vcenterUser), - $this->warg($vcenterPassword), - ); + $remoteCmd = $this->windowsPowerShellCommand(self::SCRIPT_DIR, $script, [ + $powerCliVmId, + $newPassword, + $vcenterHost, + $vcenterUser, + $vcenterPassword, + ]); Log::info('VsphereHostSshService: executing script', [ 'vm_id' => $vmId, @@ -121,30 +110,16 @@ final class VsphereHostSshService $script = $isWindows ? self::SCRIPT_ASSIGN_WINDOWS : self::SCRIPT_ASSIGN_LINUX; $powerCliVmId = $this->powerCliVmId($vmId); - $remoteCmd = $isWindows - ? $this->windowsPowerShellCommand(self::ASSIGN_DIR, $script, [ - $powerCliVmId, - $ip, - $gateway, - $cidr, - $vcenterHost, - $vcenterUser, - $vcenterPassword, - $guestPassword, - ]) - : sprintf( - 'cd %s && powershell -ExecutionPolicy Bypass -NonInteractive -File %s %s %s %s %s %s %s %s %s', - self::ASSIGN_DIR, - $script, - $this->warg($powerCliVmId), - $this->warg($ip), - $this->warg($gateway), - $this->warg($cidr), - $this->warg($vcenterHost), - $this->warg($vcenterUser), - $this->warg($vcenterPassword), - $this->warg($guestPassword), - ); + $remoteCmd = $this->windowsPowerShellCommand(self::ASSIGN_DIR, $script, [ + $powerCliVmId, + $ip, + $gateway, + $cidr, + $vcenterHost, + $vcenterUser, + $vcenterPassword, + $guestPassword, + ]); Log::info('VsphereHostSshService: executing assignIp', [ 'vm_id' => $vmId, @@ -188,26 +163,14 @@ final class VsphereHostSshService $script = $isWindows ? self::SCRIPT_VERIFY_WINDOWS : self::SCRIPT_VERIFY_LINUX; $powerCliVmId = $this->powerCliVmId($vmId); - $remoteCmd = $isWindows - ? $this->windowsPowerShellCommand(self::ASSIGN_DIR, $script, [ - $powerCliVmId, - $ip, - $vcenterHost, - $vcenterUser, - $vcenterPassword, - $guestPassword, - ]) - : sprintf( - 'cd %s && powershell -ExecutionPolicy Bypass -NonInteractive -File %s %s %s %s %s %s %s', - self::ASSIGN_DIR, - $script, - $this->warg($powerCliVmId), - $this->warg($ip), - $this->warg($vcenterHost), - $this->warg($vcenterUser), - $this->warg($vcenterPassword), - $this->warg($guestPassword), - ); + $remoteCmd = $this->windowsPowerShellCommand(self::ASSIGN_DIR, $script, [ + $powerCliVmId, + $ip, + $vcenterHost, + $vcenterUser, + $vcenterPassword, + $guestPassword, + ]); Log::info('VsphereHostSshService: executing verifyIpInGuest', [ 'vm_id' => $vmId, @@ -321,26 +284,14 @@ final class VsphereHostSshService : self::SCRIPT_CHANGE_PWD_LINUX; $powerCliVmId = $this->powerCliVmId($vmId); - $remoteCmd = strtoupper($osFamily) === VmProvisionService::OS_WINDOWS - ? $this->windowsPowerShellCommand(self::CHANGE_PWD_DIR, $script, [ - $powerCliVmId, - $newPassword, - $vcenterHost, - $vcenterUser, - $vcenterPassword, - $currentGuestPassword, - ]) - : sprintf( - 'cd %s && powershell -ExecutionPolicy Bypass -NonInteractive -File %s %s %s %s %s %s %s', - self::CHANGE_PWD_DIR, - $script, - $this->warg($powerCliVmId), - $this->warg($newPassword), - $this->warg($vcenterHost), - $this->warg($vcenterUser), - $this->warg($vcenterPassword), - $this->warg($currentGuestPassword), - ); + $remoteCmd = $this->windowsPowerShellCommand(self::CHANGE_PWD_DIR, $script, [ + $powerCliVmId, + $newPassword, + $vcenterHost, + $vcenterUser, + $vcenterPassword, + $currentGuestPassword, + ]); Log::info('VsphereHostSshService: changePasswordCustomer', [ 'vm_id' => $vmId, @@ -366,7 +317,7 @@ final class VsphereHostSshService private function windowsPowerShellCommand(string $workingDirectory, string $script, array $arguments): string { return sprintf( - 'cd %s && powershell -ExecutionPolicy Bypass -File %s %s', + 'powershell -ExecutionPolicy Bypass -NonInteractive -File "%s\\%s" %s', $workingDirectory, $script, implode(' ', array_map(