mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-02 12:50:54 +00:00
hypha: implement arg cli interface and dynamic container lookup
This commit is contained in:
parent
86c512474a
commit
def4306a04
@ -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<String>,
|
||||
#[arg[short, long]]
|
||||
env: Option<Vec<String>>,
|
||||
#[arg()]
|
||||
image: String,
|
||||
#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
|
||||
run: Vec<String>,
|
||||
},
|
||||
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 { .. } => {
|
||||
|
@ -145,7 +145,11 @@ impl Controller {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy(&mut self, domid: u32) -> Result<Uuid> {
|
||||
pub fn destroy(&mut self, id: &str) -> Result<Uuid> {
|
||||
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<Option<ContainerInfo>> {
|
||||
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<ContainerLoopInfo> {
|
||||
let sets = input
|
||||
.split(',')
|
||||
|
Loading…
Reference in New Issue
Block a user