Browse Source

feat: add build script for linking to libvirt

rust
Giovanni Torres 1 year ago
parent
commit
18dc6759d2
  1. 1740
      Cargo.lock
  2. 11
      Cargo.toml
  3. 9
      build.rs
  4. 6
      src/vm.rs

1740
Cargo.lock generated

File diff suppressed because it is too large Load Diff

11
Cargo.toml

@ -11,13 +11,8 @@ repository = "https://github.com/giovtorres/kvm-install-vm"
anyhow = "1.0"
clap = { version = "4.4", features = ["derive"] }
env_logger = "0.10"
futures-util = "0.3"
indicatif = "0.17"
ipnetwork = "0.20"
log = "0.4"
reqwest = { version = "0.11", features = ["json", "stream"] }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
tempfile = "3.8"
tokio = { version = "1", features = ["full"] }
virt = "0.3.1"
[build-dependencies]
pkg-config = "0.3"

9
build.rs

@ -0,0 +1,9 @@
fn main() {
println!("cargo:rustc-link-lib=virt");
// // Try using pkg-config to find libvirt
// match pkg_config::probe_library("libvirt") {
// Ok(_) => println!("Found libvirt via pkg-config"),
// Err(e) => println!("cargo:warning=Could not find libvirt via pkg-config: {}", e),
// }
}

6
src/vm.rs

@ -27,8 +27,8 @@ impl VirtualMachine {
}
pub fn connect(&mut self, uri: Option<&str>) -> Result<()> {
// Connect to libvirt daemon, default to "qemu:///system" if no URI provided
let uri = uri.or(Some("qemu:///system"));
// Connect to libvirt daemon, default to "qemu:///session" if no URI provided
let uri = uri.or(Some("qemu:///session"));
self.connection = Some(Connect::open(uri).context("Failed to connect to libvirt")?);
Ok(())
}
@ -68,7 +68,7 @@ impl VirtualMachine {
fn generate_domain_xml(&self) -> Result<String> {
// Generate domain XML
let xml = format!( r#"
let xml = format!(r#"
<domain type='kvm'>
<name>{}</name>
<memory unit='MiB'>{}</memory>

Loading…
Cancel
Save