Clan-app: generate hw spec via ssh

This commit is contained in:
Johannes Kirschbauer
2024-08-14 16:16:51 +02:00
parent eb844e83fe
commit 3f46d37b67
8 changed files with 148 additions and 29 deletions

View File

@@ -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",

View File

@@ -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(

View File

@@ -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(