| 1 | /** libvirt's virDomainState, minus "nostate". "shutdown" means a shutdown is under way. */ |
| 2 | export type DomainState = "running" | "blocked" | "paused" | "shutdown" | "shutoff" | "crashed" | "pmsuspended"; |
| 3 | |
| 4 | export 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 | |
| 15 | export 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 | |
| 24 | export interface Domain { |
| 25 | name: string; |
| 26 | owner: string | null; |
| 27 | /** What it's for, from the domain's `<description>`; empty when unset. */ |
| 28 | description: string; |
| 29 | state: DomainState; |
| 30 | /** libvirt's reason for a paused or crashed state, like "user", "ioerror" or "panicked"; null otherwise. */ |
| 31 | reason: string | null; |
| 32 | os: string; |
| 33 | vcpus: number; |
| 34 | /** Host threads the vCPUs are pinned to; null when they float over all of them. */ |
| 35 | pinned: number[] | null; |
| 36 | /** The most memory the guest can have. */ |
| 37 | memory: number; |
| 38 | /** What the balloon currently gives the guest, at most `memory`. */ |
| 39 | balloon: number; |
| 40 | autostart: boolean; |
| 41 | /** Unix seconds the QEMU process started; null while shut off. */ |
| 42 | startedAt: number | null; |
| 43 | /** The latest sample: cpu as percent of its vCPUs, memory as bytes the guest uses; null while off. */ |
| 44 | usage: { cpu: number; memory: number } | null; |
| 45 | /** The guest agent channel's state; null when the domain has none. */ |
| 46 | agent: "connected" | "disconnected" | null; |
| 47 | disks: Disk[]; |
| 48 | media: { target: string; source: string | null }[]; |
| 49 | firmware: "bios" | "uefi"; |
| 50 | platform: "linux" | "windows"; |
| 51 | console: boolean; |
| 52 | serial: boolean; |
| 53 | /** `source` is the bridge or libvirt network; addresses come from DHCP leases. */ |
| 54 | interfaces: { mac: string; source: string; addresses: string[] }[]; |
| 55 | hostdevs: Hostdev[]; |
| 56 | } |
| 57 | |
| 58 | export interface Installer { |
| 59 | volume: string; |
| 60 | os: string; |
| 61 | arch: "x86_64" | "aarch64"; |
| 62 | capacity: number; |
| 63 | recommended: { vcpus: number; memory: number; disk: number }; |
| 64 | } |
| 65 | |
| 66 | /** Samples on one time axis; cpu is percent of the domain's vCPUs, memory is bytes the guest uses. */ |
| 67 | export interface History { |
| 68 | t: number[]; |
| 69 | domains: Record<string, { cpu: (number | null)[]; memory: (number | null)[] }>; |
| 70 | } |
| 71 | |
| 72 | export const DOMAIN_ACTIONS = ["start", "shutdown", "reboot", "destroy", "resume"] as const; |
| 73 | export interface Preset { |
| 74 | id: string; |
| 75 | os: string; |
| 76 | description: string; |
| 77 | firmware: "bios" | "uefi"; |
| 78 | platform: "linux" | "windows"; |
| 79 | capacity: number; |
| 80 | createdAt: number; |
| 81 | recommended: { vcpus: number; memory: number; disk: number }; |
| 82 | } |
| 83 | export interface VMLibrary { |
| 84 | arch: "x86_64"; |
| 85 | installers: Installer[]; |
| 86 | presets: Preset[]; |
| 87 | } |
| 88 | export type NewDomain = {mode:"iso"|"preset";firmware:"bios"|"uefi";platform:"linux"|"windows";name:string;image:string;vcpus:number;memory:number;disk:number}; |