2023-09-28 16:27:06 +00:00
|
|
|
import argparse
|
2023-10-03 14:47:14 +00:00
|
|
|
import json
|
2023-11-21 10:36:50 +00:00
|
|
|
from dataclasses import dataclass
|
2023-10-12 20:46:32 +00:00
|
|
|
from pathlib import Path
|
2023-09-28 16:27:06 +00:00
|
|
|
|
2024-06-04 13:49:11 +00:00
|
|
|
from ..completions import add_dynamic_completer, complete_machines
|
2024-01-19 13:37:30 +00:00
|
|
|
from ..machines.machines import Machine
|
2023-10-25 11:10:30 +00:00
|
|
|
|
2023-10-03 14:47:14 +00:00
|
|
|
|
2023-11-21 10:36:50 +00:00
|
|
|
@dataclass
|
|
|
|
class VmConfig:
|
2024-01-19 13:37:30 +00:00
|
|
|
machine_name: str
|
2024-02-06 12:25:34 +00:00
|
|
|
machine_icon: Path
|
|
|
|
machine_description: str
|
2023-11-21 10:36:50 +00:00
|
|
|
flake_url: str | Path
|
2024-01-19 13:37:30 +00:00
|
|
|
clan_name: str
|
2023-10-03 14:47:14 +00:00
|
|
|
|
|
|
|
cores: int
|
|
|
|
memory_size: int
|
|
|
|
graphics: bool
|
2024-02-01 02:52:20 +00:00
|
|
|
waypipe: bool = False
|
2023-10-03 14:47:14 +00:00
|
|
|
|
|
|
|
|
2024-01-19 13:37:30 +00:00
|
|
|
def inspect_vm(machine: Machine) -> VmConfig:
|
2024-06-17 10:42:28 +00:00
|
|
|
data = json.loads(machine.eval_nix("config.clan.core.vm.inspect"))
|
2024-03-08 15:01:54 +00:00
|
|
|
return VmConfig(flake_url=str(machine.flake), **data)
|
2023-09-28 16:27:06 +00:00
|
|
|
|
|
|
|
|
2023-12-08 10:47:25 +00:00
|
|
|
@dataclass
|
|
|
|
class InspectOptions:
|
|
|
|
machine: str
|
|
|
|
flake: Path
|
|
|
|
|
|
|
|
|
2023-10-03 14:47:14 +00:00
|
|
|
def inspect_command(args: argparse.Namespace) -> None:
|
2023-12-08 10:47:25 +00:00
|
|
|
inspect_options = InspectOptions(
|
|
|
|
machine=args.machine,
|
|
|
|
flake=args.flake or Path.cwd(),
|
|
|
|
)
|
2024-01-19 13:37:30 +00:00
|
|
|
|
|
|
|
machine = Machine(inspect_options.machine, inspect_options.flake)
|
|
|
|
res = inspect_vm(machine)
|
2023-10-03 14:47:14 +00:00
|
|
|
print("Cores:", res.cores)
|
|
|
|
print("Memory size:", res.memory_size)
|
|
|
|
print("Graphics:", res.graphics)
|
2023-09-28 16:27:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def register_inspect_parser(parser: argparse.ArgumentParser) -> None:
|
2024-06-04 13:49:11 +00:00
|
|
|
machine_action = parser.add_argument("machine", type=str, default="defaultVM")
|
|
|
|
add_dynamic_completer(machine_action, complete_machines)
|
2023-10-03 14:47:14 +00:00
|
|
|
parser.set_defaults(func=inspect_command)
|