From ccb62254f225bb4ac9ac88b6a9711274d19ccfce Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sun, 10 Nov 2024 00:57:55 +0100 Subject: [PATCH] pkgs/cli: Add `--target-host` to `clan machines create` Add the `--target-host` flag to `clan machines create`. This allows setting the `deploy.targetHost` for the newly created machine via the inventory. Closes: #2339 --- pkgs/clan-cli/clan_cli/machines/create.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/machines/create.py b/pkgs/clan-cli/clan_cli/machines/create.py index 4b7d8bcb1..b75fc1f29 100644 --- a/pkgs/clan-cli/clan_cli/machines/create.py +++ b/pkgs/clan-cli/clan_cli/machines/create.py @@ -42,6 +42,7 @@ def validate_directory(root_dir: Path) -> None: class CreateOptions: clan_dir: FlakeId machine: InventoryMachine + target_host: str | None = None template_src: FlakeId | None = None template_name: str | None = None @@ -132,8 +133,10 @@ def create_machine(opts: CreateOptions) -> None: template_inventory = load_inventory_json(dst) merge_template_inventory(inventory, template_inventory, machine_name) + deploy = MachineDeploy() + deploy.targetHost = opts.target_host # TODO: We should allow the template to specify machine metadata if not defined by user - new_machine = InventoryMachine(name=machine_name, deploy=MachineDeploy()) + new_machine = InventoryMachine(name=machine_name, deploy=deploy) inventory.machines.update({new_machine.name: dataclass_to_dict(new_machine)}) set_inventory(inventory, clan_dir, "Imported machine from template") @@ -161,6 +164,7 @@ def create_command(args: argparse.Namespace) -> None: clan_dir=clan_dir, machine=machine, template_name=args.template_name, + target_host=args.target_host, ) create_machine(opts) @@ -183,3 +187,8 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None: type=str, help="The name of the template machine to import", ) + parser.add_argument( + "--target-host", + type=str, + help="Address of the machine to install and update, in the format of user@host:1234", + )