Clan-app: generate hw spec via ssh

This commit is contained in:
Johannes Kirschbauer
2024-08-14 16:16:51 +02:00
parent 6709d47ae5
commit c86b14d34d
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(