clan-lib: machines.py: Remove host_key attribute
This commit is contained in:
@@ -159,11 +159,7 @@ def generate_machine_hardware_info(
|
||||
|
||||
def update_hardware_config_command(args: argparse.Namespace) -> None:
|
||||
host_key_check = HostKeyCheck.from_str(args.host_key_check)
|
||||
machine = Machine(
|
||||
flake=args.flake,
|
||||
name=args.machine,
|
||||
host_key_check=host_key_check,
|
||||
)
|
||||
machine = Machine(flake=args.flake, name=args.machine)
|
||||
opts = HardwareGenerateOptions(
|
||||
machine=machine,
|
||||
password=args.password,
|
||||
@@ -172,12 +168,10 @@ def update_hardware_config_command(args: argparse.Namespace) -> None:
|
||||
|
||||
if args.target_host:
|
||||
target_host = Remote.from_deployment_address(
|
||||
machine_name=machine.name,
|
||||
address=args.target_host,
|
||||
host_key_check=host_key_check,
|
||||
)
|
||||
machine_name=machine.name, address=args.target_host
|
||||
).override(host_key_check=host_key_check)
|
||||
else:
|
||||
target_host = machine.target_host()
|
||||
target_host = machine.target_host().override(host_key_check=host_key_check)
|
||||
|
||||
generate_machine_hardware_info(opts, target_host)
|
||||
|
||||
|
||||
@@ -189,10 +189,8 @@ def install_command(args: argparse.Namespace) -> None:
|
||||
)
|
||||
if target_host_str is not None:
|
||||
target_host = Remote.from_deployment_address(
|
||||
machine_name=machine.name,
|
||||
address=target_host_str,
|
||||
host_key_check=host_key_check,
|
||||
)
|
||||
machine_name=machine.name, address=target_host_str
|
||||
).override(host_key_check=host_key_check)
|
||||
else:
|
||||
target_host = machine.target_host().override(host_key_check=host_key_check)
|
||||
|
||||
|
||||
@@ -220,10 +220,7 @@ def update_command(args: argparse.Namespace) -> None:
|
||||
|
||||
for machine_name in selected_machines:
|
||||
machine = Machine(
|
||||
name=machine_name,
|
||||
flake=args.flake,
|
||||
nix_options=args.option,
|
||||
host_key_check=HostKeyCheck.from_str(args.host_key_check),
|
||||
name=machine_name, flake=args.flake, nix_options=args.option
|
||||
)
|
||||
machines.append(machine)
|
||||
|
||||
@@ -281,8 +278,7 @@ def update_command(args: argparse.Namespace) -> None:
|
||||
target_host = Remote.from_deployment_address(
|
||||
machine_name=machine.name,
|
||||
address=args.target_host,
|
||||
host_key_check=host_key_check,
|
||||
)
|
||||
).override(host_key_check=host_key_check)
|
||||
else:
|
||||
target_host = machine.target_host()
|
||||
runtime.async_run(
|
||||
|
||||
@@ -47,10 +47,8 @@ class DeployInfo:
|
||||
msg = "Hostname cannot be empty."
|
||||
raise ClanError(msg)
|
||||
remote = Remote.from_deployment_address(
|
||||
machine_name="clan-installer",
|
||||
address=host,
|
||||
host_key_check=host_key_check,
|
||||
)
|
||||
machine_name="clan-installer", address=host
|
||||
).override(host_key_check=host_key_check)
|
||||
remotes.append(remote)
|
||||
return DeployInfo(addrs=remotes)
|
||||
|
||||
@@ -64,9 +62,8 @@ class DeployInfo:
|
||||
remote = Remote.from_deployment_address(
|
||||
machine_name="clan-installer",
|
||||
address=addr,
|
||||
host_key_check=host_key_check,
|
||||
password=password,
|
||||
)
|
||||
).override(host_key_check=host_key_check)
|
||||
addrs.append(remote)
|
||||
else:
|
||||
msg = f"Invalid address format: {addr}"
|
||||
@@ -75,10 +72,9 @@ class DeployInfo:
|
||||
remote = Remote.from_deployment_address(
|
||||
machine_name="clan-installer",
|
||||
address=tor_addr,
|
||||
host_key_check=host_key_check,
|
||||
password=password,
|
||||
tor_socks=True,
|
||||
)
|
||||
).override(host_key_check=host_key_check)
|
||||
addrs.append(remote)
|
||||
|
||||
return DeployInfo(addrs=addrs)
|
||||
|
||||
@@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from clan_cli.facts import public_modules as facts_public_modules
|
||||
from clan_cli.facts import secret_modules as facts_secret_modules
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
from clan_cli.vars._types import StoreBase
|
||||
|
||||
from clan_lib.api import API
|
||||
@@ -33,8 +32,6 @@ class Machine:
|
||||
|
||||
nix_options: list[str] = field(default_factory=list)
|
||||
|
||||
host_key_check: HostKeyCheck = HostKeyCheck.STRICT
|
||||
|
||||
def get_inv_machine(self) -> "InventoryMachine":
|
||||
return get_machine(self.flake, self.name)
|
||||
|
||||
@@ -149,9 +146,7 @@ class Machine:
|
||||
description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.",
|
||||
)
|
||||
data = remote.data
|
||||
return data.override(
|
||||
host_key_check=self.host_key_check,
|
||||
)
|
||||
return data
|
||||
|
||||
def build_host(self) -> Remote | None:
|
||||
"""
|
||||
@@ -162,9 +157,7 @@ class Machine:
|
||||
|
||||
if remote:
|
||||
data = remote.data
|
||||
return data.override(
|
||||
host_key_check=self.host_key_check,
|
||||
)
|
||||
return data
|
||||
|
||||
return None
|
||||
|
||||
@@ -266,9 +259,7 @@ def get_host(
|
||||
|
||||
return RemoteSource(
|
||||
data=Remote.from_deployment_address(
|
||||
machine_name=machine.name,
|
||||
address=host_str,
|
||||
host_key_check=machine.host_key_check,
|
||||
machine_name=machine.name, address=host_str
|
||||
),
|
||||
source=source,
|
||||
)
|
||||
|
||||
@@ -3,8 +3,6 @@ import urllib.parse
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -15,7 +13,6 @@ def parse_deployment_address(
|
||||
*,
|
||||
machine_name: str,
|
||||
address: str,
|
||||
host_key_check: HostKeyCheck,
|
||||
forward_agent: bool = True,
|
||||
meta: dict[str, Any] | None = None,
|
||||
private_key: Path | None = None,
|
||||
@@ -73,7 +70,6 @@ def parse_deployment_address(
|
||||
port=port,
|
||||
private_key=private_key,
|
||||
password=password,
|
||||
host_key_check=host_key_check,
|
||||
command_prefix=machine_name,
|
||||
forward_agent=forward_agent,
|
||||
ssh_options=options,
|
||||
|
||||
@@ -91,7 +91,6 @@ class Remote:
|
||||
*,
|
||||
machine_name: str,
|
||||
address: str,
|
||||
host_key_check: HostKeyCheck,
|
||||
forward_agent: bool = True,
|
||||
private_key: Path | None = None,
|
||||
password: str | None = None,
|
||||
@@ -104,7 +103,6 @@ class Remote:
|
||||
return parse_deployment_address(
|
||||
machine_name=machine_name,
|
||||
address=address,
|
||||
host_key_check=host_key_check,
|
||||
forward_agent=forward_agent,
|
||||
private_key=private_key,
|
||||
password=password,
|
||||
|
||||
@@ -114,8 +114,7 @@ def test_parse_deployment_address(
|
||||
result = Remote.from_deployment_address(
|
||||
machine_name=machine_name,
|
||||
address=test_addr,
|
||||
host_key_check=HostKeyCheck.STRICT,
|
||||
)
|
||||
).override(host_key_check=HostKeyCheck.STRICT)
|
||||
|
||||
if expected_exception:
|
||||
return
|
||||
@@ -132,8 +131,8 @@ def test_parse_deployment_address(
|
||||
|
||||
def test_parse_ssh_options() -> None:
|
||||
addr = "root@example.com:2222?IdentityFile=/path/to/private/key&StrictRemoteKeyChecking=yes"
|
||||
host = Remote.from_deployment_address(
|
||||
machine_name="foo", address=addr, host_key_check=HostKeyCheck.STRICT
|
||||
host = Remote.from_deployment_address(machine_name="foo", address=addr).override(
|
||||
host_key_check=HostKeyCheck.STRICT
|
||||
)
|
||||
assert host.address == "example.com"
|
||||
assert host.port == 2222
|
||||
|
||||
@@ -191,16 +191,16 @@ def test_clan_create_api(
|
||||
clan_dir_flake, inv_machine, target_host=f"{host.target}:{ssh_port_var}"
|
||||
)
|
||||
)
|
||||
machine = Machine(
|
||||
name=vm_name, flake=clan_dir_flake, host_key_check=HostKeyCheck.NONE
|
||||
)
|
||||
machine = Machine(name=vm_name, flake=clan_dir_flake)
|
||||
machines.append(machine)
|
||||
assert len(machines) == 1
|
||||
|
||||
# Invalidate cache because of new machine creation
|
||||
clan_dir_flake.invalidate_cache()
|
||||
|
||||
target_host = machine.target_host().override(private_key=private_key)
|
||||
target_host = machine.target_host().override(
|
||||
private_key=private_key, host_key_check=HostKeyCheck.NONE
|
||||
)
|
||||
result = check_machine_online(target_host)
|
||||
assert result == "Online", f"Machine {machine.name} is not online"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user