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 = {}
|
filtered_machines = {}
|
||||||
for machine in machines.values():
|
for machine in machines.values():
|
||||||
inv_machine = get_machine(machine)
|
inv_machine = get_machine(machine.flake, machine.name)
|
||||||
machine_tags = inv_machine.get("tags", [])
|
machine_tags = inv_machine.get("tags", [])
|
||||||
if all(tag in machine_tags for tag in tags):
|
if all(tag in machine_tags for tag in tags):
|
||||||
filtered_machines[machine.name] = machine
|
filtered_machines[machine.name] = machine
|
||||||
@@ -97,7 +97,7 @@ def extract_header(c: str) -> str:
|
|||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def get_machine_details(machine: Machine) -> MachineDetails:
|
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)
|
hw_config = HardwareConfig.detect_type(machine)
|
||||||
|
|
||||||
machine_dir = specific_machine_dir(machine)
|
machine_dir = specific_machine_dir(machine)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
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.machines.machines import Machine
|
from clan_lib.machines.machines import Machine
|
||||||
from clan_lib.nix_models.clan import (
|
from clan_lib.nix_models.clan import (
|
||||||
InventoryMachine,
|
InventoryMachine,
|
||||||
@@ -9,13 +10,13 @@ from clan_lib.persist.util import set_value_by_path
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def get_machine(machine: Machine) -> InventoryMachine:
|
def get_machine(flake: Flake, name: str) -> InventoryMachine:
|
||||||
inventory_store = InventoryStore(flake=machine.flake)
|
inventory_store = InventoryStore(flake=flake)
|
||||||
inventory = inventory_store.read()
|
inventory = inventory_store.read()
|
||||||
|
|
||||||
machine_inv = inventory.get("machines", {}).get(machine.name)
|
machine_inv = inventory.get("machines", {}).get(name)
|
||||||
if machine_inv is None:
|
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)
|
raise ClanError(msg)
|
||||||
|
|
||||||
return InventoryMachine(**machine_inv)
|
return InventoryMachine(**machine_inv)
|
||||||
|
|||||||
Reference in New Issue
Block a user