From 1b146943d87994c80af42ac5a225323018dae46d Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 21 Aug 2024 15:22:56 +0200 Subject: [PATCH] API: init set_machine --- pkgs/clan-cli/clan_cli/machines/list.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/list.py b/pkgs/clan-cli/clan_cli/machines/list.py index bc754d661..0ebe9ec5b 100644 --- a/pkgs/clan-cli/clan_cli/machines/list.py +++ b/pkgs/clan-cli/clan_cli/machines/list.py @@ -8,12 +8,21 @@ from typing import Literal from clan_cli.api import API from clan_cli.cmd import run_no_stdout from clan_cli.errors import ClanCmdError, ClanError -from clan_cli.inventory import Machine, load_inventory_eval +from clan_cli.inventory import Machine, load_inventory_eval, save_inventory from clan_cli.nix import nix_eval, nix_shell log = logging.getLogger(__name__) +@API.register +def set_machine(flake_url: str | Path, machine_name: str, machine: Machine) -> None: + inventory = load_inventory_eval(flake_url) + + inventory.machines[machine_name] = machine + + save_inventory(inventory, flake_url, "machines: edit '{machine_name}'") + + @API.register def list_inventory_machines(flake_url: str | Path) -> dict[str, Machine]: inventory = load_inventory_eval(flake_url) @@ -86,7 +95,7 @@ def check_machine_online( if not hostname: raise ClanError(f"Machine {machine_name} does not specify a targetHost") - timeout = opts.timeout if opts and opts.timeout else 2 + timeout = opts.timeout if opts and opts.timeout else 20 cmd = nix_shell( ["nixpkgs#util-linux", *(["nixpkgs#openssh"] if hostname else [])],