diff --git a/hypha/bin/controller.rs b/hypha/bin/controller.rs index f0b70c4..8d7a530 100644 --- a/hypha/bin/controller.rs +++ b/hypha/bin/controller.rs @@ -22,8 +22,6 @@ enum Commands { kernel: String, #[arg(short = 'r', long, default_value = "auto")] initrd: String, - #[arg(short, long)] - image: String, #[arg(short, long, default_value_t = 1)] cpus: u32, #[arg(short, long, default_value_t = 512)] @@ -32,16 +30,18 @@ enum Commands { config_bundle: Option, #[arg[short, long]] env: Option>, + #[arg()] + image: String, #[arg(allow_hyphen_values = true, trailing_var_arg = true)] run: Vec, }, Destroy { - #[arg(short, long)] - domain: u32, + #[arg()] + container: String, }, Console { - #[arg(short, long)] - domain: u32, + #[arg()] + container: String, }, } @@ -88,12 +88,12 @@ fn main() -> Result<()> { println!("launched container: {}", uuid); } - Commands::Destroy { domain } => { - controller.destroy(domain)?; + Commands::Destroy { container } => { + controller.destroy(&container)?; } - Commands::Console { domain } => { - controller.console(domain)?; + Commands::Console { container } => { + controller.console(&container)?; } Commands::List { .. } => { diff --git a/hypha/src/ctl/mod.rs b/hypha/src/ctl/mod.rs index 3773dcb..8339a85 100644 --- a/hypha/src/ctl/mod.rs +++ b/hypha/src/ctl/mod.rs @@ -145,7 +145,11 @@ impl Controller { } } - pub fn destroy(&mut self, domid: u32) -> Result { + pub fn destroy(&mut self, id: &str) -> Result { + let info = self + .resolve(id)? + .ok_or_else(|| anyhow!("unable to resolve container: {}", id))?; + let domid = info.domid; let mut store = XsdClient::open()?; let dom_path = store.get_domain_path(domid)?; let uuid = match store.read_string_optional(format!("{}/hypha/uuid", dom_path).as_str())? { @@ -181,7 +185,11 @@ impl Controller { Ok(uuid) } - pub fn console(&mut self, domid: u32) -> Result<()> { + pub fn console(&mut self, id: &str) -> Result<()> { + let info = self + .resolve(id)? + .ok_or_else(|| anyhow!("unable to resolve container: {}", id))?; + let domid = info.domid; let (mut read, mut write) = self.client.open_console(domid)?; let mut stdin = io::stdin(); let is_tty = termion::is_tty(&stdin); @@ -258,6 +266,17 @@ impl Controller { Ok(containers) } + pub fn resolve(&mut self, id: &str) -> Result> { + for container in self.list()? { + let uuid_string = container.uuid.to_string(); + let domid_string = container.domid.to_string(); + if uuid_string == id || domid_string == id || id == format!("hypha-{}", uuid_string) { + return Ok(Some(container)); + } + } + Ok(None) + } + fn parse_loop_set(input: &str) -> Vec { let sets = input .split(',')