Managed to start a VM again
This commit is contained in:
parent
8b53875349
commit
60d35f17bd
@ -76,6 +76,9 @@ pub struct AppConfig {
|
|||||||
pub storage: String,
|
pub storage: String,
|
||||||
|
|
||||||
/// Directory where temporary files are stored
|
/// Directory where temporary files are stored
|
||||||
|
///
|
||||||
|
/// Warning! This directory MUST be changed if `/tmp` is not in the same disk as the storage
|
||||||
|
/// directory!
|
||||||
#[arg(long, env, default_value = "/tmp")]
|
#[arg(long, env, default_value = "/tmp")]
|
||||||
pub temp_dir: String,
|
pub temp_dir: String,
|
||||||
|
|
||||||
|
@ -59,7 +59,10 @@ pub async fn upload_file(MultipartForm(mut form): MultipartForm<UploadIsoForm>)
|
|||||||
return Ok(HttpResponse::Conflict().json("The file already exists!"));
|
return Ok(HttpResponse::Conflict().json("The file already exists!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
file.file.persist(dest_file)?;
|
file.file.persist(&dest_file)?;
|
||||||
|
|
||||||
|
// Set file permissions
|
||||||
|
files_utils::set_file_permission(dest_file, 0o644)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().finish())
|
Ok(HttpResponse::Accepted().finish())
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,25 @@ pub struct DomainMemoryXML {
|
|||||||
pub memory: usize,
|
pub memory: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(rename = "topology")]
|
||||||
|
pub struct DomainCPUTopology {
|
||||||
|
#[serde(rename(serialize = "@sockets"))]
|
||||||
|
pub sockets: usize,
|
||||||
|
#[serde(rename(serialize = "@cores"))]
|
||||||
|
pub cores: usize,
|
||||||
|
#[serde(rename(serialize = "@threads"))]
|
||||||
|
pub threads: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(rename = "cpu")]
|
||||||
|
pub struct DomainCPUXML {
|
||||||
|
#[serde(rename(serialize = "@mode"))]
|
||||||
|
pub mode: String,
|
||||||
|
pub topology: Option<DomainCPUTopology>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Domain information, see https://libvirt.org/formatdomain.html
|
/// Domain information, see https://libvirt.org/formatdomain.html
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(rename = "domain")]
|
#[serde(rename = "domain")]
|
||||||
@ -202,6 +221,9 @@ pub struct DomainXML {
|
|||||||
/// The maximum allocation of memory for the guest at boot time
|
/// The maximum allocation of memory for the guest at boot time
|
||||||
pub memory: DomainMemoryXML,
|
pub memory: DomainMemoryXML,
|
||||||
|
|
||||||
|
/// CPU information
|
||||||
|
pub cpu: DomainCPUXML,
|
||||||
|
|
||||||
pub on_poweroff: String,
|
pub on_poweroff: String,
|
||||||
pub on_reboot: String,
|
pub on_reboot: String,
|
||||||
pub on_crash: String,
|
pub on_crash: String,
|
||||||
|
@ -2,9 +2,9 @@ use crate::app_config::AppConfig;
|
|||||||
use crate::constants;
|
use crate::constants;
|
||||||
use crate::libvirt_lib_structures::{
|
use crate::libvirt_lib_structures::{
|
||||||
DevicesXML, DiskBootXML, DiskDriverXML, DiskReadOnlyXML, DiskSourceXML, DiskTargetXML, DiskXML,
|
DevicesXML, DiskBootXML, DiskDriverXML, DiskReadOnlyXML, DiskSourceXML, DiskTargetXML, DiskXML,
|
||||||
DomainMemoryXML, DomainXML, FeaturesXML, GraphicsXML, NetworkDHCPRangeXML, NetworkDHCPXML,
|
DomainCPUTopology, DomainCPUXML, DomainMemoryXML, DomainXML, FeaturesXML, GraphicsXML,
|
||||||
NetworkDNSForwarderXML, NetworkDNSXML, NetworkDomainXML, NetworkForwardXML, NetworkIPXML,
|
NetworkDHCPRangeXML, NetworkDHCPXML, NetworkDNSForwarderXML, NetworkDNSXML, NetworkDomainXML,
|
||||||
NetworkXML, OSLoaderXML, OSTypeXML, XMLUuid, ACPIXML, OSXML,
|
NetworkForwardXML, NetworkIPXML, NetworkXML, OSLoaderXML, OSTypeXML, XMLUuid, ACPIXML, OSXML,
|
||||||
};
|
};
|
||||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
|
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
|
||||||
use crate::utils::disks_utils::Disk;
|
use crate::utils::disks_utils::Disk;
|
||||||
@ -245,9 +245,18 @@ impl VMInfo {
|
|||||||
memory: self.memory,
|
memory: self.memory,
|
||||||
},
|
},
|
||||||
|
|
||||||
on_poweroff: "preserve".to_string(),
|
cpu: DomainCPUXML {
|
||||||
|
mode: "host-passthrough".to_string(),
|
||||||
|
topology: Some(DomainCPUTopology {
|
||||||
|
sockets: 1,
|
||||||
|
cores: 1,
|
||||||
|
threads: 1,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
|
||||||
|
on_poweroff: "destroy".to_string(),
|
||||||
on_reboot: "restart".to_string(),
|
on_reboot: "restart".to_string(),
|
||||||
on_crash: "preserve".to_string(),
|
on_crash: "destroy".to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
log::debug!("Create required directory, if missing");
|
log::debug!("Create required directory, if missing");
|
||||||
files_utils::create_directory_if_missing(AppConfig::get().iso_storage_path()).unwrap();
|
files_utils::create_directory_if_missing(AppConfig::get().iso_storage_path()).unwrap();
|
||||||
files_utils::create_directory_if_missing(AppConfig::get().vnc_sockets_path()).unwrap();
|
files_utils::create_directory_if_missing(AppConfig::get().vnc_sockets_path()).unwrap();
|
||||||
|
files_utils::set_file_permission(AppConfig::get().vnc_sockets_path(), 0o644).unwrap();
|
||||||
files_utils::create_directory_if_missing(AppConfig::get().disks_storage_path()).unwrap();
|
files_utils::create_directory_if_missing(AppConfig::get().disks_storage_path()).unwrap();
|
||||||
|
|
||||||
let conn = Data::new(LibVirtClient(
|
let conn = Data::new(LibVirtClient(
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
const INVALID_CHARS: [&str; 19] = [
|
const INVALID_CHARS: [&str; 19] = [
|
||||||
@ -19,6 +20,14 @@ pub fn create_directory_if_missing<P: AsRef<Path>>(path: P) -> anyhow::Result<()
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update file permission
|
||||||
|
pub fn set_file_permission<P: AsRef<Path>>(path: P, mode: u32) -> anyhow::Result<()> {
|
||||||
|
let mut perms = std::fs::metadata(path.as_ref())?.permissions();
|
||||||
|
perms.set_mode(mode);
|
||||||
|
std::fs::set_permissions(path.as_ref(), perms)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::utils::files_utils::check_file_name;
|
use crate::utils::files_utils::check_file_name;
|
||||||
|
Loading…
Reference in New Issue
Block a user