diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index d2f04529f..2c57ba4cb 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -24,12 +24,14 @@ def install_command(args: argparse.Namespace) -> None: # Only if the caller did not specify a target_host via args.target_host # Find a suitable target_host that is reachable target_host_str = args.target_host - deploy_info: DeployInfo | None = ssh_command_parse(args) + deploy_info: DeployInfo | None = ( + ssh_command_parse(args) if target_host_str is None else None + ) use_tor = False - if deploy_info and not args.target_host: + if deploy_info: host = find_reachable_host(deploy_info) - if host is None: + if host is None or host.tor_socks: use_tor = True target_host_str = deploy_info.tor.target else: diff --git a/pkgs/clan-cli/clan_cli/ssh/deploy_info.py b/pkgs/clan-cli/clan_cli/ssh/deploy_info.py index a3e9619b1..0838844d5 100644 --- a/pkgs/clan-cli/clan_cli/ssh/deploy_info.py +++ b/pkgs/clan-cli/clan_cli/ssh/deploy_info.py @@ -154,6 +154,7 @@ def ssh_shell_from_deploy( def ssh_command_parse(args: argparse.Namespace) -> DeployInfo | None: host_key_check = args.host_key_check deploy = None + if args.json: json_file = Path(args.json) if json_file.is_file(): @@ -161,23 +162,25 @@ def ssh_command_parse(args: argparse.Namespace) -> DeployInfo | None: return DeployInfo.from_json(data, host_key_check) data = json.loads(args.json) deploy = DeployInfo.from_json(data, host_key_check) - if args.png: + elif args.png: deploy = DeployInfo.from_qr_code(Path(args.png), host_key_check) - - if hasattr(args, "machine") and args.machine: + elif hasattr(args, "machine") and args.machine: machine = Machine(args.machine, args.flake) target = machine.target_host().override( command_prefix=machine.name, host_key_check=host_key_check ) deploy = DeployInfo(addrs=[target]) - - if deploy is None: + else: return None - ssh_options = {} - for name, value in args.ssh_option or []: - ssh_options[name] = value + ssh_options = None + if hasattr(args, "ssh_option") and args.ssh_option: + for name, value in args.ssh_option: + ssh_options = {} + ssh_options[name] = value + deploy = deploy.overwrite_remotes(ssh_options=ssh_options) + return deploy diff --git a/pkgs/clan-cli/clan_cli/ssh/test_deploy_info.py b/pkgs/clan-cli/clan_cli/ssh/test_deploy_info.py index 0e274539a..30d758311 100644 --- a/pkgs/clan-cli/clan_cli/ssh/test_deploy_info.py +++ b/pkgs/clan-cli/clan_cli/ssh/test_deploy_info.py @@ -9,8 +9,6 @@ from clan_lib.ssh.remote import Remote from clan_cli.ssh.deploy_info import DeployInfo, find_reachable_host from clan_cli.tests.fixtures_flakes import ClanFlake from clan_cli.tests.helpers import cli -from clan_cli.tests.nix_config import ConfigItem -from clan_cli.tests.stdout import CaptureOutput def test_qrcode_scan(temp_dir: Path) -> None: @@ -90,13 +88,11 @@ def test_find_reachable_host(hosts: list[Remote]) -> None: def test_ssh_shell_from_deploy( hosts: list[Remote], flake: ClanFlake, - nix_config: dict[str, ConfigItem], - capture_output: CaptureOutput, ) -> None: host = hosts[0] machine1_config = flake.machines["m1_machine"] - machine1_config["nixpkgs"]["hostPlatform"] = nix_config["system"].value + machine1_config["nixpkgs"]["hostPlatform"] = "x86_64-linux" machine1_config["clan"]["networking"]["targetHost"] = host.ssh_url() flake.refresh() diff --git a/pkgs/clan-cli/clan_lib/ssh/remote.py b/pkgs/clan-cli/clan_lib/ssh/remote.py index c42f70af6..9cf0c0cfa 100644 --- a/pkgs/clan-cli/clan_lib/ssh/remote.py +++ b/pkgs/clan-cli/clan_lib/ssh/remote.py @@ -454,7 +454,7 @@ class Remote: @dataclass(frozen=True) class ConnectionOptions: timeout: int = 2 - retries: int = 10 + retries: int = 5 @dataclass @@ -527,6 +527,10 @@ def check_machine_ssh_reachable( if opts is None: opts = ConnectionOptions() + cmdlog.debug( + f"Checking SSH reachability for {remote.target} on port {remote.port or 22}", + ) + address_family = socket.AF_INET6 if ":" in remote.address else socket.AF_INET for _ in range(opts.retries): with socket.socket(address_family, socket.SOCK_STREAM) as sock: