diff --git a/hypha/bin/controller.rs b/hypha/bin/controller.rs index 2f1b067..5342072 100644 --- a/hypha/bin/controller.rs +++ b/hypha/bin/controller.rs @@ -1,8 +1,6 @@ use clap::Parser; use hypha::ctl::Controller; use hypha::error::Result; -use hypha::image::ImageCompiler; -use ocipkg::ImageName; #[derive(Parser, Debug)] #[command(version, about)] @@ -27,12 +25,9 @@ fn main() -> Result<()> { env_logger::init(); let args = ControllerArgs::parse(); - let mut controller = Controller::new(args.kernel, args.initrd, args.cpus, args.mem)?; - let image = ImageName::parse(args.image.as_str())?; - let compiler = ImageCompiler::new()?; - let squashfs = compiler.compile(&image)?; - println!("packed image into squashfs: {}", &squashfs); - + let mut controller = + Controller::new(args.kernel, args.initrd, args.image, args.cpus, args.mem)?; + controller.compile()?; let domid = controller.launch()?; println!("launched domain: {}", domid); Ok(()) diff --git a/hypha/src/ctl/mod.rs b/hypha/src/ctl/mod.rs index 366df9d..490495a 100644 --- a/hypha/src/ctl/mod.rs +++ b/hypha/src/ctl/mod.rs @@ -1,4 +1,6 @@ use crate::error::Result; +use crate::image::ImageCompiler; +use ocipkg::ImageName; use xenclient::{DomainConfig, XenClient}; pub struct Controller { @@ -7,12 +9,14 @@ pub struct Controller { initrd_path: String, vcpus: u32, mem: u64, + image: String, } impl Controller { pub fn new( kernel_path: String, initrd_path: String, + image: String, vcpus: u32, mem: u64, ) -> Result { @@ -21,11 +25,19 @@ impl Controller { client, kernel_path, initrd_path, + image, vcpus, mem, }) } + pub fn compile(&mut self) -> Result<()> { + let image = ImageName::parse(&self.image)?; + let compiler = ImageCompiler::new()?; + let _squashfs = compiler.compile(&image)?; + Ok(()) + } + pub fn launch(&mut self) -> Result { let config = DomainConfig { max_vcpus: self.vcpus,