Merge pull request 'clan-lib: machines.py: Remove private_key attribute' (#4033) from Qubasa/clan-core:minimize_machine_obj into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4033
This commit is contained in:
@@ -194,7 +194,7 @@ def install_command(args: argparse.Namespace) -> None:
|
||||
host_key_check=host_key_check,
|
||||
)
|
||||
else:
|
||||
target_host = machine.target_host().with_data(host_key_check=host_key_check)
|
||||
target_host = machine.target_host().override(host_key_check=host_key_check)
|
||||
|
||||
if machine._class_ == "darwin":
|
||||
msg = "Installing macOS machines is not yet supported"
|
||||
|
||||
@@ -32,7 +32,7 @@ class Machine:
|
||||
flake: Flake
|
||||
|
||||
nix_options: list[str] = field(default_factory=list)
|
||||
private_key: Path | None = None
|
||||
|
||||
host_key_check: HostKeyCheck = HostKeyCheck.STRICT
|
||||
|
||||
def get_inv_machine(self) -> "InventoryMachine":
|
||||
@@ -149,18 +149,8 @@ class Machine:
|
||||
description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.",
|
||||
)
|
||||
data = remote.data
|
||||
return Remote(
|
||||
address=data.address,
|
||||
user=data.user,
|
||||
command_prefix=data.command_prefix,
|
||||
port=data.port,
|
||||
private_key=self.private_key,
|
||||
password=data.password,
|
||||
forward_agent=data.forward_agent,
|
||||
return data.override(
|
||||
host_key_check=self.host_key_check,
|
||||
verbose_ssh=data.verbose_ssh,
|
||||
ssh_options=data.ssh_options,
|
||||
tor_socks=data.tor_socks,
|
||||
)
|
||||
|
||||
def build_host(self) -> Remote | None:
|
||||
@@ -172,18 +162,8 @@ class Machine:
|
||||
|
||||
if remote:
|
||||
data = remote.data
|
||||
return Remote(
|
||||
address=data.address,
|
||||
user=data.user,
|
||||
command_prefix=data.command_prefix,
|
||||
port=data.port,
|
||||
private_key=self.private_key,
|
||||
password=data.password,
|
||||
forward_agent=data.forward_agent,
|
||||
return data.override(
|
||||
host_key_check=self.host_key_check,
|
||||
verbose_ssh=data.verbose_ssh,
|
||||
ssh_options=data.ssh_options,
|
||||
tor_socks=data.tor_socks,
|
||||
)
|
||||
|
||||
return None
|
||||
@@ -289,7 +269,6 @@ def get_host(
|
||||
machine_name=machine.name,
|
||||
address=host_str,
|
||||
host_key_check=machine.host_key_check,
|
||||
private_key=machine.private_key,
|
||||
),
|
||||
source=source,
|
||||
)
|
||||
|
||||
@@ -54,7 +54,12 @@ class Remote:
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def with_data(self, host_key_check: HostKeyCheck | None = None) -> "Remote":
|
||||
def override(
|
||||
self,
|
||||
*,
|
||||
host_key_check: HostKeyCheck | None = None,
|
||||
private_key: Path | None = None,
|
||||
) -> "Remote":
|
||||
"""
|
||||
Returns a new Remote instance with the same data but with a different host_key_check.
|
||||
"""
|
||||
@@ -63,7 +68,7 @@ class Remote:
|
||||
user=self.user,
|
||||
command_prefix=self.command_prefix,
|
||||
port=self.port,
|
||||
private_key=self.private_key,
|
||||
private_key=private_key if private_key is not None else self.private_key,
|
||||
password=self.password,
|
||||
forward_agent=self.forward_agent,
|
||||
host_key_check=host_key_check
|
||||
|
||||
@@ -192,10 +192,7 @@ def test_clan_create_api(
|
||||
)
|
||||
)
|
||||
machine = Machine(
|
||||
name=vm_name,
|
||||
flake=clan_dir_flake,
|
||||
host_key_check=HostKeyCheck.NONE,
|
||||
private_key=private_key,
|
||||
name=vm_name, flake=clan_dir_flake, host_key_check=HostKeyCheck.NONE
|
||||
)
|
||||
machines.append(machine)
|
||||
assert len(machines) == 1
|
||||
@@ -203,7 +200,8 @@ def test_clan_create_api(
|
||||
# Invalidate cache because of new machine creation
|
||||
clan_dir_flake.invalidate_cache()
|
||||
|
||||
result = check_machine_online(machine.target_host())
|
||||
target_host = machine.target_host().override(private_key=private_key)
|
||||
result = check_machine_online(target_host)
|
||||
assert result == "Online", f"Machine {machine.name} is not online"
|
||||
|
||||
ssh_keys = [
|
||||
|
||||
Reference in New Issue
Block a user