All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #146
108 lines
2.5 KiB
TypeScript
108 lines
2.5 KiB
TypeScript
import { APIClient } from "./ApiClient";
|
|
import { VMGroup } from "./ServerApi";
|
|
import { VMInfo, VMState } from "./VMApi";
|
|
|
|
export interface GroupVMState {
|
|
[key: string]: VMState;
|
|
}
|
|
|
|
export interface TreatmentResult {
|
|
ok: number;
|
|
failed: number;
|
|
}
|
|
|
|
export class GroupApi {
|
|
/**
|
|
* Get the state of the VMs of a group
|
|
*/
|
|
static async State(g: VMGroup): Promise<GroupVMState> {
|
|
return (
|
|
await APIClient.exec({ method: "GET", uri: `/group/${g.id}/vm/state` })
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request to start the VM of a group
|
|
*/
|
|
static async StartVM(g: VMGroup, vm?: VMInfo): Promise<TreatmentResult> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/start` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request to suspend the VM of a group
|
|
*/
|
|
static async SuspendVM(g: VMGroup, vm?: VMInfo): Promise<TreatmentResult> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/suspend` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request to resume the VM of a group
|
|
*/
|
|
static async ResumeVM(g: VMGroup, vm?: VMInfo): Promise<TreatmentResult> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/resume` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request to shutdown the VM of a group
|
|
*/
|
|
static async ShutdownVM(g: VMGroup, vm?: VMInfo): Promise<TreatmentResult> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/shutdown` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request to kill the VM of a group
|
|
*/
|
|
static async KillVM(g: VMGroup, vm?: VMInfo): Promise<TreatmentResult> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/kill` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request to reset the VM of a group
|
|
*/
|
|
static async ResetVM(g: VMGroup, vm?: VMInfo): Promise<TreatmentResult> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/reset` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Request a screenshot of the VM of group
|
|
*/
|
|
static async ScreenshotVM(g: VMGroup, vm?: VMInfo): Promise<Blob> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/group/${g.id}/vm/screenshot` + (vm ? `?vm_id=${vm.uuid}` : ""),
|
|
})
|
|
).data;
|
|
}
|
|
}
|