Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/commands/inspect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 Red Hat, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::process::Command;

use crate::{
utils::{get_buildah_args, BuildahCommand},
KrunvmConfig,
};
use clap::Args;

/// Run `buildah inspect` on an existing microVM
#[derive(Args, Debug)]
pub struct InspectCmd {
/// Name of the microVM to be inspected
name: String,
}

impl InspectCmd {
pub fn run(self, cfg: &mut KrunvmConfig) {
let vmcfg = match cfg.vmconfig_map.get(&self.name) {
None => {
println!("No VM found with that name");
std::process::exit(-1);
}
Some(vmcfg) => vmcfg,
};

let mut args = get_buildah_args(cfg, BuildahCommand::Inspect);
args.push(vmcfg.container.clone());

let output = Command::new("buildah")
.args(&args)
.stderr(std::process::Stdio::inherit())
.output();

if output.is_err() {
println!("Failed to inspect VM");
std::process::exit(1);
}

let output = match String::from_utf8(output.unwrap().stdout) {
Err(err) => {
println!("Failed to parse `buildah inspect` output: #{err}.");
std::process::exit(1);
}
Ok(output) => output,
};

println!("{output}");
}
}
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ mod changevm;
mod config;
mod create;
mod delete;
mod inspect;
mod list;
mod start;

pub use changevm::ChangeVmCmd;
pub use config::ConfigCmd;
pub use create::CreateCmd;
pub use delete::DeleteCmd;
pub use inspect::InspectCmd;
pub use list::ListCmd;
pub use start::StartCmd;
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::fs::File;
#[cfg(target_os = "macos")]
use std::io::{self, Read, Write};

use crate::commands::{ChangeVmCmd, ConfigCmd, CreateCmd, DeleteCmd, ListCmd, StartCmd};
use crate::commands::{
ChangeVmCmd, ConfigCmd, CreateCmd, DeleteCmd, InspectCmd, ListCmd, StartCmd,
};
use clap::{Parser, Subcommand};
use serde_derive::{Deserialize, Serialize};
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -159,6 +161,7 @@ struct Cli {
enum Command {
Start(StartCmd),
Create(CreateCmd),
Inspect(InspectCmd),
List(ListCmd),
Delete(DeleteCmd),
#[command(name = "changevm")]
Expand All @@ -176,6 +179,7 @@ fn main() {
check_unshare();

match cli_args.command {
Command::Inspect(cmd) => cmd.run(&mut cfg),
Command::Start(cmd) => cmd.run(&cfg),
Command::Create(cmd) => cmd.run(&mut cfg),
Command::List(cmd) => cmd.run(&cfg),
Expand Down
Loading