Add groups support (#146)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #146
This commit is contained in:
107
remote_frontend/src/api/GroupApi.ts
Normal file
107
remote_frontend/src/api/GroupApi.ts
Normal file
@ -0,0 +1,107 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { APIClient } from "./ApiClient";
|
||||
import { VMInfo } from "./VMApi";
|
||||
import { VMCaps, VMInfo, VMInfoAndCaps } from "./VMApi";
|
||||
|
||||
export interface ServerConfig {
|
||||
authenticated: boolean;
|
||||
@ -7,10 +7,18 @@ export interface ServerConfig {
|
||||
}
|
||||
|
||||
export interface Rights {
|
||||
vms: VMInfo[];
|
||||
groups: VMGroup[];
|
||||
vms: VMInfoAndCaps[];
|
||||
sys_info: boolean;
|
||||
}
|
||||
|
||||
export type VMGroup = VMGroupInfo & VMCaps;
|
||||
|
||||
export interface VMGroupInfo {
|
||||
id: string;
|
||||
vms: VMInfo[];
|
||||
}
|
||||
|
||||
let config: ServerConfig | null = null;
|
||||
|
||||
export class ServerApi {
|
||||
|
@ -1,12 +1,15 @@
|
||||
import { APIClient } from "./ApiClient";
|
||||
|
||||
export interface VMInfo {
|
||||
uiid: string;
|
||||
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;
|
||||
@ -17,6 +20,8 @@ export interface VMInfo {
|
||||
can_screenshot: boolean;
|
||||
}
|
||||
|
||||
export type VMInfoAndCaps = VMInfo & VMCaps;
|
||||
|
||||
export type VMState =
|
||||
| "NoState"
|
||||
| "Running"
|
||||
@ -34,7 +39,7 @@ export class VMApi {
|
||||
*/
|
||||
static async State(vm: VMInfo): Promise<VMState> {
|
||||
return (
|
||||
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/state` })
|
||||
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/state` })
|
||||
).data.state;
|
||||
}
|
||||
|
||||
@ -42,42 +47,42 @@ export class VMApi {
|
||||
* Request to start VM
|
||||
*/
|
||||
static async StartVM(vm: VMInfo): Promise<void> {
|
||||
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/start` });
|
||||
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.uiid}/suspend` });
|
||||
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.uiid}/resume` });
|
||||
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.uiid}/shutdown` });
|
||||
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.uiid}/kill` });
|
||||
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.uiid}/reset` });
|
||||
await APIClient.exec({ method: "GET", uri: `/vm/${vm.uuid}/reset` });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +91,7 @@ export class VMApi {
|
||||
static async Screenshot(vm: VMInfo): Promise<Blob> {
|
||||
return (
|
||||
await APIClient.exec({
|
||||
uri: `/vm/${vm.uiid}/screenshot`,
|
||||
uri: `/vm/${vm.uuid}/screenshot`,
|
||||
method: "GET",
|
||||
})
|
||||
).data;
|
||||
|
Reference in New Issue
Block a user