Check if qemu-img is present before startup
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:
parent
ff372800bd
commit
de33c7d521
@ -108,3 +108,6 @@ pub const API_TOKEN_DESCRIPTION_MAX_LENGTH: usize = 30;
|
||||
|
||||
/// API token right path max length
|
||||
pub const API_TOKEN_RIGHT_PATH_MAX_LENGTH: usize = 255;
|
||||
|
||||
/// Qemu image program path
|
||||
pub const QEMU_IMAGE_PROGRAM: &str = "/usr/bin/qemu-img";
|
||||
|
@ -28,7 +28,7 @@ use virtweb_backend::controllers::{
|
||||
use virtweb_backend::libvirt_client::LibVirtClient;
|
||||
use virtweb_backend::middlewares::auth_middleware::AuthChecker;
|
||||
use virtweb_backend::nat::nat_conf_mode;
|
||||
use virtweb_backend::utils::files_utils;
|
||||
use virtweb_backend::utils::{exec_utils, files_utils};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
@ -43,6 +43,12 @@ async fn main() -> std::io::Result<()> {
|
||||
// Load additional config from file, if requested
|
||||
AppConfig::parse_env_file().unwrap();
|
||||
|
||||
log::debug!("Checking for required programs");
|
||||
exec_utils::check_program(
|
||||
constants::QEMU_IMAGE_PROGRAM,
|
||||
"QEMU disk image utility is required to manipulate QCow2 files!",
|
||||
);
|
||||
|
||||
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().vnc_sockets_path()).unwrap();
|
||||
|
10
virtweb_backend/src/utils/exec_utils.rs
Normal file
10
virtweb_backend/src/utils/exec_utils.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use std::path::Path;
|
||||
|
||||
/// Check the existence of a required program
|
||||
pub fn check_program(name: &str, description: &str) {
|
||||
let path = Path::new(name);
|
||||
|
||||
if !path.exists() {
|
||||
panic!("{name} does not exist! {description}");
|
||||
}
|
||||
}
|
@ -155,7 +155,7 @@ impl FileDisk {
|
||||
}
|
||||
|
||||
DiskFormat::QCow2 => {
|
||||
let mut cmd = Command::new("/usr/bin/qemu-img");
|
||||
let mut cmd = Command::new(constants::QEMU_IMAGE_PROGRAM);
|
||||
cmd.arg("create")
|
||||
.arg("-f")
|
||||
.arg("qcow2")
|
||||
@ -189,12 +189,13 @@ struct QCowInfoOutput {
|
||||
/// Get QCow2 virtual size
|
||||
fn qcow_virt_size(path: &str) -> anyhow::Result<usize> {
|
||||
// Run qemu-img
|
||||
let mut cmd = Command::new("qemu-img");
|
||||
let mut cmd = Command::new(constants::QEMU_IMAGE_PROGRAM);
|
||||
cmd.args(["info", path, "--output", "json", "--force-share"]);
|
||||
let output = cmd.output()?;
|
||||
if !output.status.success() {
|
||||
anyhow::bail!(
|
||||
"qemu-img info failed, status: {}, stderr: {}",
|
||||
"{} info failed, status: {}, stderr: {}",
|
||||
constants::QEMU_IMAGE_PROGRAM,
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
|
@ -1,3 +1,4 @@
|
||||
pub mod exec_utils;
|
||||
pub mod file_disks_utils;
|
||||
pub mod files_utils;
|
||||
pub mod net_utils;
|
||||
|
Loading…
x
Reference in New Issue
Block a user