From 4af74ee5a5fdb35914d5019c697286a1c0cec1d9 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 4 Oct 2023 23:28:15 +0200 Subject: [PATCH] machines update: add --target-host --- pkgs/clan-cli/clan_cli/machines/update.py | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index ff4e74994..6f1171952 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -112,10 +112,24 @@ def get_selected_machines(machine_names: list[str], clan_dir: Path) -> HostGroup # FIXME: we want some kind of inventory here. def update(args: argparse.Namespace) -> None: clan_dir = get_clan_flake_toplevel() - if len(args.machines) == 0: - machines = get_all_machines(clan_dir) + if len(args.machines) == 1 and args.target_host is not None: + machine = Machine(name=args.machines[0], clan_dir=clan_dir) + machine.deployment_address = args.target_host + host = parse_deployment_address( + args.machines[0], + args.target_host, + meta={"machine": machine}, + ) + machines = HostGroup([host]) + + elif args.target_host is not None: + print("target host can only be specified for a single machine") + exit(1) else: - machines = get_selected_machines(args.machines, clan_dir) + if len(args.machines) == 0: + machines = get_all_machines(clan_dir) + else: + machines = get_selected_machines(args.machines, clan_dir) deploy_nixos(machines, clan_dir) @@ -128,4 +142,9 @@ def register_update_parser(parser: argparse.ArgumentParser) -> None: nargs="*", default=[], ) + parser.add_argument( + "--target-host", + type=str, + help="address of the machine to update, in the format of user@host:1234", + ) parser.set_defaults(func=update)