API: init methods: hw_generate, dns discovery
All checks were successful
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.postgresql Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.template-minimal Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
checks / checks-impure (pull_request) Successful in 2m15s
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
All checks were successful
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.postgresql Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.template-minimal Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
checks / checks-impure (pull_request) Successful in 2m15s
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
This commit is contained in:
parent
36a418b6ac
commit
b73246bdfd
|
@ -25,6 +25,10 @@ site_index: Path = (
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def sanitize_string(s: str) -> str:
|
||||||
|
return s.replace("\\", "\\\\").replace('"', '\\"')
|
||||||
|
|
||||||
|
|
||||||
def dataclass_to_dict(obj: Any) -> Any:
|
def dataclass_to_dict(obj: Any) -> Any:
|
||||||
"""
|
"""
|
||||||
Utility function to convert dataclasses to dictionaries
|
Utility function to convert dataclasses to dictionaries
|
||||||
|
@ -33,13 +37,18 @@ def dataclass_to_dict(obj: Any) -> Any:
|
||||||
It does NOT convert member functions.
|
It does NOT convert member functions.
|
||||||
"""
|
"""
|
||||||
if dataclasses.is_dataclass(obj):
|
if dataclasses.is_dataclass(obj):
|
||||||
return {k: dataclass_to_dict(v) for k, v in dataclasses.asdict(obj).items()}
|
return {
|
||||||
|
sanitize_string(k): dataclass_to_dict(v)
|
||||||
|
for k, v in dataclasses.asdict(obj).items()
|
||||||
|
}
|
||||||
elif isinstance(obj, list | tuple):
|
elif isinstance(obj, list | tuple):
|
||||||
return [dataclass_to_dict(item) for item in obj]
|
return [dataclass_to_dict(item) for item in obj]
|
||||||
elif isinstance(obj, dict):
|
elif isinstance(obj, dict):
|
||||||
return {k: dataclass_to_dict(v) for k, v in obj.items()}
|
return {sanitize_string(k): dataclass_to_dict(v) for k, v in obj.items()}
|
||||||
elif isinstance(obj, Path):
|
elif isinstance(obj, Path):
|
||||||
return str(obj)
|
return str(obj)
|
||||||
|
elif isinstance(obj, str):
|
||||||
|
return sanitize_string(obj)
|
||||||
else:
|
else:
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ from pathlib import Path
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
|
||||||
# These imports are unused, but necessary for @API.register to run once.
|
# These imports are unused, but necessary for @API.register to run once.
|
||||||
from clan_cli.api import directory
|
from clan_cli.api import directory, mdns_discovery
|
||||||
from clan_cli.arg_actions import AppendOptionAction
|
from clan_cli.arg_actions import AppendOptionAction
|
||||||
from clan_cli.clan import show
|
from clan_cli.clan import show
|
||||||
|
|
||||||
__all__ = ["directory"]
|
__all__ = ["directory", "mdns_discovery"]
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
backups,
|
backups,
|
||||||
|
|
116
pkgs/clan-cli/clan_cli/api/mdns_discovery.py
Normal file
116
pkgs/clan-cli/clan_cli/api/mdns_discovery.py
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
import argparse
|
||||||
|
import re
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from clan_cli.cmd import run_no_stdout
|
||||||
|
from clan_cli.nix import nix_shell
|
||||||
|
|
||||||
|
from . import API
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Host:
|
||||||
|
# Part of the discovery
|
||||||
|
interface: str
|
||||||
|
protocol: str
|
||||||
|
name: str
|
||||||
|
type_: str
|
||||||
|
domain: str
|
||||||
|
# Optional, only if more data is available
|
||||||
|
host: str | None
|
||||||
|
ip: str | None
|
||||||
|
port: str | None
|
||||||
|
txt: str | None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DNSInfo:
|
||||||
|
""" "
|
||||||
|
mDNS/DNS-SD services discovered on the network
|
||||||
|
"""
|
||||||
|
|
||||||
|
services: dict[str, Host]
|
||||||
|
|
||||||
|
|
||||||
|
def decode_escapes(s: str) -> str:
|
||||||
|
return re.sub(r"\\(\d{3})", lambda x: chr(int(x.group(1))), s)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_avahi_output(output: str) -> DNSInfo:
|
||||||
|
dns_info = DNSInfo(services={})
|
||||||
|
for line in output.splitlines():
|
||||||
|
parts = line.split(";")
|
||||||
|
# New service discovered
|
||||||
|
# print(parts)
|
||||||
|
if parts[0] == "+" and len(parts) >= 6:
|
||||||
|
interface, protocol, name, type_, domain = parts[1:6]
|
||||||
|
|
||||||
|
name = decode_escapes(name)
|
||||||
|
|
||||||
|
dns_info.services[name] = Host(
|
||||||
|
interface=interface,
|
||||||
|
protocol=protocol,
|
||||||
|
name=name,
|
||||||
|
type_=decode_escapes(type_),
|
||||||
|
domain=domain,
|
||||||
|
host=None,
|
||||||
|
ip=None,
|
||||||
|
port=None,
|
||||||
|
txt=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Resolved more data for already discovered services
|
||||||
|
elif parts[0] == "=" and len(parts) >= 9:
|
||||||
|
interface, protocol, name, type_, domain, host, ip, port = parts[1:9]
|
||||||
|
|
||||||
|
name = decode_escapes(name)
|
||||||
|
|
||||||
|
if name in dns_info.services:
|
||||||
|
dns_info.services[name].host = decode_escapes(host)
|
||||||
|
dns_info.services[name].ip = ip
|
||||||
|
dns_info.services[name].port = port
|
||||||
|
if len(parts) > 9:
|
||||||
|
dns_info.services[name].txt = decode_escapes(parts[9])
|
||||||
|
else:
|
||||||
|
dns_info.services[name] = Host(
|
||||||
|
interface=parts[1],
|
||||||
|
protocol=parts[2],
|
||||||
|
name=name,
|
||||||
|
type_=decode_escapes(parts[4]),
|
||||||
|
domain=parts[5],
|
||||||
|
host=decode_escapes(parts[6]),
|
||||||
|
ip=parts[7],
|
||||||
|
port=parts[8],
|
||||||
|
txt=decode_escapes(parts[9]) if len(parts) > 9 else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
return dns_info
|
||||||
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def show_mdns() -> DNSInfo:
|
||||||
|
cmd = nix_shell(
|
||||||
|
["nixpkgs#avahi"],
|
||||||
|
[
|
||||||
|
"avahi-browse",
|
||||||
|
"--all",
|
||||||
|
"--resolve",
|
||||||
|
"--parsable",
|
||||||
|
"-l", # Ignore local services
|
||||||
|
"--terminate",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
proc = run_no_stdout(cmd)
|
||||||
|
data = parse_avahi_output(proc.stdout)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def mdns_command(args: argparse.Namespace) -> None:
|
||||||
|
dns_info = show_mdns()
|
||||||
|
for name, info in dns_info.services.items():
|
||||||
|
print(f"Hostname: {name} - ip: {info.ip}")
|
||||||
|
|
||||||
|
|
||||||
|
def register_mdns(parser: argparse.ArgumentParser) -> None:
|
||||||
|
parser.set_defaults(func=mdns_command)
|
|
@ -20,6 +20,72 @@ class HardwareInfo:
|
||||||
system: str | None
|
system: str | None
|
||||||
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def show_machine_hardware_info(
|
||||||
|
clan_dir: str | Path, machine_name: str
|
||||||
|
) -> HardwareInfo | None:
|
||||||
|
"""
|
||||||
|
Show hardware information for a machine returns None if none exist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
hw_file = Path(f"{clan_dir}/machines/{machine_name}/hardware-configuration.nix")
|
||||||
|
|
||||||
|
is_template = hw_file.exists() and "throw" in hw_file.read_text()
|
||||||
|
if not hw_file.exists() or is_template:
|
||||||
|
return None
|
||||||
|
|
||||||
|
system = show_machine_hardware_platform(clan_dir, machine_name)
|
||||||
|
return HardwareInfo(system)
|
||||||
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def show_machine_deployment_target(
|
||||||
|
clan_dir: str | Path, machine_name: str
|
||||||
|
) -> str | None:
|
||||||
|
"""
|
||||||
|
Show hardware information for a machine returns None if none exist.
|
||||||
|
"""
|
||||||
|
config = nix_config()
|
||||||
|
system = config["system"]
|
||||||
|
cmd = nix_eval(
|
||||||
|
[
|
||||||
|
f"{clan_dir}#clanInternals.machines.{system}.{machine_name}",
|
||||||
|
"--apply",
|
||||||
|
"machine: { inherit (machine.config.clan.networking) targetHost; }",
|
||||||
|
"--json",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
proc = run_no_stdout(cmd)
|
||||||
|
res = proc.stdout.strip()
|
||||||
|
|
||||||
|
target_host = json.loads(res)
|
||||||
|
return target_host.get("targetHost", None)
|
||||||
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def show_machine_hardware_platform(
|
||||||
|
clan_dir: str | Path, machine_name: str
|
||||||
|
) -> str | None:
|
||||||
|
"""
|
||||||
|
Show hardware information for a machine returns None if none exist.
|
||||||
|
"""
|
||||||
|
config = nix_config()
|
||||||
|
system = config["system"]
|
||||||
|
cmd = nix_eval(
|
||||||
|
[
|
||||||
|
f"{clan_dir}#clanInternals.machines.{system}.{machine_name}",
|
||||||
|
"--apply",
|
||||||
|
"machine: { inherit (machine.config.nixpkgs.hostPlatform) system; }",
|
||||||
|
"--json",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
proc = run_no_stdout(cmd)
|
||||||
|
res = proc.stdout.strip()
|
||||||
|
|
||||||
|
host_platform = json.loads(res)
|
||||||
|
return host_platform.get("system", None)
|
||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def generate_machine_hardware_info(
|
def generate_machine_hardware_info(
|
||||||
clan_dir: str | Path,
|
clan_dir: str | Path,
|
||||||
|
@ -63,9 +129,7 @@ def generate_machine_hardware_info(
|
||||||
hw_file.parent.mkdir(parents=True, exist_ok=True)
|
hw_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Check if the hardware-configuration.nix file is a template
|
# Check if the hardware-configuration.nix file is a template
|
||||||
is_template = False
|
is_template = hw_file.exists() and "throw" in hw_file.read_text()
|
||||||
if hw_file.exists():
|
|
||||||
is_template = "throw" in hw_file.read_text()
|
|
||||||
|
|
||||||
if hw_file.exists() and not force and not is_template:
|
if hw_file.exists() and not force and not is_template:
|
||||||
raise ClanError(
|
raise ClanError(
|
||||||
|
@ -78,25 +142,8 @@ def generate_machine_hardware_info(
|
||||||
f.write(out.stdout)
|
f.write(out.stdout)
|
||||||
print(f"Successfully generated: {hw_file}")
|
print(f"Successfully generated: {hw_file}")
|
||||||
|
|
||||||
# TODO: This could be its own API function?
|
system = show_machine_hardware_platform(clan_dir, machine_name)
|
||||||
config = nix_config()
|
return HardwareInfo(system)
|
||||||
system = config["system"]
|
|
||||||
cmd = nix_eval(
|
|
||||||
[
|
|
||||||
f"{clan_dir}#clanInternals.machines.{system}.{machine_name}",
|
|
||||||
"--apply",
|
|
||||||
"machine: { inherit (machine.config.nixpkgs.hostPlatform) system; }",
|
|
||||||
"--json",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
proc = run_no_stdout(cmd)
|
|
||||||
res = proc.stdout.strip()
|
|
||||||
|
|
||||||
host_platform = json.loads(res)
|
|
||||||
|
|
||||||
return HardwareInfo(
|
|
||||||
system=host_platform.get("system", None),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def hw_generate_command(args: argparse.Namespace) -> None:
|
def hw_generate_command(args: argparse.Namespace) -> None:
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Toaster } from "solid-toast";
|
||||||
const [route, setRoute] = createSignal<Route>("machines");
|
const [route, setRoute] = createSignal<Route>("machines");
|
||||||
|
|
||||||
const [currClanURI, setCurrClanURI] = createSignal<string>(
|
const [currClanURI, setCurrClanURI] = createSignal<string>(
|
||||||
"/home/johannes/1_clans/myclan"
|
"/home/johannes/git/testing/xd"
|
||||||
);
|
);
|
||||||
|
|
||||||
export { currClanURI, setCurrClanURI };
|
export { currClanURI, setCurrClanURI };
|
||||||
|
|
|
@ -100,6 +100,7 @@ const deserialize =
|
||||||
try {
|
try {
|
||||||
fn(JSON.parse(str) as T);
|
fn(JSON.parse(str) as T);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(str);
|
||||||
alert(`Error parsing JSON: ${e}`);
|
alert(`Error parsing JSON: ${e}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { For, Show, createSignal } from "solid-js";
|
import { For, Match, Show, Switch, createSignal } from "solid-js";
|
||||||
import { ErrorData, SuccessData, pyApi } from "../api";
|
import { ErrorData, SuccessData, pyApi } from "../api";
|
||||||
import { currClanURI } from "../App";
|
import { currClanURI } from "../App";
|
||||||
|
|
||||||
|
@ -7,10 +7,19 @@ interface MachineListItemProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MachineDetails = Record<string, SuccessData<"show_machine">["data"]>;
|
type MachineDetails = Record<string, SuccessData<"show_machine">["data"]>;
|
||||||
|
type HWInfo = Record<string, SuccessData<"show_machine_hardware_info">["data"]>;
|
||||||
|
type DeploymentInfo = Record<
|
||||||
|
string,
|
||||||
|
SuccessData<"show_machine_deployment_target">["data"]
|
||||||
|
>;
|
||||||
|
|
||||||
type MachineErrors = Record<string, ErrorData<"show_machine">["errors"]>;
|
type MachineErrors = Record<string, ErrorData<"show_machine">["errors"]>;
|
||||||
|
|
||||||
const [details, setDetails] = createSignal<MachineDetails>({});
|
const [details, setDetails] = createSignal<MachineDetails>({});
|
||||||
|
const [hwInfo, setHwInfo] = createSignal<HWInfo>({});
|
||||||
|
|
||||||
|
const [deploymentInfo, setDeploymentInfo] = createSignal<DeploymentInfo>({});
|
||||||
|
|
||||||
const [errors, setErrors] = createSignal<MachineErrors>({});
|
const [errors, setErrors] = createSignal<MachineErrors>({});
|
||||||
|
|
||||||
pyApi.show_machine.receive((r) => {
|
pyApi.show_machine.receive((r) => {
|
||||||
|
@ -26,6 +35,34 @@ pyApi.show_machine.receive((r) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pyApi.show_machine_hardware_info.receive((r) => {
|
||||||
|
const { op_key } = r;
|
||||||
|
if (r.status === "error") {
|
||||||
|
console.error(r.errors);
|
||||||
|
if (op_key) {
|
||||||
|
setHwInfo((d) => ({ ...d, [op_key]: { system: null } }));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (op_key) {
|
||||||
|
setHwInfo((d) => ({ ...d, [op_key]: r.data }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
pyApi.show_machine_deployment_target.receive((r) => {
|
||||||
|
const { op_key } = r;
|
||||||
|
if (r.status === "error") {
|
||||||
|
console.error(r.errors);
|
||||||
|
if (op_key) {
|
||||||
|
setDeploymentInfo((d) => ({ ...d, [op_key]: null }));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (op_key) {
|
||||||
|
setDeploymentInfo((d) => ({ ...d, [op_key]: r.data }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export const MachineListItem = (props: MachineListItemProps) => {
|
export const MachineListItem = (props: MachineListItemProps) => {
|
||||||
const { name } = props;
|
const { name } = props;
|
||||||
|
|
||||||
|
@ -35,6 +72,18 @@ export const MachineListItem = (props: MachineListItemProps) => {
|
||||||
flake_url: currClanURI(),
|
flake_url: currClanURI(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pyApi.show_machine_hardware_info.dispatch({
|
||||||
|
op_key: name,
|
||||||
|
clan_dir: currClanURI(),
|
||||||
|
machine_name: name,
|
||||||
|
});
|
||||||
|
|
||||||
|
pyApi.show_machine_deployment_target.dispatch({
|
||||||
|
op_key: name,
|
||||||
|
clan_dir: currClanURI(),
|
||||||
|
machine_name: name,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<div class="card card-side m-2 bg-base-100 shadow-lg">
|
<div class="card card-side m-2 bg-base-100 shadow-lg">
|
||||||
|
@ -46,27 +95,60 @@ export const MachineListItem = (props: MachineListItemProps) => {
|
||||||
<div class="card-body flex-row justify-between">
|
<div class="card-body flex-row justify-between">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<h2 class="card-title">{name}</h2>
|
<h2 class="card-title">{name}</h2>
|
||||||
<Show when={errors()[name]}>
|
<div class="text-slate-600">
|
||||||
{(errors) => (
|
<Show
|
||||||
<For each={errors()}>
|
when={details()[name]}
|
||||||
{(error) => (
|
fallback={
|
||||||
<p class="text-red-500">
|
<Switch fallback={<div class="skeleton h-8 w-full"></div>}>
|
||||||
{error.message}: {error.description}
|
<Match when={!details()[name]?.machine_description}>
|
||||||
</p>
|
No description
|
||||||
)}
|
</Match>
|
||||||
</For>
|
</Switch>
|
||||||
)}
|
}
|
||||||
</Show>
|
>
|
||||||
<Show when={details()[name]}>
|
{(d) => d()?.machine_description}
|
||||||
{(details) => (
|
</Show>
|
||||||
<p
|
</div>
|
||||||
classList={{
|
<div class="flex flex-row flex-wrap gap-4 py-2">
|
||||||
"text-gray-400": !details().machine_description,
|
<div class="badge badge-primary flex flex-row gap-1 py-4 align-middle">
|
||||||
"text-gray-600": !!details().machine_description,
|
<span class="material-icons">
|
||||||
}}
|
{hwInfo()[name]?.system ? "check" : "pending"}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<Switch fallback={<div class="skeleton h-8 w-full"></div>}>
|
||||||
|
<Match when={hwInfo()[name]?.system}>
|
||||||
|
{(system) => "System: " + system()}
|
||||||
|
</Match>
|
||||||
|
<Match when={hwInfo()[name]?.system === null}>
|
||||||
|
{"No hardware info"}
|
||||||
|
</Match>
|
||||||
|
</Switch>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="badge badge-primary flex flex-row gap-1 py-4 align-middle">
|
||||||
|
<span class="material-icons">
|
||||||
|
{deploymentInfo()[name] ? "check" : "pending"}
|
||||||
|
</span>
|
||||||
|
<Show
|
||||||
|
when={deploymentInfo()[name]}
|
||||||
|
fallback={
|
||||||
|
<Switch fallback={<div class="skeleton h-8 w-full"></div>}>
|
||||||
|
<Match when={deploymentInfo()[name] !== undefined}>
|
||||||
|
No deployment target detected
|
||||||
|
</Match>
|
||||||
|
</Switch>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{details().machine_description || "No description"}
|
{(i) => "Deploys to: " + i()}
|
||||||
</p>
|
</Show>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/* Show only the first error at the bottom */}
|
||||||
|
<Show when={errors()[name]?.[0]}>
|
||||||
|
{(error) => (
|
||||||
|
<div class="badge badge-error py-4">
|
||||||
|
Error: {error().message}: {error().description}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
For,
|
For,
|
||||||
Match,
|
Match,
|
||||||
|
Show,
|
||||||
Switch,
|
Switch,
|
||||||
createEffect,
|
createEffect,
|
||||||
createSignal,
|
createSignal,
|
||||||
|
@ -17,6 +18,11 @@ type FilesModel = Extract<
|
||||||
{ status: "success" }
|
{ status: "success" }
|
||||||
>["data"]["files"];
|
>["data"]["files"];
|
||||||
|
|
||||||
|
type ServiceModel = Extract<
|
||||||
|
OperationResponse<"show_mdns">,
|
||||||
|
{ status: "success" }
|
||||||
|
>["data"]["services"];
|
||||||
|
|
||||||
export const MachineListView: Component = () => {
|
export const MachineListView: Component = () => {
|
||||||
const [{ machines, loading }, { getMachines }] = useMachineContext();
|
const [{ machines, loading }, { getMachines }] = useMachineContext();
|
||||||
|
|
||||||
|
@ -27,6 +33,13 @@ export const MachineListView: Component = () => {
|
||||||
setFiles(r.data.files);
|
setFiles(r.data.files);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [services, setServices] = createSignal<ServiceModel>();
|
||||||
|
pyApi.show_mdns.receive((r) => {
|
||||||
|
const { status } = r;
|
||||||
|
if (status === "error") return console.error(r.errors);
|
||||||
|
setServices(r.data.services);
|
||||||
|
});
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
console.log(files());
|
console.log(files());
|
||||||
});
|
});
|
||||||
|
@ -72,11 +85,66 @@ export const MachineListView: Component = () => {
|
||||||
<span class="material-icons ">folder_open</span>
|
<span class="material-icons ">folder_open</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tooltip" data-tip="Search install targets">
|
||||||
|
<button
|
||||||
|
class="btn btn-ghost"
|
||||||
|
onClick={() => pyApi.show_mdns.dispatch({})}
|
||||||
|
>
|
||||||
|
<span class="material-icons ">search</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div class="tooltip" data-tip="Refresh">
|
<div class="tooltip" data-tip="Refresh">
|
||||||
<button class="btn btn-ghost" onClick={() => getMachines()}>
|
<button class="btn btn-ghost" onClick={() => getMachines()}>
|
||||||
<span class="material-icons ">refresh</span>
|
<span class="material-icons ">refresh</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<Show when={services()}>
|
||||||
|
{(services) => (
|
||||||
|
<For each={Object.values(services())}>
|
||||||
|
{(service) => (
|
||||||
|
<div class="rounded-lg bg-white p-5 shadow-lg">
|
||||||
|
<h2 class="mb-2 text-xl font-semibold">{service.name}</h2>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Interface:</span>
|
||||||
|
{service.interface}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Protocol:</span>
|
||||||
|
{service.protocol}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Name</span>
|
||||||
|
{service.name}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Type:</span>
|
||||||
|
{service.type_}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Domain:</span>
|
||||||
|
{service.domain}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Host:</span>
|
||||||
|
{service.host}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">IP:</span>
|
||||||
|
{service.ip}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">Port:</span>
|
||||||
|
{service.port}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">TXT:</span>
|
||||||
|
{service.txt}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
)}
|
||||||
|
</Show>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Match when={loading()}>
|
<Match when={loading()}>
|
||||||
{/* Loading skeleton */}
|
{/* Loading skeleton */}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user