krata: api cleanup and improvements

This commit is contained in:
Alex Zenla
2024-03-24 05:25:48 +00:00
parent 7543fccfaf
commit cb6839b0f6
7 changed files with 99 additions and 69 deletions

View File

@ -1,7 +1,12 @@
use std::collections::HashMap;
use anyhow::Result;
use clap::Parser;
use krata::{
common::{guest_image_spec::Image, GuestImageSpec, GuestOciImageSpec, GuestSpec, GuestStatus},
common::{
guest_image_spec::Image, GuestEnvVar, GuestImageSpec, GuestOciImageSpec, GuestSpec,
GuestStatus,
},
control::{
control_service_client::ControlServiceClient, watch_events_reply::Event, CreateGuestRequest,
},
@ -46,7 +51,13 @@ impl LauchCommand {
}),
vcpus: self.cpus,
mem: self.mem,
env: self.env.unwrap_or_default(),
env: env_map(&self.env.unwrap_or_default())
.iter()
.map(|(key, value)| GuestEnvVar {
key: key.clone(),
value: value.clone(),
})
.collect(),
run: self.run,
}),
};
@ -121,3 +132,13 @@ async fn wait_guest_started(id: &str, events: EventStream) -> Result<()> {
}
Ok(())
}
fn env_map(env: &[String]) -> HashMap<String, String> {
let mut map = HashMap::<String, String>::new();
for item in env {
if let Some((key, value)) = item.split_once('=') {
map.insert(key.to_string(), value.to_string());
}
}
map
}