Get VM state

This commit is contained in:
2024-05-06 18:20:55 +02:00
parent e441492306
commit 766ec1780a
2 changed files with 47 additions and 2 deletions

View File

@ -17,6 +17,17 @@ export interface VMInfo {
can_screenshot: boolean;
}
export type VMState =
| "NoState"
| "Running"
| "Blocked"
| "Paused"
| "Shutdown"
| "Shutoff"
| "Crashed"
| "PowerManagementSuspended"
| "Other";
export class VMApi {
/**
* Get the list of VM that can be managed by this console
@ -24,4 +35,13 @@ export class VMApi {
static async GetList(): Promise<VMInfo[]> {
return (await APIClient.exec({ method: "GET", uri: "/vm/list" })).data;
}
/**
* Get the state of a VM
*/
static async State(vm: VMInfo): Promise<VMState> {
return (
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/state` })
).data.state;
}
}