Can select disk bus type when adding new disk to VM
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-05-31 08:52:07 +02:00
parent 22416badcf
commit c7cc15d8d0
5 changed files with 59 additions and 4 deletions

View File

@ -13,6 +13,12 @@ enum VMDisksError {
Config(&'static str),
}
#[derive(serde::Serialize, serde::Deserialize)]
pub enum VMDiskBus {
Virtio,
Sata,
}
/// Disk allocation type
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(tag = "format")]
@ -30,6 +36,8 @@ pub struct VMFileDisk {
pub name: String,
/// Disk size, in bytes
pub size: FileSize,
/// Disk bus
pub bus: VMDiskBus,
/// Disk format
#[serde(flatten)]
pub format: VMDiskFormat,
@ -41,7 +49,7 @@ pub struct 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 info = DiskFileInfo::load_file(file)?;
@ -61,6 +69,13 @@ impl VMFileDisk {
DiskFileFormat::QCow2 { .. } => VMDiskFormat::QCow2,
_ => 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,
from_image: None,
})