diff --git a/pkgs/clan-cli/clan_cli/api/directory.py b/pkgs/clan-cli/clan_cli/api/directory.py index d47225b3b..895749709 100644 --- a/pkgs/clan-cli/clan_cli/api/directory.py +++ b/pkgs/clan-cli/clan_cli/api/directory.py @@ -90,6 +90,7 @@ def get_directory(current_path: str) -> Directory: @dataclass class BlkInfo: name: str + id_link: str path: str rm: str size: str @@ -111,19 +112,47 @@ def blk_from_dict(data: dict) -> BlkInfo: size=data["size"], ro=data["ro"], mountpoints=data["mountpoints"], - type_=data["type"], # renamed here + type_=data["type"], # renamed + id_link=data["id-link"], # renamed ) +@dataclass +class BlockDeviceOptions: + hostname: str | None = None + keyfile: str | None = None + + @API.register -def show_block_devices() -> Blockdevices: +def show_block_devices(options: BlockDeviceOptions) -> Blockdevices: """ Abstract api method to show block devices. It must return a list of block devices. """ + keyfile = options.keyfile + remote = ( + [ + "ssh", + *(["-i", f"{keyfile}"] if keyfile else []), + # Disable strict host key checking + "-o StrictHostKeyChecking=no", + # Disable known hosts file + "-o UserKnownHostsFile=/dev/null", + f"{options.hostname}", + ] + if options.hostname + else [] + ) + cmd = nix_shell( - ["nixpkgs#util-linux"], - ["lsblk", "--json", "--output", "PATH,NAME,RM,SIZE,RO,MOUNTPOINTS,TYPE"], + ["nixpkgs#util-linux", *(["nixpkgs#openssh"] if options.hostname else [])], + [ + *remote, + "lsblk", + "--json", + "--output", + "PATH,NAME,RM,SIZE,RO,MOUNTPOINTS,TYPE,ID-LINK", + ], ) proc = run_no_stdout(cmd) res = proc.stdout.strip() diff --git a/pkgs/webview-ui/app/src/routes/flash/view.tsx b/pkgs/webview-ui/app/src/routes/flash/view.tsx index 37618e419..309e00cd0 100644 --- a/pkgs/webview-ui/app/src/routes/flash/view.tsx +++ b/pkgs/webview-ui/app/src/routes/flash/view.tsx @@ -83,7 +83,7 @@ export const Flash = () => { const deviceQuery = createQuery(() => ({ queryKey: ["block_devices"], queryFn: async () => { - const result = await callApi("show_block_devices", {}); + const result = await callApi("show_block_devices", { options: {} }); if (result.status === "error") throw new Error("Failed to fetch data"); return result.data; },