Refactor(api/update_machine): rename to set_machine; use name, flake
This commit is contained in:
@@ -411,7 +411,7 @@ const MachineForm = (props: MachineDetailsProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const machine_response = await callApi("update_machine", {
|
const machine_response = await callApi("set_machine", {
|
||||||
machine: {
|
machine: {
|
||||||
name: props.initialData.machine.name || "My machine",
|
name: props.initialData.machine.name || "My machine",
|
||||||
flake: {
|
flake: {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
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,
|
||||||
)
|
)
|
||||||
@@ -22,9 +23,21 @@ 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 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"
|
assert machine.name == update.get("name", machine.name), "Machine name mismatch"
|
||||||
|
|
||||||
inventory_store = InventoryStore(flake=machine.flake)
|
inventory_store = InventoryStore(flake=machine.flake)
|
||||||
inventory = inventory_store.read()
|
inventory = inventory_store.read()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user