diff --git a/pkgs/clan-cli/clan_lib/machines/actions.py b/pkgs/clan-cli/clan_lib/machines/actions.py index 0fd7748ce..4c19e7a23 100644 --- a/pkgs/clan-cli/clan_lib/machines/actions.py +++ b/pkgs/clan-cli/clan_lib/machines/actions.py @@ -1,9 +1,9 @@ -from dataclasses import dataclass from typing import TypedDict 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, ) @@ -65,16 +65,8 @@ 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 set_machine(machine: MachineID, update: InventoryMachine) -> None: +def set_machine(machine: Machine, update: InventoryMachine) -> None: """ Update the machine information in the inventory. """ diff --git a/pkgs/clan-cli/clan_lib/machines/machines.py b/pkgs/clan-cli/clan_lib/machines/machines.py index 489b0bccf..ce4a51b6d 100644 --- a/pkgs/clan-cli/clan_lib/machines/machines.py +++ b/pkgs/clan-cli/clan_lib/machines/machines.py @@ -13,7 +13,6 @@ from clan_cli.vars._types import StoreBase from clan_lib.api import API from clan_lib.errors import ClanCmdError, ClanError from clan_lib.flake import Flake -from clan_lib.machines.actions import get_machine from clan_lib.nix import nix_config from clan_lib.nix_models.clan import InventoryMachine from clan_lib.ssh.remote import Remote @@ -39,6 +38,9 @@ class Machine: return cls(name=name, flake=flake) def get_inv_machine(self) -> "InventoryMachine": + # Import on demand to avoid circular imports + from clan_lib.machines.actions import get_machine + return get_machine(self.flake, self.name) def get_id(self) -> str: diff --git a/pkgs/clan-cli/clan_lib/templates/handler.py b/pkgs/clan-cli/clan_lib/templates/handler.py index 72d28a627..74ce167d6 100644 --- a/pkgs/clan-cli/clan_lib/templates/handler.py +++ b/pkgs/clan-cli/clan_lib/templates/handler.py @@ -7,7 +7,8 @@ from pathlib import Path from clan_lib.dirs import specific_machine_dir from clan_lib.errors import ClanError from clan_lib.flake import Flake -from clan_lib.machines.actions import MachineID, list_machines +from clan_lib.machines.actions import list_machines +from clan_lib.machines.machines import Machine from clan_lib.templates.filesystem import copy_from_nixstore, realize_nix_path from clan_lib.templates.template_url import transform_url @@ -84,7 +85,7 @@ def machine_template( description="Template machine must contain a configuration.nix", ) - tmp_machine = MachineID(flake=flake, name=dst_machine_name) + tmp_machine = Machine(flake=flake, name=dst_machine_name) dst_machine_dir = specific_machine_dir(tmp_machine)