-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wicket cli: add "inventory configured-bootstrap-sleds" (#6218)
## This PR My main motivation for adding: I am working on automating control plane deployment on london and madrid. Before we can start rack init, we need to know if all the sleds we are going to initialize are actually available. This information is something you can see from the rack init TUI, but there was no way to get it from the CLI. I have added an `inventory` command with a `configured-bootstrap-sleds` subcommand, which presents exactly the same information accessible in the TUI's rack init screen. (Note: there is no way to start rack init for the CLI yet, but I will add that in a future PR.) In theory `inventory` could be expanded to provide other information. Note, I am absolutely not attached to the command interface or data format. I only care about making this information accessible so I can use it in my scripts. Meaning, if *any* of this interface should be different from how I've done it in this initial PR, I will make those changes as asked. ### Example Usage ``` artemis@jeeves ~ $ ssh londonwicket inventory configured-bootstrap-sleds ⚠ Cubby 14 BRM42220036 (not available) ✔ Cubby 15 BRM42220062 fdb0:a840:2504:312::1 ✔ Cubby 16 BRM42220030 fdb0:a840:2504:257::1 ✔ Cubby 17 BRM44220007 fdb0:a840:2504:492::1 ``` ``` artemis@jeeves ~ $ ssh londonwicket -- inventory configured-bootstrap-sleds --json | jq [ { "id": { "slot": 14, "type": "sled" }, "baseboard": { "type": "gimlet", "identifier": "BRM42220036", "model": "913-0000019", "revision": 6 }, "bootstrap_ip": "fdb0:a840:2504:212::1" }, { "id": { "slot": 15, "type": "sled" }, "baseboard": { "type": "gimlet", "identifier": "BRM42220062", "model": "913-0000019", "revision": 6 }, "bootstrap_ip": "fdb0:a840:2504:312::1" }, { "id": { "slot": 16, "type": "sled" }, "baseboard": { "type": "gimlet", "identifier": "BRM42220030", "model": "913-0000019", "revision": 6 }, "bootstrap_ip": "fdb0:a840:2504:257::1" }, { "id": { "slot": 17, "type": "sled" }, "baseboard": { "type": "gimlet", "identifier": "BRM44220007", "model": "913-0000019", "revision": 6 }, "bootstrap_ip": "fdb0:a840:2504:492::1" } ] ```
- Loading branch information
1 parent
04fdbcd
commit d391e5c
Showing
4 changed files
with
203 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
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,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(), | ||
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"); | ||
} |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
//! support for that. | ||
mod command; | ||
mod inventory; | ||
mod preflight; | ||
mod rack_setup; | ||
mod rack_update; | ||
|
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