clan/update: make build-host overridable in cli

This commit is contained in:
Jörg Thalheim
2024-12-03 17:28:21 +01:00
parent 760126d8d5
commit 0b3816b6ec
2 changed files with 12 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ class Machine:
nix_options: list[str] = field(default_factory=list)
cached_deployment: None | dict[str, Any] = None
override_target_host: None | str = None
override_build_host: None | str = None
host_key_check: HostKeyCheck = HostKeyCheck.STRICT
_eval_cache: dict[str, str] = field(default_factory=dict)
@@ -196,7 +197,7 @@ class Machine:
The host where the machine is built and deployed from.
Can be the same as the target host.
"""
build_host = self.deployment.get("buildHost")
build_host = self.override_build_host or self.deployment.get("buildHost")
if build_host is None:
return self.target_host
# enable ssh agent forwarding to allow the build host to access the target host

View File

@@ -105,6 +105,8 @@ def update_machines(base_path: str, machines: list[InventoryMachine]) -> None:
raise ClanError(msg)
# Copy targetHost to machine
m.override_target_host = machine.deploy.targetHost
# Would be nice to have?
# m.override_build_host = machine.deploy.buildHost
group_machines.append(m)
deploy_machine(MachineGroup(group_machines))
@@ -197,6 +199,7 @@ def update(args: argparse.Namespace) -> None:
name=args.machines[0], flake=args.flake, nix_options=args.option
)
machine.override_target_host = args.target_host
machine.override_build_host = args.build_host
machine.host_key_check = HostKeyCheck.from_str(args.host_key_check)
machines.append(machine)
@@ -215,6 +218,7 @@ def update(args: argparse.Namespace) -> None:
ignored_machines.append(machine)
continue
machine.host_key_check = HostKeyCheck.from_str(args.host_key_check)
machine.override_build_host = args.build_host
machines.append(machine)
if not machines and ignored_machines != []:
@@ -230,6 +234,7 @@ def update(args: argparse.Namespace) -> None:
else:
machines = get_selected_machines(args.flake, args.option, args.machines)
for machine in machines:
machine.override_build_host = args.build_host
machine.host_key_check = HostKeyCheck.from_str(args.host_key_check)
host_group = MachineGroup(machines)
@@ -258,4 +263,9 @@ def register_update_parser(parser: argparse.ArgumentParser) -> None:
type=str,
help="Address of the machine to update, in the format of user@host:1234.",
)
parser.add_argument(
"--build-host",
type=str,
help="Address of the machine to build the flake, in the format of user@host:1234.",
)
parser.set_defaults(func=update)