From eb844e83fe6f51ca780af13a254f290f4951ea78 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 14 Aug 2024 14:27:48 +0200 Subject: [PATCH 1/2] Clan-cli: remove unused show machine --- pkgs/clan-cli/clan_cli/machines/__init__.py | 12 ----- pkgs/clan-cli/clan_cli/machines/show.py | 59 --------------------- 2 files changed, 71 deletions(-) delete mode 100644 pkgs/clan-cli/clan_cli/machines/show.py diff --git a/pkgs/clan-cli/clan_cli/machines/__init__.py b/pkgs/clan-cli/clan_cli/machines/__init__.py index bad8706fb..c6b0631e1 100644 --- a/pkgs/clan-cli/clan_cli/machines/__init__.py +++ b/pkgs/clan-cli/clan_cli/machines/__init__.py @@ -6,7 +6,6 @@ from .delete import register_delete_parser from .hardware import register_hw_generate from .install import register_install_parser from .list import register_list_parser -from .show import register_show_parser from .update import register_update_parser @@ -86,17 +85,6 @@ For more detailed information, visit: https://docs.clan.lol/getting-started/conf ) register_hw_generate(generate_hw_parser) - show_parser = subparser.add_parser( - "show", - help="Show a machine", - epilog=( - """ -This subcommand shows the details of a machine managed by this clan like icon, description, etc -""" - ), - ) - register_show_parser(show_parser) - install_parser = subparser.add_parser( "install", help="Install a machine", diff --git a/pkgs/clan-cli/clan_cli/machines/show.py b/pkgs/clan-cli/clan_cli/machines/show.py deleted file mode 100644 index 29284b034..000000000 --- a/pkgs/clan-cli/clan_cli/machines/show.py +++ /dev/null @@ -1,59 +0,0 @@ -import argparse -import dataclasses -import json -import logging -from pathlib import Path - -from clan_cli.api import API - -from ..cmd import run_no_stdout -from ..completions import add_dynamic_completer, complete_machines -from ..nix import nix_config, nix_eval -from .types import machine_name_type - -log = logging.getLogger(__name__) - - -@dataclasses.dataclass -class MachineInfo: - machine_name: str - machine_description: str | None - machine_icon: str | None - - -@API.register -def show_machine(flake_url: str | Path, machine_name: str) -> MachineInfo: - config = nix_config() - system = config["system"] - cmd = nix_eval( - [ - f"{flake_url}#clanInternals.machines.{system}.{machine_name}", - "--apply", - "machine: { inherit (machine.config.clan.core) machineDescription machineIcon machineName; }", - "--json", - ] - ) - proc = run_no_stdout(cmd) - res = proc.stdout.strip() - machine = json.loads(res) - - return MachineInfo( - machine_name=machine.get("machineName"), - machine_description=machine.get("machineDescription", None), - machine_icon=machine.get("machineIcon", None), - ) - - -def show_command(args: argparse.Namespace) -> None: - machine = show_machine(args.flake.path, args.machine) - print(f"Name: {machine.machine_name}") - print(f"Description: {machine.machine_description or ''}") - print(f"Icon: {machine.machine_icon or ''}") - - -def register_show_parser(parser: argparse.ArgumentParser) -> None: - parser.set_defaults(func=show_command) - machine_parser = parser.add_argument( - "machine", help="the name of the machine", type=machine_name_type - ) - add_dynamic_completer(machine_parser, complete_machines) From 3f46d37b6716cf03d3350387c01bf0792d568ade Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 14 Aug 2024 16:16:51 +0200 Subject: [PATCH 2/2] Clan-app: generate hw spec via ssh --- pkgs/clan-cli/clan_cli/machines/hardware.py | 2 +- pkgs/clan-cli/clan_cli/machines/list.py | 28 +++++ pkgs/clan-cli/tests/test_machines_cli.py | 4 - .../app/src/components/MachineListItem.tsx | 11 +- pkgs/webview-ui/app/src/layout/layout.tsx | 5 + .../app/src/routes/machines/[name]/view.tsx | 106 +++++++++++++++++- .../app/src/routes/machines/create.tsx | 4 +- pkgs/webview-ui/app/tests/types.test.ts | 17 --- 8 files changed, 148 insertions(+), 29 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 99ec9c865..4a3fb1430 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -114,7 +114,7 @@ def generate_machine_hardware_info( "-o StrictHostKeyChecking=no", # Disable known hosts file "-o UserKnownHostsFile=/dev/null", - f"root@{hostname}", + f"{hostname}", "nixos-generate-config", # Filesystems are managed by disko "--no-filesystems", diff --git a/pkgs/clan-cli/clan_cli/machines/list.py b/pkgs/clan-cli/clan_cli/machines/list.py index a89504733..139ab9bde 100644 --- a/pkgs/clan-cli/clan_cli/machines/list.py +++ b/pkgs/clan-cli/clan_cli/machines/list.py @@ -1,6 +1,7 @@ import argparse import json import logging +from dataclasses import dataclass from pathlib import Path from clan_cli.api import API @@ -18,6 +19,33 @@ def list_inventory_machines(flake_url: str | Path) -> dict[str, Machine]: return inventory.machines +@dataclass +class MachineDetails: + machine: Machine + has_hw_specs: bool = False + # TODO: + # has_disk_specs: bool = False + + +@API.register +def get_inventory_machine_details( + flake_url: str | Path, machine_name: str +) -> MachineDetails: + inventory = load_inventory_eval(flake_url) + machine = inventory.machines.get(machine_name) + if machine is None: + raise ClanError(f"Machine {machine_name} not found in inventory") + + hw_config_path = ( + Path(flake_url) / "machines" / Path(machine_name) / "hardware-configuration.nix" + ) + + return MachineDetails( + machine=machine, + has_hw_specs=hw_config_path.exists(), + ) + + @API.register def list_nixos_machines(flake_url: str | Path) -> list[str]: cmd = nix_eval( diff --git a/pkgs/clan-cli/tests/test_machines_cli.py b/pkgs/clan-cli/tests/test_machines_cli.py index 10c8f22a6..1bfe53c0e 100644 --- a/pkgs/clan-cli/tests/test_machines_cli.py +++ b/pkgs/clan-cli/tests/test_machines_cli.py @@ -21,10 +21,6 @@ def test_machine_subcommands( assert "vm2" in out.out capsys.readouterr() - cli.run(["machines", "show", "--flake", str(test_flake_with_core.path), "machine1"]) - out = capsys.readouterr() - assert "machine1" in out.out - assert "Description" in out.out print(out) cli.run( diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx index 92a245918..e241d49ce 100644 --- a/pkgs/webview-ui/app/src/components/MachineListItem.tsx +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -3,6 +3,7 @@ import { callApi, SuccessData } from "../api"; import { Menu } from "./Menu"; import { activeURI } from "../App"; import toast from "solid-toast"; +import { useNavigate } from "@solidjs/router"; type MachineDetails = SuccessData<"list_inventory_machines">["data"][string]; @@ -16,7 +17,7 @@ export const MachineListItem = (props: MachineListItemProps) => { const { name, info, nixOnly } = props; const [deploying, setDeploying] = createSignal(false); - + const navigate = useNavigate(); return (
  • @@ -63,11 +64,11 @@ export const MachineListItem = (props: MachineListItemProps) => {