Refactor(machine/install): don't mutate the machine class during installation

This commit is contained in:
Johannes Kirschbauer
2025-05-06 17:09:37 +02:00
parent 7371085c05
commit b21c98db7f

View File

@@ -162,7 +162,32 @@ def install_machine(opts: InstallOptions) -> None:
def install_command(args: argparse.Namespace) -> None: def install_command(args: argparse.Namespace) -> None:
host_key_check = HostKeyCheck.from_str(args.host_key_check) host_key_check = HostKeyCheck.from_str(args.host_key_check)
try: try:
machine = Machine(name=args.machine, flake=args.flake, nix_options=args.option) # Only if the caller did not specify a target_host via args.target_host
# Find a suitable target_host that is reachable
target_host = args.target_host
deploy_info: DeployInfo | None = ssh_command_parse(args)
if deploy_info and not args.target_host:
host = find_reachable_host(deploy_info, host_key_check)
if host is None:
use_tor = True
target_host = f"root@{deploy_info.tor}"
else:
target_host = host.target
if args.password:
password = args.password
elif deploy_info and deploy_info.pwd:
password = deploy_info.pwd
else:
password = None
machine = Machine(
name=args.machine,
flake=args.flake,
nix_options=args.option,
override_target_host=target_host,
)
use_tor = False use_tor = False
if machine._class_ == "darwin": if machine._class_ == "darwin":
@@ -173,26 +198,6 @@ def install_command(args: argparse.Namespace) -> None:
msg = "Could not find clan flake toplevel directory" msg = "Could not find clan flake toplevel directory"
raise ClanError(msg) raise ClanError(msg)
deploy_info: DeployInfo | None = ssh_command_parse(args)
if args.target_host:
machine.override_target_host = args.target_host
elif deploy_info:
host = find_reachable_host(deploy_info, host_key_check)
if host is None:
use_tor = True
machine.override_target_host = f"root@{deploy_info.tor}"
else:
machine.override_target_host = host.target
password = deploy_info.pwd
if args.password:
password = args.password
elif deploy_info and deploy_info.pwd:
password = deploy_info.pwd
else:
password = None
if not args.yes: if not args.yes:
ask = input( ask = input(
f"Install {args.machine} to {machine.target_host_address}? [y/N] " f"Install {args.machine} to {machine.target_host_address}? [y/N] "