test libvirt from rust
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
94861e5296
commit
df8e362034
|
@ -20,6 +20,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
|
@ -1882,10 +1888,20 @@ version = "0.9.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
|
||||
[[package]]
|
||||
name = "virt"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ce5cd536aa559d1088ddc531bbf3e55edc5db8ec0a5329dfb17f83a5b469ca"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "waifud"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"diesel",
|
||||
"diesel_migrations",
|
||||
"r2d2_redis",
|
||||
|
@ -1901,6 +1917,7 @@ dependencies = [
|
|||
"tracing-log",
|
||||
"tracing-subscriber",
|
||||
"uuid 0.8.2",
|
||||
"virt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -9,6 +9,7 @@ repository = "https://github.com/Xe/waifud"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
diesel_migrations = "1"
|
||||
r2d2_redis = "0.14.0"
|
||||
serde_json = "1"
|
||||
|
@ -17,6 +18,7 @@ tracing-futures = "0.2"
|
|||
tracing-log = "0.1"
|
||||
tracing-subscriber = "0.2"
|
||||
uuid = "0.8"
|
||||
virt = "0.2"
|
||||
|
||||
[dependencies.diesel]
|
||||
version = "1"
|
||||
|
|
|
@ -14,6 +14,7 @@ in pkgs.mkShell rec {
|
|||
pkg-config
|
||||
sqliteInteractive
|
||||
diesel-cli
|
||||
libvirt
|
||||
|
||||
# dhall
|
||||
dhall
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
use anyhow::Result;
|
||||
use virt::connect::Connect;
|
||||
|
||||
fn list_all_vms(uri: &str) -> Result<()> {
|
||||
let mut conn = Connect::open(uri)?;
|
||||
for dom in conn.list_all_domains(0)? {
|
||||
// if dom.is_active().unwrap() {
|
||||
println!(
|
||||
"{:<30} {:<15}{:<6}{}",
|
||||
uri,
|
||||
dom.get_name()?,
|
||||
if dom.is_active()? { "on" } else { "off" },
|
||||
dom.get_uuid_string()?
|
||||
);
|
||||
// }
|
||||
}
|
||||
conn.close()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for host in &["kos-mos", "logos", "ontos", "pneuma"] {
|
||||
list_all_vms(&format!("qemu+ssh://root@{}/system", host)).unwrap()
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ extern crate diesel_migrations;
|
|||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use anyhow::{anyhow, Result};
|
||||
use diesel::prelude::*;
|
||||
use std::env;
|
||||
|
||||
|
@ -12,11 +12,10 @@ diesel_migrations::embed_migrations!("./migrations");
|
|||
pub fn establish_connection() -> Result<SqliteConnection> {
|
||||
let database_url = env::var("DATABASE_URL").unwrap_or("./var/waifud.db".to_string());
|
||||
SqliteConnection::establish(&database_url)
|
||||
.map_err(|why| eyre!("can't connect to {}: {}", database_url, why))
|
||||
.map_err(|why| anyhow!("can't connect to {}: {}", database_url, why))
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
info!("{} migrator starting up", waifud::APPLICATION_NAME);
|
||||
|
|
Loading…
Reference in New Issue