import { APIClient } from "./ApiClient"; export interface VMInfo { uuid: string; name: string; description?: string; architecture: string; memory: number; number_vcpu: number; } export interface VMCaps { can_get_state: boolean; can_start: boolean; can_shutdown: boolean; can_kill: boolean; can_reset: boolean; can_suspend: boolean; can_resume: boolean; can_screenshot: boolean; } export type VMInfoAndCaps = VMInfo & VMCaps; export type VMState = | "NoState" | "Running" | "Blocked" | "Paused" | "Shutdown" | "Shutoff" | "Crashed" | "PowerManagementSuspended" | "Other"; export class VMApi { /** * Get the state of a VM */ static async State(vm: VMInfo): Promise { return ( await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/state` }) ).data.state; } /** * Request to start VM */ static async StartVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/start` }); } /** * Request to suspend VM */ static async SuspendVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/suspend` }); } /** * Request to resume VM */ static async ResumeVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/resume` }); } /** * Request to shutdown VM */ static async ShutdownVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/shutdown` }); } /** * Request to kill VM */ static async KillVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/kill` }); } /** * Request to reset VM */ static async ResetVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/reset` }); } /** * Get a screenshot of a VM */ static async Screenshot(vm: VMInfo): Promise { return ( await APIClient.exec({ uri: `/vm/${vm.uuid}/screenshot`, method: "GET", }) ).data; } }