Can delete the VM from the WebUI
This commit is contained in:
		
							
								
								
									
										68
									
								
								virtweb_frontend/src/api/VMApi.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								virtweb_frontend/src/api/VMApi.ts
									
									
									
									
									
										Normal 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 },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user