Can set the number of VCPUs
This commit is contained in:
		@@ -172,6 +172,18 @@ export class ServerApi {
 | 
			
		||||
    ).data;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get host supported vCPUs configurations
 | 
			
		||||
   */
 | 
			
		||||
  static async NumberVCPUs(): Promise<number[]> {
 | 
			
		||||
    return (
 | 
			
		||||
      await APIClient.exec({
 | 
			
		||||
        method: "GET",
 | 
			
		||||
        uri: "/server/number_vcpus",
 | 
			
		||||
      })
 | 
			
		||||
    ).data;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get host networks card list
 | 
			
		||||
   */
 | 
			
		||||
 
 | 
			
		||||
@@ -39,6 +39,7 @@ interface VMInfoInterface {
 | 
			
		||||
  boot_type: "UEFI" | "UEFISecureBoot";
 | 
			
		||||
  architecture: "i686" | "x86_64";
 | 
			
		||||
  memory: number;
 | 
			
		||||
  number_vcpu: number;
 | 
			
		||||
  vnc_access: boolean;
 | 
			
		||||
  iso_file?: string;
 | 
			
		||||
  disks: VMDisk[];
 | 
			
		||||
@@ -52,6 +53,7 @@ export class VMInfo implements VMInfoInterface {
 | 
			
		||||
  description?: string;
 | 
			
		||||
  boot_type: "UEFI" | "UEFISecureBoot";
 | 
			
		||||
  architecture: "i686" | "x86_64";
 | 
			
		||||
  number_vcpu: number;
 | 
			
		||||
  memory: number;
 | 
			
		||||
  vnc_access: boolean;
 | 
			
		||||
  iso_file?: string;
 | 
			
		||||
@@ -65,6 +67,7 @@ export class VMInfo implements VMInfoInterface {
 | 
			
		||||
    this.description = int.description;
 | 
			
		||||
    this.boot_type = int.boot_type;
 | 
			
		||||
    this.architecture = int.architecture;
 | 
			
		||||
    this.number_vcpu = int.number_vcpu;
 | 
			
		||||
    this.memory = int.memory;
 | 
			
		||||
    this.vnc_access = int.vnc_access;
 | 
			
		||||
    this.iso_file = int.iso_file;
 | 
			
		||||
@@ -77,6 +80,7 @@ export class VMInfo implements VMInfoInterface {
 | 
			
		||||
      boot_type: "UEFI",
 | 
			
		||||
      architecture: "x86_64",
 | 
			
		||||
      memory: 1024,
 | 
			
		||||
      number_vcpu: 1,
 | 
			
		||||
      vnc_access: true,
 | 
			
		||||
      disks: [],
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -80,7 +80,7 @@ function VNCInner(p: { vm: VMInfo }): React.ReactElement {
 | 
			
		||||
      }}
 | 
			
		||||
    >
 | 
			
		||||
      <VncScreen
 | 
			
		||||
        url={token!.url}
 | 
			
		||||
        url={token.url}
 | 
			
		||||
        onDisconnect={() => {
 | 
			
		||||
          console.info("VNC disconnected " + token?.url);
 | 
			
		||||
          disconnected();
 | 
			
		||||
 
 | 
			
		||||
@@ -22,10 +22,14 @@ interface DetailsProps {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function VMDetails(p: DetailsProps): React.ReactElement {
 | 
			
		||||
  const [list, setList] = React.useState<IsoFile[] | any>();
 | 
			
		||||
  const [isoList, setIsoList] = React.useState<IsoFile[] | any>();
 | 
			
		||||
  const [vcpuCombinations, setVCPUCombinations] = React.useState<
 | 
			
		||||
    number[] | any
 | 
			
		||||
  >();
 | 
			
		||||
 | 
			
		||||
  const load = async () => {
 | 
			
		||||
    setList(await IsoFilesApi.GetList());
 | 
			
		||||
    setIsoList(await IsoFilesApi.GetList());
 | 
			
		||||
    setVCPUCombinations(await ServerApi.NumberVCPUs());
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
@@ -33,13 +37,19 @@ export function VMDetails(p: DetailsProps): React.ReactElement {
 | 
			
		||||
      loadKey={"1"}
 | 
			
		||||
      load={load}
 | 
			
		||||
      errMsg="Failed to load the list of ISO files"
 | 
			
		||||
      build={() => <VMDetailsInner isoList={list} {...p} />}
 | 
			
		||||
      build={() => (
 | 
			
		||||
        <VMDetailsInner
 | 
			
		||||
          isoList={isoList}
 | 
			
		||||
          vcpuCombinations={vcpuCombinations}
 | 
			
		||||
          {...p}
 | 
			
		||||
        />
 | 
			
		||||
      )}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function VMDetailsInner(
 | 
			
		||||
  p: DetailsProps & { isoList: IsoFile[] }
 | 
			
		||||
  p: DetailsProps & { isoList: IsoFile[]; vcpuCombinations: number[] }
 | 
			
		||||
): React.ReactElement {
 | 
			
		||||
  return (
 | 
			
		||||
    <Grid container spacing={2}>
 | 
			
		||||
@@ -146,6 +156,19 @@ function VMDetailsInner(
 | 
			
		||||
          }
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
        <SelectInput
 | 
			
		||||
          editable={p.editable}
 | 
			
		||||
          label="Number of vCPU"
 | 
			
		||||
          options={p.vcpuCombinations.map((v) => {
 | 
			
		||||
            return { label: v.toString(), value: v.toString() };
 | 
			
		||||
          })}
 | 
			
		||||
          value={p.vm.number_vcpu.toString()}
 | 
			
		||||
          onValueChange={(v) => {
 | 
			
		||||
            p.vm.number_vcpu = Number(v ?? "0");
 | 
			
		||||
            p.onChange?.();
 | 
			
		||||
          }}
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
        <CheckboxInput
 | 
			
		||||
          editable={p.editable}
 | 
			
		||||
          label="Enable VNC access"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user