2024-03-23 09:48:53 +00:00
|
|
|
pub mod attach;
|
2024-03-15 15:59:18 +00:00
|
|
|
pub mod destroy;
|
2024-04-14 04:54:21 -07:00
|
|
|
pub mod idm_snoop;
|
2024-03-15 15:59:18 +00:00
|
|
|
pub mod launch;
|
|
|
|
pub mod list;
|
2024-04-02 08:57:34 +00:00
|
|
|
pub mod logs;
|
2024-04-12 00:34:46 -07:00
|
|
|
pub mod metrics;
|
2024-03-23 09:48:53 +00:00
|
|
|
pub mod resolve;
|
2024-03-15 15:59:18 +00:00
|
|
|
pub mod watch;
|
|
|
|
|
2024-03-23 09:48:53 +00:00
|
|
|
use anyhow::{anyhow, Result};
|
2024-03-15 15:59:18 +00:00
|
|
|
use clap::{Parser, Subcommand};
|
2024-03-27 02:54:39 +00:00
|
|
|
use krata::{
|
|
|
|
client::ControlClientProvider,
|
|
|
|
events::EventStream,
|
2024-03-31 01:11:50 +00:00
|
|
|
v1::control::{control_service_client::ControlServiceClient, ResolveGuestRequest},
|
2024-03-23 09:48:53 +00:00
|
|
|
};
|
|
|
|
use tonic::{transport::Channel, Request};
|
2024-03-15 15:59:18 +00:00
|
|
|
|
|
|
|
use self::{
|
2024-04-14 04:54:21 -07:00
|
|
|
attach::AttachCommand, destroy::DestroyCommand, idm_snoop::IdmSnoopCommand,
|
|
|
|
launch::LauchCommand, list::ListCommand, logs::LogsCommand, metrics::MetricsCommand,
|
|
|
|
resolve::ResolveCommand, watch::WatchCommand,
|
2024-03-15 15:59:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
2024-04-05 17:00:02 -07:00
|
|
|
#[command(
|
|
|
|
version,
|
|
|
|
about = "Control the krata hypervisor, a secure platform for running containers"
|
|
|
|
)]
|
2024-03-15 15:59:18 +00:00
|
|
|
pub struct ControlCommand {
|
2024-04-05 17:00:02 -07:00
|
|
|
#[arg(
|
|
|
|
short,
|
|
|
|
long,
|
|
|
|
help = "The connection URL to the krata hypervisor",
|
|
|
|
default_value = "unix:///var/lib/krata/daemon.socket"
|
|
|
|
)]
|
2024-03-15 15:59:18 +00:00
|
|
|
connection: String,
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: Commands,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
pub enum Commands {
|
|
|
|
Launch(LauchCommand),
|
|
|
|
Destroy(DestroyCommand),
|
|
|
|
List(ListCommand),
|
2024-03-23 09:48:53 +00:00
|
|
|
Attach(AttachCommand),
|
2024-04-02 08:57:34 +00:00
|
|
|
Logs(LogsCommand),
|
2024-03-15 15:59:18 +00:00
|
|
|
Watch(WatchCommand),
|
2024-03-23 09:48:53 +00:00
|
|
|
Resolve(ResolveCommand),
|
2024-04-12 00:34:46 -07:00
|
|
|
Metrics(MetricsCommand),
|
2024-04-14 04:54:21 -07:00
|
|
|
IdmSnoop(IdmSnoopCommand),
|
2024-03-15 15:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ControlCommand {
|
|
|
|
pub async fn run(self) -> Result<()> {
|
2024-03-31 01:11:50 +00:00
|
|
|
let client = ControlClientProvider::dial(self.connection.parse()?).await?;
|
|
|
|
let events = EventStream::open(client.clone()).await?;
|
2024-03-15 15:59:18 +00:00
|
|
|
|
|
|
|
match self.command {
|
|
|
|
Commands::Launch(launch) => {
|
|
|
|
launch.run(client, events).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Commands::Destroy(destroy) => {
|
2024-03-23 10:09:00 +00:00
|
|
|
destroy.run(client, events).await?;
|
2024-03-15 15:59:18 +00:00
|
|
|
}
|
|
|
|
|
2024-03-23 09:48:53 +00:00
|
|
|
Commands::Attach(attach) => {
|
|
|
|
attach.run(client, events).await?;
|
2024-03-15 15:59:18 +00:00
|
|
|
}
|
|
|
|
|
2024-04-02 08:57:34 +00:00
|
|
|
Commands::Logs(logs) => {
|
|
|
|
logs.run(client, events).await?;
|
|
|
|
}
|
|
|
|
|
2024-03-15 15:59:18 +00:00
|
|
|
Commands::List(list) => {
|
|
|
|
list.run(client, events).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Commands::Watch(watch) => {
|
|
|
|
watch.run(events).await?;
|
|
|
|
}
|
2024-03-23 09:48:53 +00:00
|
|
|
|
|
|
|
Commands::Resolve(resolve) => {
|
|
|
|
resolve.run(client).await?;
|
|
|
|
}
|
2024-04-12 00:34:46 -07:00
|
|
|
|
|
|
|
Commands::Metrics(metrics) => {
|
|
|
|
metrics.run(client, events).await?;
|
|
|
|
}
|
2024-04-14 04:54:21 -07:00
|
|
|
|
|
|
|
Commands::IdmSnoop(snoop) => {
|
|
|
|
snoop.run(client, events).await?;
|
|
|
|
}
|
2024-03-15 15:59:18 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 09:48:53 +00:00
|
|
|
|
|
|
|
pub async fn resolve_guest(
|
|
|
|
client: &mut ControlServiceClient<Channel>,
|
|
|
|
name: &str,
|
|
|
|
) -> Result<String> {
|
|
|
|
let reply = client
|
|
|
|
.resolve_guest(Request::new(ResolveGuestRequest {
|
|
|
|
name: name.to_string(),
|
|
|
|
}))
|
|
|
|
.await?
|
|
|
|
.into_inner();
|
|
|
|
|
|
|
|
if let Some(guest) = reply.guest {
|
|
|
|
Ok(guest.id)
|
|
|
|
} else {
|
2024-03-23 10:09:00 +00:00
|
|
|
Err(anyhow!("unable to resolve guest '{}'", name))
|
2024-03-23 09:48:53 +00:00
|
|
|
}
|
|
|
|
}
|