ExecuteQemuShellWith attempts to connect to a QEMU VM using SSH with custom execution context. This function provides full control over the execution context and command executor for connecting directly to QEMU VMs via SSH. The function automatically sets TERM=xterm-256color for better terminal co
(ctx context.Context, execer CommandExecutor, user, vmIP string, jumphost config.SSHJumpHost)
| 311 | // |
| 312 | // Returns an error if the VM IP is empty or if the SSH connection fails. |
| 313 | func ExecuteQemuShellWith(ctx context.Context, execer CommandExecutor, user, vmIP string, jumphost config.SSHJumpHost) error { |
| 314 | if vmIP == "" { |
| 315 | return fmt.Errorf("no IP address available for VM") |
| 316 | } |
| 317 | |
| 318 | args := buildSSHArgs(user, vmIP, jumphost) |
| 319 | sshLogger().Debug("SSH QEMU shell: user=%s host=%s jumphost=%+v args=%v", user, vmIP, jumphost, args) |
| 320 | sshCmd := execer.CommandContext(ctx, "ssh", args...) |
| 321 | sshCmd.Stdin = os.Stdin |
| 322 | sshCmd.Stdout = os.Stdout |
| 323 | sshCmd.Stderr = os.Stderr |
| 324 | |
| 325 | // Set environment variables for better terminal compatibility |
| 326 | // Override TERM to xterm-256color for better compatibility with remote systems |
| 327 | // This fixes issues with terminals like Kitty (xterm-kitty) that aren't recognized on all systems |
| 328 | sshCmd.Env = append(os.Environ(), "TERM=xterm-256color") |
| 329 | |
| 330 | // Execute command using the current process environment and stdin/stdout |
| 331 | err := sshCmd.Run() |
| 332 | |
| 333 | // Show completion status and wait for user input before returning |
| 334 | utils.WaitForEnterToReturn(err, "VM SSH session completed successfully", "VM SSH session ended with error") |
| 335 | |
| 336 | if err != nil { |
| 337 | return fmt.Errorf("failed to connect to VM via SSH: %w", err) |
| 338 | } |
| 339 | |
| 340 | return nil |
| 341 | } |
| 342 | |
| 343 | func buildSSHArgs(user, host string, jumphost config.SSHJumpHost) []string { |
| 344 | return buildSSHArgsBase(user, host, jumphost) |
no test coverage detected