This commit is contained in:
parent
5a5450070a
commit
5814b0ab6a
@ -4,7 +4,7 @@ use crate::libvirt_lib_structures::XMLUuid;
|
|||||||
use crate::libvirt_lib_structures::domain::*;
|
use crate::libvirt_lib_structures::domain::*;
|
||||||
use crate::libvirt_rest_structures::LibVirtStructError;
|
use crate::libvirt_rest_structures::LibVirtStructError;
|
||||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
|
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
|
||||||
use crate::utils::file_disks_utils::{DiskFormat, FileDisk};
|
use crate::utils::file_disks_utils::{VMDiskFormat, VMFileDisk};
|
||||||
use crate::utils::files_utils;
|
use crate::utils::files_utils;
|
||||||
use crate::utils::files_utils::convert_size_unit_to_mb;
|
use crate::utils::files_utils::convert_size_unit_to_mb;
|
||||||
use lazy_regex::regex;
|
use lazy_regex::regex;
|
||||||
@ -79,7 +79,7 @@ pub struct VMInfo {
|
|||||||
/// Attach ISO file(s)
|
/// Attach ISO file(s)
|
||||||
pub iso_files: Vec<String>,
|
pub iso_files: Vec<String>,
|
||||||
/// File Storage - https://access.redhat.com/documentation/fr-fr/red_hat_enterprise_linux/6/html/virtualization_administration_guide/sect-virtualization-virtualized_block_devices-adding_storage_devices_to_guests#sect-Virtualization-Adding_storage_devices_to_guests-Adding_file_based_storage_to_a_guest
|
/// File Storage - https://access.redhat.com/documentation/fr-fr/red_hat_enterprise_linux/6/html/virtualization_administration_guide/sect-virtualization-virtualized_block_devices-adding_storage_devices_to_guests#sect-Virtualization-Adding_storage_devices_to_guests-Adding_file_based_storage_to_a_guest
|
||||||
pub file_disks: Vec<FileDisk>,
|
pub file_disks: Vec<VMFileDisk>,
|
||||||
/// Network cards
|
/// Network cards
|
||||||
pub networks: Vec<Network>,
|
pub networks: Vec<Network>,
|
||||||
/// Add a TPM v2.0 module
|
/// Add a TPM v2.0 module
|
||||||
@ -289,8 +289,8 @@ impl VMInfo {
|
|||||||
driver: DiskDriverXML {
|
driver: DiskDriverXML {
|
||||||
name: "qemu".to_string(),
|
name: "qemu".to_string(),
|
||||||
r#type: match disk.format {
|
r#type: match disk.format {
|
||||||
DiskFormat::Raw { .. } => "raw".to_string(),
|
VMDiskFormat::Raw { .. } => "raw".to_string(),
|
||||||
DiskFormat::QCow2 => "qcow2".to_string(),
|
VMDiskFormat::QCow2 => "qcow2".to_string(),
|
||||||
},
|
},
|
||||||
cache: "none".to_string(),
|
cache: "none".to_string(),
|
||||||
},
|
},
|
||||||
@ -467,7 +467,7 @@ impl VMInfo {
|
|||||||
.disks
|
.disks
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|d| d.device == "disk")
|
.filter(|d| d.device == "disk")
|
||||||
.map(|d| FileDisk::load_from_file(&d.source.file).unwrap())
|
.map(|d| VMFileDisk::load_from_file(&d.source.file).unwrap())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
networks: domain
|
networks: domain
|
||||||
|
@ -20,7 +20,7 @@ enum DisksError {
|
|||||||
|
|
||||||
/// Type of disk allocation
|
/// Type of disk allocation
|
||||||
#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum DiskAllocType {
|
pub enum VMDiskAllocType {
|
||||||
Fixed,
|
Fixed,
|
||||||
Sparse,
|
Sparse,
|
||||||
}
|
}
|
||||||
@ -28,28 +28,28 @@ pub enum DiskAllocType {
|
|||||||
/// Disk allocation type
|
/// Disk allocation type
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(tag = "format")]
|
#[serde(tag = "format")]
|
||||||
pub enum DiskFormat {
|
pub enum VMDiskFormat {
|
||||||
Raw {
|
Raw {
|
||||||
/// Type of disk allocation
|
/// Type of disk allocation
|
||||||
alloc_type: DiskAllocType,
|
alloc_type: VMDiskAllocType,
|
||||||
},
|
},
|
||||||
QCow2,
|
QCow2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
pub struct FileDisk {
|
pub struct VMFileDisk {
|
||||||
/// Disk name
|
/// Disk name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Disk size, in bytes
|
/// Disk size, in bytes
|
||||||
pub size: usize,
|
pub size: usize,
|
||||||
/// Disk format
|
/// Disk format
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub format: DiskFormat,
|
pub format: VMDiskFormat,
|
||||||
/// Set this variable to true to delete the disk
|
/// Set this variable to true to delete the disk
|
||||||
pub delete: bool,
|
pub delete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileDisk {
|
impl VMFileDisk {
|
||||||
pub fn load_from_file(path: &str) -> anyhow::Result<Self> {
|
pub fn load_from_file(path: &str) -> anyhow::Result<Self> {
|
||||||
let file = Path::new(path);
|
let file = Path::new(path);
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ impl FileDisk {
|
|||||||
},
|
},
|
||||||
|
|
||||||
format: match info.format {
|
format: match info.format {
|
||||||
DiskFileFormat::Raw { is_sparse } => DiskFormat::Raw {
|
DiskFileFormat::Raw { is_sparse } => VMDiskFormat::Raw {
|
||||||
alloc_type: match is_sparse {
|
alloc_type: match is_sparse {
|
||||||
true => DiskAllocType::Sparse,
|
true => VMDiskAllocType::Sparse,
|
||||||
false => DiskAllocType::Fixed,
|
false => VMDiskAllocType::Fixed,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DiskFileFormat::QCow2 { .. } => DiskFormat::QCow2,
|
DiskFileFormat::QCow2 { .. } => VMDiskFormat::QCow2,
|
||||||
_ => anyhow::bail!("Unsupported image format: {:?}", info.format),
|
_ => anyhow::bail!("Unsupported image format: {:?}", info.format),
|
||||||
},
|
},
|
||||||
delete: false,
|
delete: false,
|
||||||
@ -102,8 +102,8 @@ impl FileDisk {
|
|||||||
pub fn disk_path(&self, id: XMLUuid) -> PathBuf {
|
pub fn disk_path(&self, id: XMLUuid) -> PathBuf {
|
||||||
let domain_dir = AppConfig::get().vm_storage_path(id);
|
let domain_dir = AppConfig::get().vm_storage_path(id);
|
||||||
let file_name = match self.format {
|
let file_name = match self.format {
|
||||||
DiskFormat::Raw { .. } => self.name.to_string(),
|
VMDiskFormat::Raw { .. } => self.name.to_string(),
|
||||||
DiskFormat::QCow2 => format!("{}.qcow2", self.name),
|
VMDiskFormat::QCow2 => format!("{}.qcow2", self.name),
|
||||||
};
|
};
|
||||||
domain_dir.join(&file_name)
|
domain_dir.join(&file_name)
|
||||||
}
|
}
|
||||||
@ -134,15 +134,15 @@ impl FileDisk {
|
|||||||
|
|
||||||
// Prepare command to create file
|
// Prepare command to create file
|
||||||
let res = match self.format {
|
let res = match self.format {
|
||||||
DiskFormat::Raw { alloc_type } => {
|
VMDiskFormat::Raw { alloc_type } => {
|
||||||
let mut cmd = Command::new("/usr/bin/dd");
|
let mut cmd = Command::new("/usr/bin/dd");
|
||||||
cmd.arg("if=/dev/zero")
|
cmd.arg("if=/dev/zero")
|
||||||
.arg(format!("of={}", file.to_string_lossy()))
|
.arg(format!("of={}", file.to_string_lossy()))
|
||||||
.arg("bs=1M");
|
.arg("bs=1M");
|
||||||
|
|
||||||
match alloc_type {
|
match alloc_type {
|
||||||
DiskAllocType::Fixed => cmd.arg(format!("count={}", self.size_mb())),
|
VMDiskAllocType::Fixed => cmd.arg(format!("count={}", self.size_mb())),
|
||||||
DiskAllocType::Sparse => {
|
VMDiskAllocType::Sparse => {
|
||||||
cmd.arg(format!("seek={}", self.size_mb())).arg("count=0")
|
cmd.arg(format!("seek={}", self.size_mb())).arg("count=0")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -150,7 +150,7 @@ impl FileDisk {
|
|||||||
cmd.output()?
|
cmd.output()?
|
||||||
}
|
}
|
||||||
|
|
||||||
DiskFormat::QCow2 => {
|
VMDiskFormat::QCow2 => {
|
||||||
let mut cmd = Command::new(constants::QEMU_IMAGE_PROGRAM);
|
let mut cmd = Command::new(constants::QEMU_IMAGE_PROGRAM);
|
||||||
cmd.arg("create")
|
cmd.arg("create")
|
||||||
.arg("-f")
|
.arg("-f")
|
||||||
@ -182,6 +182,7 @@ impl FileDisk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
|
#[serde(tag = "format")]
|
||||||
pub enum DiskFileFormat {
|
pub enum DiskFileFormat {
|
||||||
Raw { is_sparse: bool },
|
Raw { is_sparse: bool },
|
||||||
QCow2 { virtual_size: usize },
|
QCow2 { virtual_size: usize },
|
||||||
@ -193,6 +194,7 @@ pub enum DiskFileFormat {
|
|||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct DiskFileInfo {
|
pub struct DiskFileInfo {
|
||||||
file_size: usize,
|
file_size: usize,
|
||||||
|
#[serde(flatten)]
|
||||||
format: DiskFileFormat,
|
format: DiskFileFormat,
|
||||||
file_name: String,
|
file_name: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
import { APIClient } from "./ApiClient";
|
import { APIClient } from "./ApiClient";
|
||||||
|
|
||||||
export interface DiskImage {}
|
export type DiskImage = {
|
||||||
|
file_size: number;
|
||||||
|
file_name: string;
|
||||||
|
name: string;
|
||||||
|
created: number;
|
||||||
|
} & (
|
||||||
|
| { format: "Raw"; is_sparse: boolean }
|
||||||
|
| { format: "QCow2"; virtual_size: number }
|
||||||
|
| { format: "CompressedQCow2" }
|
||||||
|
| { format: "CompressedRaw" }
|
||||||
|
);
|
||||||
|
|
||||||
export class DiskImageApi {
|
export class DiskImageApi {
|
||||||
/**
|
/**
|
||||||
@ -25,7 +35,11 @@ export class DiskImageApi {
|
|||||||
* Get the list of disk images
|
* Get the list of disk images
|
||||||
*/
|
*/
|
||||||
static async GetList(): Promise<DiskImage[]> {
|
static async GetList(): Promise<DiskImage[]> {
|
||||||
// TODO
|
return (
|
||||||
return [];
|
await APIClient.exec({
|
||||||
|
method: "GET",
|
||||||
|
uri: "/disk_images/list",
|
||||||
|
})
|
||||||
|
).data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,7 @@ function UploadDiskImageCard(p: {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
newValue &&
|
newValue &&
|
||||||
|
newValue.type.length > 0 &&
|
||||||
!ServerApi.Config.disk_images_mimetypes.includes(newValue.type)
|
!ServerApi.Config.disk_images_mimetypes.includes(newValue.type)
|
||||||
) {
|
) {
|
||||||
alert(`Selected file mimetype is not allowed! (${newValue.type})`);
|
alert(`Selected file mimetype is not allowed! (${newValue.type})`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user