-
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 9 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,110 @@ | ||||||||||
// 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; | ||||||||||
use owo_colors::OwoColorize; | ||||||||||
use sled_hardware_types::Baseboard; | ||||||||||
use slog::Logger; | ||||||||||
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 { | ||||||||||
/// Print output as json | ||||||||||
#[clap(long)] | ||||||||||
json: bool, | ||||||||||
}, | ||||||||||
} | ||||||||||
|
||||||||||
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 { json } => { | ||||||||||
// 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; | ||||||||||
if json { | ||||||||||
let json_str = serde_json::to_string(bootstrap_sleds) | ||||||||||
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, take it or leave it: maybe nicer to use
Suggested change
here, since there isn't a ton of JSON and we're not trying to send it over the network? that way, a human user gets more readable output by default, which is maybe nice if the thing consuming the JSON chokes on it? 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, love the idea of using |
||||||||||
.context("serializing sled data failed")?; | ||||||||||
writeln!(output.stdout, "{}", json_str) | ||||||||||
.expect("writing to stdout failed"); | ||||||||||
} else { | ||||||||||
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()), | ||||||||||
Comment on lines
+116
to
+117
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. IIUC, the
Suggested change
although maybe i'm overlooking something... 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. Ah I think we use owo-colors here. 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 i think red() and green() here return Display or something like that. |
||||||||||
}; | ||||||||||
|
||||||||||
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!("\t{}", 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}{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.
suuuper nitpicky, doesn't actually matter: elsewhere, when writing CLI commands with multiple output formats, i like to define an output format enum and have a
--output plain
or--output text
in addition to--output json
/--output csv
or what-have-you, rather than having a boolean flag for a specific format. that has two very small advantages IMO:--output
flag and passplain
orjson
, rather than adding/removing the--json
.but, OTTOH, this is a bit more code as it requires adding an enum and stuff...and, if other wicket commands have a
--json
already (AFAIK they don't, but i may have missed something), let's keep it consistent.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.
Agreed about this! I'd use
--format json
and--format human
.