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