virtweb_backend/src
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;
|
||||
|
Reference in New Issue
Block a user