-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a `krunvm inspect` command that runs `buildah inspect` under the hood, so users can find information about the VM, such as the image metadata (e.g. image name and digest) or mount point.
- Loading branch information
1 parent
765614c
commit ccdd1fa
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters