From 7f478bffe2deec75a1cd5aa4db6646cbf95b46d8 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 9 Jun 2025 11:38:15 +0200 Subject: [PATCH] Refactor(api/update_machine): rename to set_machine; use name, flake --- .../clan-app/ui/src/routes/machines/details.tsx | 2 +- pkgs/clan-cli/clan_lib/machines/actions.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkgs/clan-app/ui/src/routes/machines/details.tsx b/pkgs/clan-app/ui/src/routes/machines/details.tsx index 97bc7f217..60aa78dfe 100644 --- a/pkgs/clan-app/ui/src/routes/machines/details.tsx +++ b/pkgs/clan-app/ui/src/routes/machines/details.tsx @@ -411,7 +411,7 @@ const MachineForm = (props: MachineDetailsProps) => { return; } - const machine_response = await callApi("update_machine", { + const machine_response = await callApi("set_machine", { machine: { name: props.initialData.machine.name || "My machine", flake: { diff --git a/pkgs/clan-cli/clan_lib/machines/actions.py b/pkgs/clan-cli/clan_lib/machines/actions.py index dc00dba7e..8d0a48acf 100644 --- a/pkgs/clan-cli/clan_lib/machines/actions.py +++ b/pkgs/clan-cli/clan_lib/machines/actions.py @@ -1,7 +1,8 @@ +from dataclasses import dataclass + from clan_lib.api import API from clan_lib.errors import ClanError from clan_lib.flake.flake import Flake -from clan_lib.machines.machines import Machine from clan_lib.nix_models.clan import ( InventoryMachine, ) @@ -22,9 +23,21 @@ def get_machine(flake: Flake, name: str) -> InventoryMachine: return InventoryMachine(**machine_inv) +# TODO: remove this machine, once the Machine class is refactored +# We added this now, to allow for dispatching actions. To require only 'name' and 'flake' of a machine. +@dataclass(frozen=True) +class MachineID: + name: str + flake: Flake + + @API.register -def update_machine(machine: Machine, update: InventoryMachine) -> None: +def set_machine(machine: MachineID, update: InventoryMachine) -> None: + """ + Update the machine information in the inventory. + """ assert machine.name == update.get("name", machine.name), "Machine name mismatch" + inventory_store = InventoryStore(flake=machine.flake) inventory = inventory_store.read()