Show VM status

This commit is contained in:
2023-10-16 13:46:46 +02:00
parent 3c00c23205
commit 7ef5afb978
3 changed files with 253 additions and 6 deletions

View File

@ -6,6 +6,17 @@
import { APIClient } from "./ApiClient";
export type VMState =
| "NoState"
| "Running"
| "Blocked"
| "Paused"
| "Shutdown"
| "Shutoff"
| "Crashed"
| "PowerManagementSuspended"
| "Other";
interface VMInfoInterface {
name: string;
uuid?: string;
@ -40,6 +51,10 @@ export class VMInfo implements VMInfoInterface {
this.memory = int.memory;
this.vnc_access = int.vnc_access;
}
get ViewURL(): string {
return `/api/vm/${this.uuid}`;
}
}
export class VMApi {
@ -55,6 +70,90 @@ export class VMApi {
).data.map((i: VMInfoInterface) => new VMInfo(i));
}
/**
* Get the state of a VM
*/
static async GetState(vm: VMInfo): Promise<VMState> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/state`,
method: "GET",
})
).data.state;
}
/**
* Start the VM
*/
static async StartVM(vm: VMInfo): Promise<void> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/start`,
method: "GET",
})
).data.state;
}
/**
* Shutdown the VM
*/
static async ShutdownVM(vm: VMInfo): Promise<void> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/shutdown`,
method: "GET",
})
).data.state;
}
/**
* Restt the VM
*/
static async ResetVM(vm: VMInfo): Promise<void> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/reset`,
method: "GET",
})
).data.state;
}
/**
* Kill the VM
*/
static async KillVM(vm: VMInfo): Promise<void> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/kill`,
method: "GET",
})
).data.state;
}
/**
* Suspend the VM
*/
static async SuspendVM(vm: VMInfo): Promise<void> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/suspend`,
method: "GET",
})
).data.state;
}
/**
* Resume the VM
*/
static async ResumeVM(vm: VMInfo): Promise<void> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/resume`,
method: "GET",
})
).data.state;
}
/**
* Delete a virtual machine
*/