Files
VirtWebRemote/remote_frontend/src/api/VMApi.ts
Pierre HUBERT 4c6608bf55
All checks were successful
continuous-integration/drone/push Build is passing
Add groups support (#146)
Reviewed-on: #146
2024-12-06 18:06:01 +00:00

100 lines
2.1 KiB
TypeScript

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<VMState> {
return (
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/state` })
).data.state;
}
/**
* Request to start VM
*/
static async StartVM(vm: VMInfo): Promise<void> {
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/start` });
}
/**
* Request to suspend VM
*/
static async SuspendVM(vm: VMInfo): Promise<void> {
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/suspend` });
}
/**
* Request to resume VM
*/
static async ResumeVM(vm: VMInfo): Promise<void> {
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/resume` });
}
/**
* Request to shutdown VM
*/
static async ShutdownVM(vm: VMInfo): Promise<void> {
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/shutdown` });
}
/**
* Request to kill VM
*/
static async KillVM(vm: VMInfo): Promise<void> {
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/kill` });
}
/**
* Request to reset VM
*/
static async ResetVM(vm: VMInfo): Promise<void> {
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/reset` });
}
/**
* Get a screenshot of a VM
*/
static async Screenshot(vm: VMInfo): Promise<Blob> {
return (
await APIClient.exec({
uri: `/vm/${vm.uuid}/screenshot`,
method: "GET",
})
).data;
}
}