diff --git a/pkgs/clan-cli/clan_cli/api/directory.py b/pkgs/clan-cli/clan_cli/api/directory.py index f08e34c0..e37b13f5 100644 --- a/pkgs/clan-cli/clan_cli/api/directory.py +++ b/pkgs/clan-cli/clan_cli/api/directory.py @@ -1,9 +1,11 @@ +import json import os from dataclasses import dataclass, field from pathlib import Path -from typing import Literal +from typing import Any, Literal from clan_cli.errors import ClanError +from clan_cli.nix import nix_shell, run_no_stdout from . import API @@ -81,3 +83,46 @@ def get_directory(current_path: str) -> Directory: ) return directory + + +@dataclass +class BlkInfo: + name: str + rm: str + size: str + ro: bool + mountpoints: list[str] + type_: Literal["disk"] + + +@dataclass +class Blockdevices: + blockdevices: list[BlkInfo] + + +def blk_from_dict(data: dict) -> BlkInfo: + return BlkInfo( + name=data["name"], + rm=data["rm"], + size=data["size"], + ro=data["ro"], + mountpoints=data["mountpoints"], + type_=data["type"], # renamed here + ) + + +@API.register +def show_block_devices() -> Blockdevices: + """ + Abstract api method to show block devices. + It must return a list of block devices. + """ + cmd = nix_shell(["nixpkgs#util-linux"], ["lsblk", "--json"]) + proc = run_no_stdout(cmd) + res = proc.stdout.strip() + + blk_info: dict[str, Any] = json.loads(res) + + return Blockdevices( + blockdevices=[blk_from_dict(device) for device in blk_info["blockdevices"]] + ) diff --git a/pkgs/webview-ui/app/src/Routes.tsx b/pkgs/webview-ui/app/src/Routes.tsx index 38b69179..12af6621 100644 --- a/pkgs/webview-ui/app/src/Routes.tsx +++ b/pkgs/webview-ui/app/src/Routes.tsx @@ -3,6 +3,7 @@ import { MachineListView } from "./routes/machines/view"; import { colors } from "./routes/colors/view"; import { clan } from "./routes/clan/view"; import { HostList } from "./routes/hosts/view"; +import { BlockDevicesView } from "./routes/blockdevices/view"; export type Route = keyof typeof routes; @@ -22,6 +23,11 @@ export const routes = { label: "hosts", icon: "devices_other", }, + blockdevices: { + child: BlockDevicesView, + label: "blockdevices", + icon: "devices_other", + }, colors: { child: colors, label: "Colors", diff --git a/pkgs/webview-ui/app/src/routes/blockdevices/view.tsx b/pkgs/webview-ui/app/src/routes/blockdevices/view.tsx new file mode 100644 index 00000000..2ab4d423 --- /dev/null +++ b/pkgs/webview-ui/app/src/routes/blockdevices/view.tsx @@ -0,0 +1,61 @@ +import { route } from "@/src/App"; +import { OperationResponse, pyApi } from "@/src/api"; +import { Component, For, Show, createEffect, createSignal } from "solid-js"; + +type DevicesModel = Extract< + OperationResponse<"show_block_devices">, + { status: "success" } +>["data"]["blockdevices"]; + +export const BlockDevicesView: Component = () => { + const [devices, setServices] = createSignal(); + + pyApi.show_block_devices.receive((r) => { + const { status } = r; + if (status === "error") return console.error(r.errors); + setServices(r.data.blockdevices); + }); + + createEffect(() => { + if (route() === "blockdevices") pyApi.show_block_devices.dispatch({}); + }); + + return ( +
+
+ +
+
+ + {(devices) => ( + + {(device) => ( +
+
+
Name
+
+ {" "} + storage {device.name} +
+
+
+ +
+
Size
+
{device.size}
+
+
+
+ )} +
+ )} +
+
+
+ ); +}; diff --git a/pkgs/webview-ui/app/src/routes/hosts/view.tsx b/pkgs/webview-ui/app/src/routes/hosts/view.tsx index c12f234b..cb49d191 100644 --- a/pkgs/webview-ui/app/src/routes/hosts/view.tsx +++ b/pkgs/webview-ui/app/src/routes/hosts/view.tsx @@ -1,16 +1,12 @@ import { For, - Match, Show, - Switch, createEffect, createSignal, type Component, } from "solid-js"; -import { useMachineContext } from "../../Config"; import { route } from "@/src/App"; import { OperationResponse, pyApi } from "@/src/api"; -import toast from "solid-toast"; type ServiceModel = Extract< OperationResponse<"show_mdns">, @@ -40,13 +36,13 @@ export const HostList: Component = () => { refresh -
+
{(services) => ( {(service) => ( -
-
+
+
Host
{service.host}
@@ -61,7 +57,7 @@ export const HostList: Component = () => {
-
+
Details