Skip to content

Commit 714b357

Browse files
committed
hypervisor: initial polymorphic hypervisor interface
1 parent 6a062fe commit 714b357

File tree

15 files changed

+100
-28
lines changed

15 files changed

+100
-28
lines changed

Cargo.lock

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
[workspace]
22
resolver = "3"
33
default-members = ["monitor"]
4-
members = ["monitor", "monitor/cli", "monitor/settings", "monitor/web"]
4+
members = ["monitor", "monitor/cli", "monitor/hypervisor", "monitor/settings", "monitor/shell", "monitor/web"]
55
exclude = ["analysis", "docker"]
66

77
[workspace.dependencies]
88
bytesize = "2.0.1"
99
chrono = { version = "0.4.39", features = ["serde"] }
1010
cli = { path = "monitor/cli" }
11+
cmd_lib = "1.9.5"
1112
dotenv = "0.15.0"
13+
hypervisor = { path = "monitor/hypervisor" }
1214
jane-eyre = "0.3.0"
1315
mktemp = "0.5.1"
1416
rocket = { version = "0.5.1", features = ["json"] }
1517
serde = { version = "1.0.204", features = ["derive"] }
1618
settings = { path = "monitor/settings" }
19+
shell = { path = "monitor/shell" }
1720
toml = "0.8.15"
1821
tracing = "0.1.40"
1922
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

monitor/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ bytesize = { workspace = true }
1111
cfg-if = "1.0.1"
1212
chrono = { workspace = true }
1313
cli = { workspace = true }
14-
cmd_lib = "1.9.5"
14+
cmd_lib = { workspace = true }
1515
crossbeam-channel = "0.5.13"
1616
dotenv = { workspace = true }
1717
http = "0.2"
18+
hypervisor = { workspace = true }
1819
itertools = "0.13.0"
1920
jane-eyre = { workspace = true }
2021
mktemp = { workspace = true }
21-
reflink = "0.1.3"
2222
reqwest = { version = "0.12.24", features = ["charset", "http2", "json", "rustls-tls", "system-proxy"], default-features = false }
2323
rocket = { workspace = true }
2424
serde = { workspace = true }
@@ -31,6 +31,7 @@ tracing = { workspace = true }
3131
tracing-subscriber = { workspace = true }
3232
web = { workspace = true }
3333
rand = "0.9.1"
34+
shell.workspace = true
3435

3536
[dev-dependencies]
3637
settings = { workspace = true, features = ["test"] }

monitor/hypervisor/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "hypervisor"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
cmd_lib.workspace = true
8+
jane-eyre.workspace = true
9+
settings.workspace = true
10+
shell.workspace = true
11+
tracing.workspace = true

monitor/src/libvirt.rs renamed to monitor/hypervisor/src/impl_libvirt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use std::{
88
use cmd_lib::{run_fun, spawn_with_output};
99
use jane_eyre::eyre;
1010
use settings::TOML;
11+
use shell::log_output_as_trace;
1112
use tracing::debug;
1213

13-
use crate::shell::log_output_as_trace;
14-
1514
pub fn list_template_guests() -> eyre::Result<Vec<String>> {
1615
// Output is not filtered by prefix, so we must filter it ourselves.
1716
let prefix = format!("{}-", TOML.libvirt_template_guest_prefix());

monitor/hypervisor/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#[cfg_attr(target_os = "linux", path = "impl_libvirt.rs")]
2+
mod platform;
3+
4+
use std::{net::Ipv4Addr, path::Path};
5+
6+
use jane_eyre::eyre;
7+
8+
pub fn list_template_guests() -> eyre::Result<Vec<String>> {
9+
self::platform::list_template_guests()
10+
}
11+
12+
pub fn list_rebuild_guests() -> eyre::Result<Vec<String>> {
13+
self::platform::list_rebuild_guests()
14+
}
15+
16+
pub fn list_runner_guests() -> eyre::Result<Vec<String>> {
17+
self::platform::list_runner_guests()
18+
}
19+
20+
pub fn update_screenshot(guest_name: &str, output_dir: &Path) -> eyre::Result<()> {
21+
self::platform::update_screenshot(guest_name, output_dir)
22+
}
23+
24+
pub fn take_screenshot(guest_name: &str, output_path: &Path) -> eyre::Result<()> {
25+
self::platform::take_screenshot(guest_name, output_path)
26+
}
27+
28+
pub fn get_ipv4_address(guest_name: &str) -> Option<Ipv4Addr> {
29+
self::platform::get_ipv4_address(guest_name)
30+
}

monitor/shell/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "shell"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
jane-eyre.workspace = true
8+
mktemp.workspace = true
9+
reflink = "0.1.3"
10+
tracing.workspace = true
File renamed without changes.

monitor/src/image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ use std::{
1919
use bytesize::ByteSize;
2020
use chrono::{SecondsFormat, Utc};
2121
use cmd_lib::{run_cmd, run_fun, spawn_with_output};
22+
use hypervisor::{list_rebuild_guests, list_template_guests};
2223
use jane_eyre::eyre::{self, bail, OptionExt};
2324
use settings::{
2425
profile::{parse_rebuild_guest_name, parse_template_guest_name, Profile},
2526
TOML,
2627
};
28+
use shell::{log_output_as_info, reflink_or_copy_with_warning};
2729
use tracing::{debug, error, info, warn};
2830

2931
use crate::{
3032
image::{macos13::Macos13, ubuntu2204::Ubuntu2204, windows10::Windows10},
31-
libvirt::{list_rebuild_guests, list_template_guests},
3233
policy::{runner_images_path, template_or_rebuild_images_path, Policy},
33-
shell::{log_output_as_info, reflink_or_copy_with_warning},
3434
};
3535

3636
static IMAGES: LazyLock<BTreeMap<String, Box<dyn Image + Send + Sync>>> = LazyLock::new(|| {

monitor/src/image/macos13.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use cmd_lib::spawn_with_output;
1010
use jane_eyre::eyre;
1111
use jane_eyre::eyre::OptionExt;
1212
use settings::profile::Profile;
13+
use shell::atomic_symlink;
14+
use shell::log_output_as_info;
15+
use shell::reflink_or_copy_with_warning;
1316
use tracing::warn;
1417

1518
use crate::data::get_profile_data_path;
@@ -23,9 +26,6 @@ use crate::image::CdromImage;
2326
use crate::image::Image;
2427
use crate::policy::runner_image_path;
2528
use crate::policy::template_or_rebuild_image_path;
26-
use crate::shell::atomic_symlink;
27-
use crate::shell::log_output_as_info;
28-
use crate::shell::reflink_or_copy_with_warning;
2929

3030
use super::create_disk_image;
3131
use super::start_libvirt_guest;

0 commit comments

Comments
 (0)