clan-cli: Fixup clan install which depends on ssh_parseargs.
clan-cli: Remove --ssh-option for now, as it can't work in current state clan-cli: Remove nix_config from test as its impure
This commit is contained in:
@@ -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
|
# Only if the caller did not specify a target_host via args.target_host
|
||||||
# Find a suitable target_host that is reachable
|
# Find a suitable target_host that is reachable
|
||||||
target_host_str = args.target_host
|
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
|
use_tor = False
|
||||||
if deploy_info and not args.target_host:
|
if deploy_info:
|
||||||
host = find_reachable_host(deploy_info)
|
host = find_reachable_host(deploy_info)
|
||||||
if host is None:
|
if host is None or host.tor_socks:
|
||||||
use_tor = True
|
use_tor = True
|
||||||
target_host_str = deploy_info.tor.target
|
target_host_str = deploy_info.tor.target
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ def ssh_shell_from_deploy(
|
|||||||
def ssh_command_parse(args: argparse.Namespace) -> DeployInfo | None:
|
def ssh_command_parse(args: argparse.Namespace) -> DeployInfo | None:
|
||||||
host_key_check = args.host_key_check
|
host_key_check = args.host_key_check
|
||||||
deploy = None
|
deploy = None
|
||||||
|
|
||||||
if args.json:
|
if args.json:
|
||||||
json_file = Path(args.json)
|
json_file = Path(args.json)
|
||||||
if json_file.is_file():
|
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)
|
return DeployInfo.from_json(data, host_key_check)
|
||||||
data = json.loads(args.json)
|
data = json.loads(args.json)
|
||||||
deploy = DeployInfo.from_json(data, host_key_check)
|
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)
|
deploy = DeployInfo.from_qr_code(Path(args.png), host_key_check)
|
||||||
|
elif hasattr(args, "machine") and args.machine:
|
||||||
if hasattr(args, "machine") and args.machine:
|
|
||||||
machine = Machine(args.machine, args.flake)
|
machine = Machine(args.machine, args.flake)
|
||||||
target = machine.target_host().override(
|
target = machine.target_host().override(
|
||||||
command_prefix=machine.name, host_key_check=host_key_check
|
command_prefix=machine.name, host_key_check=host_key_check
|
||||||
)
|
)
|
||||||
deploy = DeployInfo(addrs=[target])
|
deploy = DeployInfo(addrs=[target])
|
||||||
|
else:
|
||||||
if deploy is None:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
ssh_options = None
|
||||||
|
if hasattr(args, "ssh_option") and args.ssh_option:
|
||||||
|
for name, value in args.ssh_option:
|
||||||
ssh_options = {}
|
ssh_options = {}
|
||||||
for name, value in args.ssh_option or []:
|
|
||||||
ssh_options[name] = value
|
ssh_options[name] = value
|
||||||
|
|
||||||
deploy = deploy.overwrite_remotes(ssh_options=ssh_options)
|
deploy = deploy.overwrite_remotes(ssh_options=ssh_options)
|
||||||
|
|
||||||
return deploy
|
return deploy
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.ssh.deploy_info import DeployInfo, find_reachable_host
|
||||||
from clan_cli.tests.fixtures_flakes import ClanFlake
|
from clan_cli.tests.fixtures_flakes import ClanFlake
|
||||||
from clan_cli.tests.helpers import cli
|
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:
|
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(
|
def test_ssh_shell_from_deploy(
|
||||||
hosts: list[Remote],
|
hosts: list[Remote],
|
||||||
flake: ClanFlake,
|
flake: ClanFlake,
|
||||||
nix_config: dict[str, ConfigItem],
|
|
||||||
capture_output: CaptureOutput,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
host = hosts[0]
|
host = hosts[0]
|
||||||
|
|
||||||
machine1_config = flake.machines["m1_machine"]
|
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()
|
machine1_config["clan"]["networking"]["targetHost"] = host.ssh_url()
|
||||||
flake.refresh()
|
flake.refresh()
|
||||||
|
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ class Remote:
|
|||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class ConnectionOptions:
|
class ConnectionOptions:
|
||||||
timeout: int = 2
|
timeout: int = 2
|
||||||
retries: int = 10
|
retries: int = 5
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -527,6 +527,10 @@ def check_machine_ssh_reachable(
|
|||||||
if opts is None:
|
if opts is None:
|
||||||
opts = ConnectionOptions()
|
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
|
address_family = socket.AF_INET6 if ":" in remote.address else socket.AF_INET
|
||||||
for _ in range(opts.retries):
|
for _ in range(opts.retries):
|
||||||
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
|
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
|
||||||
|
|||||||
Reference in New Issue
Block a user