Templates: replace leftover MachineID, by Machine

This commit is contained in:
Johannes Kirschbauer
2025-07-06 13:03:17 +02:00
parent 74d2ae0619
commit 38f98645ac
3 changed files with 8 additions and 13 deletions

View File

@@ -1,9 +1,9 @@
from dataclasses import dataclass
from typing import TypedDict from typing import TypedDict
from clan_lib.api import API from clan_lib.api import API
from clan_lib.errors import ClanError from clan_lib.errors import ClanError
from clan_lib.flake.flake import Flake from clan_lib.flake.flake import Flake
from clan_lib.machines.machines import Machine
from clan_lib.nix_models.clan import ( from clan_lib.nix_models.clan import (
InventoryMachine, InventoryMachine,
) )
@@ -65,16 +65,8 @@ def get_machine(flake: Flake, name: str) -> InventoryMachine:
return InventoryMachine(**machine_inv) 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 @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. Update the machine information in the inventory.
""" """

View File

@@ -13,7 +13,6 @@ from clan_cli.vars._types import StoreBase
from clan_lib.api import API from clan_lib.api import API
from clan_lib.errors import ClanCmdError, ClanError from clan_lib.errors import ClanCmdError, ClanError
from clan_lib.flake import Flake 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 import nix_config
from clan_lib.nix_models.clan import InventoryMachine from clan_lib.nix_models.clan import InventoryMachine
from clan_lib.ssh.remote import Remote from clan_lib.ssh.remote import Remote
@@ -39,6 +38,9 @@ class Machine:
return cls(name=name, flake=flake) return cls(name=name, flake=flake)
def get_inv_machine(self) -> "InventoryMachine": 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) return get_machine(self.flake, self.name)
def get_id(self) -> str: def get_id(self) -> str:

View File

@@ -7,7 +7,8 @@ from pathlib import Path
from clan_lib.dirs import specific_machine_dir from clan_lib.dirs import specific_machine_dir
from clan_lib.errors import ClanError from clan_lib.errors import ClanError
from clan_lib.flake import Flake 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.filesystem import copy_from_nixstore, realize_nix_path
from clan_lib.templates.template_url import transform_url from clan_lib.templates.template_url import transform_url
@@ -84,7 +85,7 @@ def machine_template(
description="Template machine must contain a configuration.nix", 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) dst_machine_dir = specific_machine_dir(tmp_machine)