Can select disk bus type when adding new disk to VM
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		@@ -6,7 +6,7 @@ use crate::libvirt_rest_structures::LibVirtStructError;
 | 
				
			|||||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
 | 
					use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
 | 
				
			||||||
use crate::utils::file_size_utils::FileSize;
 | 
					use crate::utils::file_size_utils::FileSize;
 | 
				
			||||||
use crate::utils::files_utils;
 | 
					use crate::utils::files_utils;
 | 
				
			||||||
use crate::utils::vm_file_disks_utils::{VMDiskFormat, VMFileDisk};
 | 
					use crate::utils::vm_file_disks_utils::{VMDiskBus, VMDiskFormat, VMFileDisk};
 | 
				
			||||||
use lazy_regex::regex;
 | 
					use lazy_regex::regex;
 | 
				
			||||||
use num::Integer;
 | 
					use num::Integer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -313,7 +313,11 @@ impl VMInfo {
 | 
				
			|||||||
                        "vd{}",
 | 
					                        "vd{}",
 | 
				
			||||||
                        ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"][disks.len()]
 | 
					                        ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"][disks.len()]
 | 
				
			||||||
                    ),
 | 
					                    ),
 | 
				
			||||||
                    bus: "virtio".to_string(),
 | 
					                    bus: match disk.bus {
 | 
				
			||||||
 | 
					                        VMDiskBus::Virtio => "virtio",
 | 
				
			||||||
 | 
					                        VMDiskBus::Sata => "sata",
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    .to_string(),
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                readonly: None,
 | 
					                readonly: None,
 | 
				
			||||||
                boot: DiskBootXML {
 | 
					                boot: DiskBootXML {
 | 
				
			||||||
@@ -479,7 +483,7 @@ impl VMInfo {
 | 
				
			|||||||
                .iter()
 | 
					                .iter()
 | 
				
			||||||
                .filter(|d| d.device == "disk")
 | 
					                .filter(|d| d.device == "disk")
 | 
				
			||||||
                .map(|d| {
 | 
					                .map(|d| {
 | 
				
			||||||
                    VMFileDisk::load_from_file(&d.source.file)
 | 
					                    VMFileDisk::load_from_file(&d.source.file, &d.target.bus)
 | 
				
			||||||
                        .expect("Failed to load file disk information!")
 | 
					                        .expect("Failed to load file disk information!")
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
                .collect(),
 | 
					                .collect(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,12 @@ enum VMDisksError {
 | 
				
			|||||||
    Config(&'static str),
 | 
					    Config(&'static str),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
 | 
					pub enum VMDiskBus {
 | 
				
			||||||
 | 
					    Virtio,
 | 
				
			||||||
 | 
					    Sata,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Disk allocation type
 | 
					/// Disk allocation type
 | 
				
			||||||
#[derive(serde::Serialize, serde::Deserialize)]
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
#[serde(tag = "format")]
 | 
					#[serde(tag = "format")]
 | 
				
			||||||
@@ -30,6 +36,8 @@ pub struct VMFileDisk {
 | 
				
			|||||||
    pub name: String,
 | 
					    pub name: String,
 | 
				
			||||||
    /// Disk size, in bytes
 | 
					    /// Disk size, in bytes
 | 
				
			||||||
    pub size: FileSize,
 | 
					    pub size: FileSize,
 | 
				
			||||||
 | 
					    /// Disk bus
 | 
				
			||||||
 | 
					    pub bus: VMDiskBus,
 | 
				
			||||||
    /// Disk format
 | 
					    /// Disk format
 | 
				
			||||||
    #[serde(flatten)]
 | 
					    #[serde(flatten)]
 | 
				
			||||||
    pub format: VMDiskFormat,
 | 
					    pub format: VMDiskFormat,
 | 
				
			||||||
@@ -41,7 +49,7 @@ pub struct VMFileDisk {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl VMFileDisk {
 | 
					impl VMFileDisk {
 | 
				
			||||||
    pub fn load_from_file(path: &str) -> anyhow::Result<Self> {
 | 
					    pub fn load_from_file(path: &str, bus: &str) -> anyhow::Result<Self> {
 | 
				
			||||||
        let file = Path::new(path);
 | 
					        let file = Path::new(path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let info = DiskFileInfo::load_file(file)?;
 | 
					        let info = DiskFileInfo::load_file(file)?;
 | 
				
			||||||
@@ -61,6 +69,13 @@ impl VMFileDisk {
 | 
				
			|||||||
                DiskFileFormat::QCow2 { .. } => VMDiskFormat::QCow2,
 | 
					                DiskFileFormat::QCow2 { .. } => VMDiskFormat::QCow2,
 | 
				
			||||||
                _ => anyhow::bail!("Unsupported image format: {:?}", info.format),
 | 
					                _ => anyhow::bail!("Unsupported image format: {:?}", info.format),
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bus: match bus {
 | 
				
			||||||
 | 
					                "virtio" => VMDiskBus::Virtio,
 | 
				
			||||||
 | 
					                "sata" => VMDiskBus::Sata,
 | 
				
			||||||
 | 
					                _ => anyhow::bail!("Unsupported disk bus type: {bus}"),
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            delete: false,
 | 
					            delete: false,
 | 
				
			||||||
            from_image: None,
 | 
					            from_image: None,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,9 +19,13 @@ export type VMState =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export type VMFileDisk = BaseFileVMDisk & (RawVMDisk | QCow2Disk);
 | 
					export type VMFileDisk = BaseFileVMDisk & (RawVMDisk | QCow2Disk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type DiskBusType = "Virtio" | "Sata";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface BaseFileVMDisk {
 | 
					export interface BaseFileVMDisk {
 | 
				
			||||||
  size: number;
 | 
					  size: number;
 | 
				
			||||||
  name: string;
 | 
					  name: string;
 | 
				
			||||||
 | 
					  bus: DiskBusType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  delete: boolean;
 | 
					  delete: boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // For new disk only
 | 
					  // For new disk only
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								virtweb_frontend/src/widgets/forms/DiskBusSelect.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								virtweb_frontend/src/widgets/forms/DiskBusSelect.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					import { DiskBusType } from "../../api/VMApi";
 | 
				
			||||||
 | 
					import { SelectInput } from "./SelectInput";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function DiskBusSelect(p: {
 | 
				
			||||||
 | 
					  editable: boolean;
 | 
				
			||||||
 | 
					  value: DiskBusType;
 | 
				
			||||||
 | 
					  onValueChange: (value: DiskBusType) => void;
 | 
				
			||||||
 | 
					}): React.ReactElement {
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <SelectInput
 | 
				
			||||||
 | 
					      {...p}
 | 
				
			||||||
 | 
					      label="Disk bus type"
 | 
				
			||||||
 | 
					      options={[
 | 
				
			||||||
 | 
					        { label: "virtio", value: "Virtio" },
 | 
				
			||||||
 | 
					        { label: "sata", value: "Sata" },
 | 
				
			||||||
 | 
					      ]}
 | 
				
			||||||
 | 
					      onValueChange={(v) => p.onValueChange(v as any)}
 | 
				
			||||||
 | 
					    />
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -23,6 +23,7 @@ import { SelectInput } from "./SelectInput";
 | 
				
			|||||||
import { TextInput } from "./TextInput";
 | 
					import { TextInput } from "./TextInput";
 | 
				
			||||||
import { DiskImageSelect } from "./DiskImageSelect";
 | 
					import { DiskImageSelect } from "./DiskImageSelect";
 | 
				
			||||||
import { DiskImage } from "../../api/DiskImageApi";
 | 
					import { DiskImage } from "../../api/DiskImageApi";
 | 
				
			||||||
 | 
					import { DiskBusSelect } from "./DiskBusSelect";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function VMDisksList(p: {
 | 
					export function VMDisksList(p: {
 | 
				
			||||||
  vm: VMInfo;
 | 
					  vm: VMInfo;
 | 
				
			||||||
@@ -39,6 +40,7 @@ export function VMDisksList(p: {
 | 
				
			|||||||
    p.vm.file_disks.push({
 | 
					    p.vm.file_disks.push({
 | 
				
			||||||
      format: "QCow2",
 | 
					      format: "QCow2",
 | 
				
			||||||
      size: 10000 * 1000 * 1000,
 | 
					      size: 10000 * 1000 * 1000,
 | 
				
			||||||
 | 
					      bus: "Virtio",
 | 
				
			||||||
      delete: false,
 | 
					      delete: false,
 | 
				
			||||||
      name: `disk${p.vm.file_disks.length}`,
 | 
					      name: `disk${p.vm.file_disks.length}`,
 | 
				
			||||||
      new: true,
 | 
					      new: true,
 | 
				
			||||||
@@ -220,6 +222,16 @@ function DiskInfo(p: {
 | 
				
			|||||||
        }}
 | 
					        }}
 | 
				
			||||||
      />
 | 
					      />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      {/* Bus selection */}
 | 
				
			||||||
 | 
					      <DiskBusSelect
 | 
				
			||||||
 | 
					        editable
 | 
				
			||||||
 | 
					        value={p.disk.bus}
 | 
				
			||||||
 | 
					        onValueChange={(v) => {
 | 
				
			||||||
 | 
					          p.disk.bus = v;
 | 
				
			||||||
 | 
					          p.onChange?.();
 | 
				
			||||||
 | 
					        }}
 | 
				
			||||||
 | 
					      />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      {p.disk.format === "Raw" && (
 | 
					      {p.disk.format === "Raw" && (
 | 
				
			||||||
        <CheckboxInput
 | 
					        <CheckboxInput
 | 
				
			||||||
          editable
 | 
					          editable
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user