Fix: regression list_machines. Split into multiple functions
list_inventory_machines, list_nixos_machine, list_sops_machines The caller of the function should specify which machines they wants to see
This commit is contained in:
@@ -6,7 +6,7 @@ from ..clan_uri import FlakeId
|
|||||||
from ..cmd import run
|
from ..cmd import run
|
||||||
from ..dirs import machine_gcroot
|
from ..dirs import machine_gcroot
|
||||||
from ..errors import ClanError
|
from ..errors import ClanError
|
||||||
from ..machines.list import list_machines
|
from ..machines.list import list_nixos_machines
|
||||||
from ..machines.machines import Machine
|
from ..machines.machines import Machine
|
||||||
from ..nix import nix_add_to_gcroots, nix_build, nix_config, nix_eval, nix_metadata
|
from ..nix import nix_add_to_gcroots, nix_build, nix_config, nix_eval, nix_metadata
|
||||||
from ..vms.inspect import VmConfig, inspect_vm
|
from ..vms.inspect import VmConfig, inspect_vm
|
||||||
@@ -40,7 +40,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
|
|||||||
system = config["system"]
|
system = config["system"]
|
||||||
|
|
||||||
# Check if the machine exists
|
# Check if the machine exists
|
||||||
machines = list_machines(flake_url, False)
|
machines: list[str] = list_nixos_machines(flake_url, False)
|
||||||
if machine_name not in machines:
|
if machine_name not in machines:
|
||||||
raise ClanError(
|
raise ClanError(
|
||||||
f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from clan_cli.clan.inspect import FlakeConfig, inspect_flake
|
from clan_cli.clan.inspect import FlakeConfig, inspect_flake
|
||||||
from clan_cli.machines.list import list_machines
|
from clan_cli.machines.list import list_nixos_machines
|
||||||
|
|
||||||
from ..clan_uri import ClanURI
|
from ..clan_uri import ClanURI
|
||||||
from ..dirs import user_history_file
|
from ..dirs import user_history_file
|
||||||
@@ -72,7 +72,7 @@ def new_history_entry(url: str, machine: str) -> HistoryEntry:
|
|||||||
def add_all_to_history(uri: ClanURI) -> list[HistoryEntry]:
|
def add_all_to_history(uri: ClanURI) -> list[HistoryEntry]:
|
||||||
history = list_history()
|
history = list_history()
|
||||||
new_entries: list[HistoryEntry] = []
|
new_entries: list[HistoryEntry] = []
|
||||||
for machine in list_machines(uri.get_url()):
|
for machine in list_nixos_machines(uri.get_url()):
|
||||||
new_entry = _add_maschine_to_history_list(uri.get_url(), machine, history)
|
new_entry = _add_maschine_to_history_list(uri.get_url(), machine, history)
|
||||||
new_entries.append(new_entry)
|
new_entries.append(new_entry)
|
||||||
write_history_file(history)
|
write_history_file(history)
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def list_machines(flake_url: str | Path, debug: bool = False) -> dict[str, Machine]:
|
def list_inventory_machines(
|
||||||
|
flake_url: str | Path, debug: bool = False
|
||||||
|
) -> dict[str, Machine]:
|
||||||
inventory = load_inventory_eval(flake_url)
|
inventory = load_inventory_eval(flake_url)
|
||||||
return inventory.machines
|
return inventory.machines
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,16 @@ def get_machine(flake_dir: Path, name: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def has_machine(flake_dir: Path, name: str) -> bool:
|
def has_machine(flake_dir: Path, name: str) -> bool:
|
||||||
|
"""
|
||||||
|
Checks if a machine exists in the sops machines folder
|
||||||
|
"""
|
||||||
return (sops_machines_folder(flake_dir) / name / "key.json").exists()
|
return (sops_machines_folder(flake_dir) / name / "key.json").exists()
|
||||||
|
|
||||||
|
|
||||||
def list_machines(flake_dir: Path) -> list[str]:
|
def list_sops_machines(flake_dir: Path) -> list[str]:
|
||||||
|
"""
|
||||||
|
Lists all machines in the sops machines folder
|
||||||
|
"""
|
||||||
path = sops_machines_folder(flake_dir)
|
path = sops_machines_folder(flake_dir)
|
||||||
|
|
||||||
def validate(name: str) -> bool:
|
def validate(name: str) -> bool:
|
||||||
@@ -86,7 +92,7 @@ def remove_secret(flake_dir: Path, machine: str, secret: str) -> None:
|
|||||||
def list_command(args: argparse.Namespace) -> None:
|
def list_command(args: argparse.Namespace) -> None:
|
||||||
if args.flake is None:
|
if args.flake is None:
|
||||||
raise ClanError("Could not find clan flake toplevel directory")
|
raise ClanError("Could not find clan flake toplevel directory")
|
||||||
lst = list_machines(args.flake.path)
|
lst = list_sops_machines(args.flake.path)
|
||||||
if len(lst) > 0:
|
if len(lst) > 0:
|
||||||
print("\n".join(lst))
|
print("\n".join(lst))
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class ClanList(Gtk.Box):
|
|||||||
|
|
||||||
# menu_model = Gio.Menu()
|
# menu_model = Gio.Menu()
|
||||||
# TODO: Make this lazy, blocks UI startup for too long
|
# TODO: Make this lazy, blocks UI startup for too long
|
||||||
# for vm in machines.list.list_machines(flake_url=vm.data.flake.flake_url):
|
# for vm in machines.list.list_nixos_machines(flake_url=vm.data.flake.flake_url):
|
||||||
# if vm not in vm_store:
|
# if vm not in vm_store:
|
||||||
# menu_model.append(vm, f"app.add::{vm}")
|
# menu_model.append(vm, f"app.add::{vm}")
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createSignal, Match, Show, Switch } from "solid-js";
|
import { createSignal, Match, Show, Switch } from "solid-js";
|
||||||
import { ErrorData, pyApi, SuccessData } from "../api";
|
import { ErrorData, pyApi, SuccessData } from "../api";
|
||||||
|
|
||||||
type MachineDetails = SuccessData<"list_machines">["data"][string];
|
type MachineDetails = SuccessData<"list_inventory_machines">["data"][string];
|
||||||
|
|
||||||
interface MachineListItemProps {
|
interface MachineListItemProps {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import { MachineListItem } from "@/src/components/MachineListItem";
|
|||||||
// >["data"]["services"];
|
// >["data"]["services"];
|
||||||
|
|
||||||
type MachinesModel = Extract<
|
type MachinesModel = Extract<
|
||||||
OperationResponse<"list_machines">,
|
OperationResponse<"list_inventory_machines">,
|
||||||
{ status: "success" }
|
{ status: "success" }
|
||||||
>["data"];
|
>["data"];
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ export const MachineListView: Component = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await callApi("list_machines", {
|
const response = await callApi("list_inventory_machines", {
|
||||||
flake_url: uri,
|
flake_url: uri,
|
||||||
});
|
});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user