From 80311db549c7bbebb0325f525554baf6739e75af Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Thu, 18 Jan 2024 01:38:56 -0800 Subject: [PATCH] hypha: name domain with uuid --- hypha/src/ctl/mod.rs | 4 ++++ hypha/src/image/cache.rs | 2 +- xenclient/examples/boot.rs | 1 + xenclient/src/lib.rs | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hypha/src/ctl/mod.rs b/hypha/src/ctl/mod.rs index 2383f5b..072d024 100644 --- a/hypha/src/ctl/mod.rs +++ b/hypha/src/ctl/mod.rs @@ -4,6 +4,7 @@ use crate::image::{ImageCompiler, ImageInfo}; use ocipkg::ImageName; use std::fs; use std::path::PathBuf; +use uuid::Uuid; use xenclient::{DomainConfig, XenClient}; pub struct Controller { @@ -50,8 +51,11 @@ impl Controller { } pub fn launch(&mut self) -> Result { + let uuid = Uuid::new_v4(); + let name = format!("hypha-{uuid}"); let _image_info = self.compile()?; let config = DomainConfig { + name: &name, max_vcpus: self.vcpus, mem_mb: self.mem, kernel_path: self.kernel_path.as_str(), diff --git a/hypha/src/image/cache.rs b/hypha/src/image/cache.rs index 8f556ad..12df611 100644 --- a/hypha/src/image/cache.rs +++ b/hypha/src/image/cache.rs @@ -33,7 +33,7 @@ impl ImageCache { { let manifest_text = fs::read_to_string(&manifest_path)?; let manifest: ImageManifest = serde_json::from_str(&manifest_text)?; - let config_text = fs::read_to_string(&manifest_path)?; + let config_text = fs::read_to_string(&config_path)?; let config: ImageConfiguration = serde_json::from_str(&config_text)?; debug!("cache hit digest={}", digest); Some(ImageInfo::new(squashfs_path.clone(), manifest, config)?) diff --git a/xenclient/examples/boot.rs b/xenclient/examples/boot.rs index c2092c6..ca750d4 100644 --- a/xenclient/examples/boot.rs +++ b/xenclient/examples/boot.rs @@ -13,6 +13,7 @@ fn main() -> Result<(), XenClientError> { let initrd_path = args.get(2).expect("argument not specified"); let mut client = XenClient::open()?; let config = DomainConfig { + name: "xenclient-test", max_vcpus: 1, mem_mb: 512, kernel_path: kernel_image_path.as_str(), diff --git a/xenclient/src/lib.rs b/xenclient/src/lib.rs index 9db75b7..6490ba1 100644 --- a/xenclient/src/lib.rs +++ b/xenclient/src/lib.rs @@ -79,6 +79,7 @@ impl From for XenClientError { } pub struct DomainConfig<'a> { + pub name: &'a str, pub max_vcpus: u32, pub mem_mb: u64, pub kernel_path: &'a str, @@ -153,7 +154,8 @@ impl XenClient { format!("{}/uuid", vm_path).as_str(), &Uuid::from_bytes(domain.handle).to_string(), )?; - tx.write_string(format!("{}/name", vm_path).as_str(), "mycelium")?; + tx.write_string(format!("{}/name", dom_path).as_str(), config.name)?; + tx.write_string(format!("{}/name", vm_path).as_str(), config.name)?; tx.write_string(format!("{}/type", libxl_path).as_str(), "pv")?; tx.commit()?; }