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 8b0d791c5a
commit 455c8654a1
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) nix_options: list[str] = field(default_factory=list)
cached_deployment: None | dict[str, Any] = None cached_deployment: None | dict[str, Any] = None
override_target_host: None | str = None override_target_host: None | str = None
override_build_host: None | str = None
host_key_check: HostKeyCheck = HostKeyCheck.STRICT host_key_check: HostKeyCheck = HostKeyCheck.STRICT
_eval_cache: dict[str, str] = field(default_factory=dict) _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. The host where the machine is built and deployed from.
Can be the same as the target host. 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: if build_host is None:
return self.target_host return self.target_host
# enable ssh agent forwarding to allow the build host to access the 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) raise ClanError(msg)
# Copy targetHost to machine # Copy targetHost to machine
m.override_target_host = machine.deploy.targetHost m.override_target_host = machine.deploy.targetHost
# Would be nice to have?
# m.override_build_host = machine.deploy.buildHost
group_machines.append(m) group_machines.append(m)
deploy_machine(MachineGroup(group_machines)) 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 name=args.machines[0], flake=args.flake, nix_options=args.option
) )
machine.override_target_host = args.target_host 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) machine.host_key_check = HostKeyCheck.from_str(args.host_key_check)
machines.append(machine) machines.append(machine)
@@ -215,6 +218,7 @@ def update(args: argparse.Namespace) -> None:
ignored_machines.append(machine) ignored_machines.append(machine)
continue continue
machine.host_key_check = HostKeyCheck.from_str(args.host_key_check) machine.host_key_check = HostKeyCheck.from_str(args.host_key_check)
machine.override_build_host = args.build_host
machines.append(machine) machines.append(machine)
if not machines and ignored_machines != []: if not machines and ignored_machines != []:
@@ -230,6 +234,7 @@ def update(args: argparse.Namespace) -> None:
else: else:
machines = get_selected_machines(args.flake, args.option, args.machines) machines = get_selected_machines(args.flake, args.option, args.machines)
for machine in machines: for machine in machines:
machine.override_build_host = args.build_host
machine.host_key_check = HostKeyCheck.from_str(args.host_key_check) machine.host_key_check = HostKeyCheck.from_str(args.host_key_check)
host_group = MachineGroup(machines) host_group = MachineGroup(machines)
@@ -258,4 +263,9 @@ def register_update_parser(parser: argparse.ArgumentParser) -> None:
type=str, type=str,
help="Address of the machine to update, in the format of user@host:1234.", 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) parser.set_defaults(func=update)