Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions monitor.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ base_image_max_age = 86400
# Uncomment to skip cached Servo repo updates.
# dont_update_cached_servo_repo = true

# Create libvirt guests for profile templates as “ci-template-<profile_name>.0”. Namespace must not be used by anything else!
# libvirt_template_guest_prefix = "ci-template"

# Create libvirt guests for image rebuilds as “ci-rebuild-<profile_name>.0”. Namespace must not be used by anything else!
# libvirt_rebuild_guest_prefix = "ci-rebuild"

# Create libvirt guests for runners as “ci-runner-<profile_name>.0”. Namespace must not be used by anything else!
# libvirt_runner_guest_prefix = "ci-runner"

Expand Down
14 changes: 14 additions & 0 deletions monitor/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct Toml {
pub main_repo_path: String,
base_image_max_age: u64,
dont_update_cached_servo_repo: Option<bool>,
libvirt_template_guest_prefix: Option<String>,
libvirt_rebuild_guest_prefix: Option<String>,
libvirt_runner_guest_prefix: Option<String>,
pub available_1g_hugepages: usize,
pub available_normal_memory: MemorySize,
Expand Down Expand Up @@ -242,6 +244,18 @@ impl Toml {
self.queue_member.unwrap_or(false)
}

pub fn libvirt_template_guest_prefix(&self) -> &str {
self.libvirt_template_guest_prefix
.as_deref()
.unwrap_or("ci-template")
}

pub fn libvirt_rebuild_guest_prefix(&self) -> &str {
self.libvirt_rebuild_guest_prefix
.as_deref()
.unwrap_or("ci-rebuild")
}

pub fn libvirt_runner_guest_prefix(&self) -> &str {
self.libvirt_runner_guest_prefix
.as_deref()
Expand Down
41 changes: 39 additions & 2 deletions monitor/settings/src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use jane_eyre::eyre::{self, OptionExt};
use serde::{Deserialize, Serialize};

use crate::{TOML, units::MemorySize};
Expand All @@ -20,8 +21,24 @@ pub enum ImageType {
}

impl Profile {
pub fn profile_guest_name(&self) -> String {
format!("{}", self.profile_name)
pub fn snapshot_path_slug(&self, snapshot_name: &str) -> String {
format!("{}@{snapshot_name}", self.profile_name)
}

pub fn template_guest_name(&self, snapshot_name: &str) -> String {
format!(
"{}-{}@{snapshot_name}",
TOML.libvirt_template_guest_prefix(),
self.profile_name
)
}

pub fn rebuild_guest_name(&self, snapshot_name: &str) -> String {
format!(
"{}-{}@{snapshot_name}",
TOML.libvirt_rebuild_guest_prefix(),
self.profile_name
)
}

pub fn runner_guest_name(&self, id: usize) -> String {
Expand All @@ -33,3 +50,23 @@ impl Profile {
)
}
}

pub fn parse_template_guest_name(template_guest_name: &str) -> eyre::Result<(&str, &str)> {
let prefix = format!("{}-", TOML.libvirt_template_guest_prefix());
let (profile_key, snapshot_name) = template_guest_name
.strip_prefix(&prefix)
.ok_or_eyre("Failed to strip template guest prefix")?
.split_once("@")
.ok_or_eyre("Failed to split snapshot path slug into profile key and snapshot name")?;
Ok((profile_key, snapshot_name))
}

pub fn parse_rebuild_guest_name(rebuild_guest_name: &str) -> eyre::Result<(&str, &str)> {
let prefix = format!("{}-", TOML.libvirt_rebuild_guest_prefix());
let (profile_key, snapshot_name) = rebuild_guest_name
.strip_prefix(&prefix)
.ok_or_eyre("Failed to strip rebuild guest prefix")?
.split_once("@")
.ok_or_eyre("Failed to split snapshot path slug into profile key and snapshot name")?;
Ok((profile_key, snapshot_name))
}
Loading