1/** libvirt's virDomainState, minus "nostate". "shutdown" means a shutdown is under way. */
2export type DomainState = "running" | "blocked" | "paused" | "shutdown" | "shutoff" | "crashed" | "pmsuspended";
3
4export interface Disk {
5 /** Guest device, like "vda". */
6 target: string;
7 /** Storage pool of a volume disk; null for a host block device passed through. */
8 pool: string | null;
9 /** Volume name, or the host device path. */
10 source: string;
11 capacity: number;
12 allocation: number;
13}
14
15export interface Hostdev {
16 /** Product name from the host's device database, like "GA104 [GeForce RTX 3070]". */
17 name: string;
18 /** A PCI address like "0000:01:00.0", or a USB "vendor:product". */
19 address: string;
20 /** Devices in one IOMMU group can only pass through together; null for USB. */
21 iommuGroup: number | null;
22}
23
24type Platform = "linux" | "windows" | "macos";
25
26export const VM_SETUP = {
27 starting: "Starting Windows…",
28 personalizing: "Preparing your account…",
29 restarting: "Restarting to finish setup…",
30 ready: "Ready",
31 failed: "Setup stopped",
32} as const;
33
34export interface Domain {
35 name: string;
36 owner: string | null;
37 /** What it's for, from the domain's `<description>`; empty when unset. */
38 description: string;
39 state: DomainState;
40 /** libvirt's reason for a paused or crashed state, like "user", "ioerror" or "panicked"; null otherwise. */
41 reason: string | null;
42 os: string;
43 vcpus: number;
44 /** Host threads the vCPUs are pinned to; null when they float over all of them. */
45 pinned: number[] | null;
46 /** The most memory the guest can have. */
47 memory: number;
48 /** What the balloon currently gives the guest, at most `memory`. */
49 balloon: number;
50 autostart: boolean;
51 /** Unix seconds the QEMU process started; null while shut off. */
52 startedAt: number | null;
53 /** The latest sample: cpu as percent of its vCPUs, memory as bytes the guest uses; null while off. */
54 usage: { cpu: number; memory: number } | null;
55 /** The guest agent channel's state; null when the domain has none. */
56 agent: "connected" | "disconnected" | null;
57 setup: keyof typeof VM_SETUP | null;
58 disks: Disk[];
59 media: { target: string; source: string | null }[];
60 firmware: "bios" | "uefi";
61 platform: Platform;
62 console: boolean;
63 serial: boolean;
64 /** `source` is the bridge or libvirt network; addresses come from DHCP leases. */
65 interfaces: { mac: string; source: string; addresses: string[] }[];
66 hostdevs: Hostdev[];
67}
68
69export interface Installer {
70 volume: string;
71 os: string;
72 arch: "x86_64" | "aarch64";
73 capacity: number;
74 recommended: { vcpus: number; memory: number; disk: number };
75}
76
77/** Samples on one time axis; cpu is percent of the domain's vCPUs, memory is bytes the guest uses. */
78export interface History {
79 t: number[];
80 domains: Record<string, { cpu: (number | null)[]; memory: (number | null)[] }>;
81}
82
83export const DOMAIN_ACTIONS = ["start", "shutdown", "reboot", "destroy", "resume"] as const;
84export interface Preset {
85 id: string;
86 os: string;
87 description: string;
88 firmware: "bios" | "uefi";
89 platform: Platform;
90 capacity: number;
91 createdAt: number;
92 recommended: { vcpus: number; memory: number; disk: number };
93}
94export interface VMLibrary {
95 arch: "x86_64";
96 installers: Installer[];
97 presets: Preset[];
98}
99export type NewDomain = {mode:"iso"|"preset";firmware:"bios"|"uefi";platform:Platform;name:string;image:string;vcpus:number;memory:number;disk:number};