| 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 | /** What it's for, from the domain's `<description>`; empty when unset. */ |
| 27 | description: string; |
| 28 | state: DomainState; |
| 29 | /** libvirt's reason for a paused or crashed state, like "user", "ioerror" or "panicked"; null otherwise. */ |
| 30 | reason: string | null; |
| 31 | /** libosinfo's name for the guest OS, like "Windows 11". */ |
| 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 | /** `source` is the bridge or libvirt network; addresses come from the guest agent. */ |
| 49 | interfaces: { mac: string; source: string; addresses: string[] }[]; |
| 50 | hostdevs: Hostdev[]; |
| 51 | } |
| 52 | |
| 53 | /** A volume in the images pool; installers attach as a CD, disk images are cloned into the new disk. */ |
| 54 | export interface Image { |
| 55 | volume: string; |
| 56 | os: string; |
| 57 | kind: "installer" | "disk"; |
| 58 | capacity: number; |
| 59 | /** libosinfo's recommended resources. */ |
| 60 | recommended: { vcpus: number; memory: number; disk: number }; |
| 61 | } |
| 62 | |
| 63 | /** Samples on one time axis; cpu is percent of the domain's vCPUs, memory is bytes the guest uses. */ |
| 64 | export interface History { |
| 65 | t: number[]; |
| 66 | domains: Record<string, { cpu: (number | null)[]; memory: (number | null)[] }>; |
| 67 | } |
| 68 | |
| 69 | export const DOMAIN_ACTIONS = ["start", "shutdown", "reboot", "destroy", "resume"] as const; |
| 70 | export type NewDomain = {name:string;description:string;image:string;vcpus:number;memory:number;disk:number;autostart:boolean;start:boolean}; |