Chore(api): narrow down get_machine
Dont require the user to pass the machine into the same getter function The workflow contradicts itself here
This commit is contained in:
@@ -69,7 +69,7 @@ def query_machines_by_tags(flake: Flake, tags: list[str]) -> dict[str, Machine]:
|
||||
|
||||
filtered_machines = {}
|
||||
for machine in machines.values():
|
||||
inv_machine = get_machine(machine)
|
||||
inv_machine = get_machine(machine.flake, machine.name)
|
||||
machine_tags = inv_machine.get("tags", [])
|
||||
if all(tag in machine_tags for tag in tags):
|
||||
filtered_machines[machine.name] = machine
|
||||
@@ -97,7 +97,7 @@ def extract_header(c: str) -> str:
|
||||
|
||||
@API.register
|
||||
def get_machine_details(machine: Machine) -> MachineDetails:
|
||||
machine_inv = get_machine(machine)
|
||||
machine_inv = get_machine(machine.flake, machine.name)
|
||||
hw_config = HardwareConfig.detect_type(machine)
|
||||
|
||||
machine_dir = specific_machine_dir(machine)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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,
|
||||
@@ -9,13 +10,13 @@ from clan_lib.persist.util import set_value_by_path
|
||||
|
||||
|
||||
@API.register
|
||||
def get_machine(machine: Machine) -> InventoryMachine:
|
||||
inventory_store = InventoryStore(flake=machine.flake)
|
||||
def get_machine(flake: Flake, name: str) -> InventoryMachine:
|
||||
inventory_store = InventoryStore(flake=flake)
|
||||
inventory = inventory_store.read()
|
||||
|
||||
machine_inv = inventory.get("machines", {}).get(machine.name)
|
||||
machine_inv = inventory.get("machines", {}).get(name)
|
||||
if machine_inv is None:
|
||||
msg = f"Machine {machine.name} not found in inventory"
|
||||
msg = f"Machine {name} not found in inventory"
|
||||
raise ClanError(msg)
|
||||
|
||||
return InventoryMachine(**machine_inv)
|
||||
|
||||
Reference in New Issue
Block a user