-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wicket cli: add "inventory configured-bootstrap-sleds" #6218
Changes from all commits
ca0b62a
1108222
f806bb8
6806620
684ec65
a147d8c
fbba682
a0b89d8
83ee04f
0302895
fce6fa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Support for inventory checks via wicketd. | ||
|
||
use crate::cli::CommandOutput; | ||
use crate::wicketd::create_wicketd_client; | ||
use anyhow::Context; | ||
use anyhow::Result; | ||
use clap::{Subcommand, ValueEnum}; | ||
use owo_colors::OwoColorize; | ||
use sled_hardware_types::Baseboard; | ||
use slog::Logger; | ||
use std::fmt; | ||
use std::net::SocketAddrV6; | ||
use std::time::Duration; | ||
use wicket_common::rack_setup::BootstrapSledDescription; | ||
|
||
const WICKETD_TIMEOUT: Duration = Duration::from_secs(5); | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub(crate) enum InventoryArgs { | ||
/// List state of all bootstrap sleds, as configured with rack-setup | ||
ConfiguredBootstrapSleds { | ||
/// Select output format | ||
#[clap(long, default_value_t = OutputFormat::Table)] | ||
format: OutputFormat, | ||
}, | ||
} | ||
|
||
#[derive(Debug, ValueEnum, Clone)] | ||
pub enum OutputFormat { | ||
/// Print output as operator-readable table | ||
Table, | ||
|
||
/// Print output as json | ||
Json, | ||
} | ||
|
||
impl fmt::Display for OutputFormat { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
OutputFormat::Table => write!(f, "table"), | ||
OutputFormat::Json => write!(f, "json"), | ||
} | ||
} | ||
} | ||
|
||
impl InventoryArgs { | ||
pub(crate) async fn exec( | ||
self, | ||
log: Logger, | ||
wicketd_addr: SocketAddrV6, | ||
mut output: CommandOutput<'_>, | ||
) -> Result<()> { | ||
let client = create_wicketd_client(&log, wicketd_addr, WICKETD_TIMEOUT); | ||
|
||
match self { | ||
InventoryArgs::ConfiguredBootstrapSleds { format } => { | ||
// We don't use the /bootstrap-sleds endpoint, because that | ||
// gets all sleds visible on the bootstrap network. We want | ||
// something subtly different here. | ||
// - We want the status of only sleds we've configured wicket | ||
// to use for setup. /bootstrap-sleds will give us sleds | ||
// we don't want | ||
// - We want the status even if they aren't visible on the | ||
// bootstrap network yet. | ||
// | ||
// In other words, we want the sled information displayed at the | ||
// bottom of the rack setup screen in the TUI, and we get it the | ||
// same way it does. | ||
let conf = client | ||
.get_rss_config() | ||
.await | ||
.context("failed to get rss config")?; | ||
|
||
let bootstrap_sleds = &conf.insensitive.bootstrap_sleds; | ||
match format { | ||
OutputFormat::Json => { | ||
let json_str = | ||
serde_json::to_string_pretty(bootstrap_sleds) | ||
.context("serializing sled data failed")?; | ||
writeln!(output.stdout, "{}", json_str) | ||
.expect("writing to stdout failed"); | ||
} | ||
OutputFormat::Table => { | ||
for sled in bootstrap_sleds { | ||
print_bootstrap_sled_data(sled, &mut output); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn print_bootstrap_sled_data( | ||
desc: &BootstrapSledDescription, | ||
output: &mut CommandOutput<'_>, | ||
) { | ||
let slot = desc.id.slot; | ||
|
||
let identifier = match &desc.baseboard { | ||
Baseboard::Gimlet { identifier, .. } => identifier.clone(), | ||
Baseboard::Pc { identifier, .. } => identifier.clone(), | ||
Baseboard::Unknown => "unknown".to_string(), | ||
}; | ||
|
||
let address = desc.bootstrap_ip; | ||
|
||
// Create status indicators | ||
let status = match address { | ||
None => format!("{}", '⚠'.red()), | ||
Some(_) => format!("{}", '✔'.green()), | ||
}; | ||
|
||
let addr_fmt = match address { | ||
None => "(not available)".to_string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpicky: looks like there's no whitespace in this case and it's smushed up against the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah. artifact from my first pass where i didnt print anything when there wasnt an address. |
||
Some(addr) => format!("{}", addr), | ||
}; | ||
|
||
// Print out this entry. We say "Cubby" rather than "Slot" here purely | ||
// because the TUI also says "Cubby". | ||
writeln!( | ||
output.stdout, | ||
"{status} Cubby {:02}\t{identifier}\t{addr_fmt}", | ||
slot | ||
) | ||
.expect("writing to stdout failed"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
//! support for that. | ||
|
||
mod command; | ||
mod inventory; | ||
mod preflight; | ||
mod rack_setup; | ||
mod rack_update; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, the
colored
crate's.red()
and.green()
return aColoredString
, which is the same type either way, so i don't think we need toformat!
these?although maybe i'm overlooking something...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think we use owo-colors here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think red() and green() here return Display or something like that.