Can delete the VM from the WebUI

This commit is contained in:
2023-10-13 18:39:34 +02:00
parent 6a3cf2e5c8
commit 3c00c23205
7 changed files with 247 additions and 12 deletions

View File

@ -0,0 +1,68 @@
/**
* Virtual Machines API
*
* @author Pierre HUBERT
*/
import { APIClient } from "./ApiClient";
interface VMInfoInterface {
name: string;
uuid?: string;
genid?: string;
title?: string;
description?: string;
boot_type: "UEFI" | "UEFISecureBoot";
architecture: "i686" | "x86_64";
memory: number;
vnc_access: boolean;
}
export class VMInfo implements VMInfoInterface {
name: string;
uuid?: string | undefined;
genid?: string | undefined;
title?: string | undefined;
description?: string | undefined;
boot_type: "UEFI" | "UEFISecureBoot";
architecture: "i686" | "x86_64";
memory: number;
vnc_access: boolean;
constructor(int: VMInfoInterface) {
this.name = int.name;
this.uuid = int.uuid;
this.genid = int.genid;
this.title = int.title;
this.description = int.description;
this.boot_type = int.boot_type;
this.architecture = int.architecture;
this.memory = int.memory;
this.vnc_access = int.vnc_access;
}
}
export class VMApi {
/**
* Get the list of defined virtual machines
*/
static async GetList(): Promise<VMInfo[]> {
return (
await APIClient.exec({
uri: "/vm/list",
method: "GET",
})
).data.map((i: VMInfoInterface) => new VMInfo(i));
}
/**
* Delete a virtual machine
*/
static async Delete(vm: VMInfo, keep_files: boolean): Promise<void> {
await APIClient.exec({
uri: `/vm/${vm.uuid}`,
method: "DELETE",
jsonData: { keep_files },
});
}
}