ExecuteNodeShellWith opens an interactive SSH session to a Proxmox node with custom execution context. This function provides full control over the execution context and command executor, making it suitable for testing and advanced use cases. The function automatically sets TERM=xterm-256color for
(ctx context.Context, execer CommandExecutor, user, nodeIP string, jumphost config.SSHJumpHost)
| 125 | // |
| 126 | // Returns an error if the SSH connection fails. |
| 127 | func ExecuteNodeShellWith(ctx context.Context, execer CommandExecutor, user, nodeIP string, jumphost config.SSHJumpHost) error { |
| 128 | args := buildSSHArgs(user, nodeIP, jumphost) |
| 129 | sshLogger().Debug("SSH node shell: user=%s host=%s jumphost=%+v args=%v", user, nodeIP, jumphost, args) |
| 130 | sshCmd := execer.CommandContext(ctx, "ssh", args...) |
| 131 | sshCmd.Stdin = os.Stdin |
| 132 | sshCmd.Stdout = os.Stdout |
| 133 | sshCmd.Stderr = os.Stderr |
| 134 | |
| 135 | // Set environment variables for better terminal compatibility |
| 136 | // Override TERM to xterm-256color for better compatibility with remote systems |
| 137 | // This fixes issues with terminals like Kitty (xterm-kitty) that aren't recognized on all systems |
| 138 | sshCmd.Env = append(os.Environ(), "TERM=xterm-256color") |
| 139 | |
| 140 | // Execute command using the current process environment and stdin/stdout |
| 141 | err := sshCmd.Run() |
| 142 | |
| 143 | // Show completion status and wait for user input before returning |
| 144 | utils.WaitForEnterToReturn(err, "SSH session completed successfully", "SSH session ended with error") |
| 145 | |
| 146 | if err != nil { |
| 147 | return fmt.Errorf("failed to execute SSH command: %w", err) |
| 148 | } |
| 149 | |
| 150 | return nil |
| 151 | } |
| 152 | |
| 153 | // ExecuteLXCShell opens an interactive session to an LXC container using 'pct enter'. |
| 154 | // |