Automatically generate cloud disk image when updating domains configuration
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -142,9 +142,22 @@ impl VMInfo {
|
||||
return Err(StructureExtraction("Invalid number of vCPU specified!").into());
|
||||
}
|
||||
|
||||
let mut disks = vec![];
|
||||
let mut iso_absolute_files = vec![];
|
||||
|
||||
// Add ISO files
|
||||
// Process cloud init image
|
||||
if self.cloud_init.attach_config {
|
||||
let cloud_init_disk_path = AppConfig::get().cloud_init_disk_path_for_vm(&self.name);
|
||||
|
||||
// Apply latest cloud init configuration
|
||||
std::fs::write(
|
||||
&cloud_init_disk_path,
|
||||
self.cloud_init.generate_nocloud_disk()?,
|
||||
)?;
|
||||
|
||||
iso_absolute_files.push(cloud_init_disk_path);
|
||||
}
|
||||
|
||||
// Process uploaded ISO files
|
||||
for iso_file in &self.iso_files {
|
||||
if !files_utils::check_file_name(iso_file) {
|
||||
return Err(StructureExtraction("ISO filename is invalid!").into());
|
||||
@ -156,6 +169,13 @@ impl VMInfo {
|
||||
return Err(StructureExtraction("Specified ISO file does not exists!").into());
|
||||
}
|
||||
|
||||
iso_absolute_files.push(path);
|
||||
}
|
||||
|
||||
let mut disks = vec![];
|
||||
|
||||
// Add ISO disk files
|
||||
for iso_path in iso_absolute_files {
|
||||
disks.push(DiskXML {
|
||||
r#type: "file".to_string(),
|
||||
device: "cdrom".to_string(),
|
||||
@ -165,7 +185,7 @@ impl VMInfo {
|
||||
cache: "none".to_string(),
|
||||
},
|
||||
source: DiskSourceXML {
|
||||
file: path.to_string_lossy().to_string(),
|
||||
file: iso_path.to_string_lossy().to_string(),
|
||||
},
|
||||
target: DiskTargetXML {
|
||||
dev: format!(
|
||||
@ -182,6 +202,7 @@ impl VMInfo {
|
||||
})
|
||||
}
|
||||
|
||||
// Configure VNC access, if requested
|
||||
let (vnc_graphics, vnc_video) = match self.vnc_access {
|
||||
true => (
|
||||
Some(GraphicsXML {
|
||||
@ -495,6 +516,7 @@ impl VMInfo {
|
||||
.iter()
|
||||
.filter(|d| d.device == "cdrom")
|
||||
.map(|d| d.source.file.rsplit_once('/').unwrap().1.to_string())
|
||||
.filter(|d| !d.starts_with(constants::CLOUD_INIT_IMAGE_PREFIX_NAME))
|
||||
.collect(),
|
||||
|
||||
file_disks: domain
|
||||
|
Reference in New Issue
Block a user