Skip to content

Commit 3db43b9

Browse files
authored
[31/n] [reconfigurator-cli] add inventory-show command (#8617)
Use the display logic implemented in #8613 to show inventory collections in reconfigurator-cli. I had to change some of the timestamps to be in RFC 3339 format to allow redactions to work properly. Kind of addresses #8611, in the sense that we now have tests that render collection output and ensure it looks reasonable.
1 parent dd422b1 commit 3db43b9

File tree

3 files changed

+428
-11
lines changed

3 files changed

+428
-11
lines changed

dev-tools/reconfigurator-cli/src/lib.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use nexus_types::deployment::{
4141
use nexus_types::deployment::{OmicronZoneNic, TargetReleaseDescription};
4242
use nexus_types::external_api::views::SledPolicy;
4343
use nexus_types::external_api::views::SledProvisionPolicy;
44+
use nexus_types::inventory::CollectionDisplayCliFilter;
4445
use omicron_common::address::REPO_DEPOT_PORT;
4546
use omicron_common::api::external::Name;
4647
use omicron_common::api::external::{Generation, TufRepoDescription};
@@ -236,6 +237,7 @@ fn process_command(
236237
Commands::SiloRemove(args) => cmd_silo_remove(sim, args),
237238
Commands::InventoryList => cmd_inventory_list(sim),
238239
Commands::InventoryGenerate => cmd_inventory_generate(sim),
240+
Commands::InventoryShow(args) => cmd_inventory_show(sim, args),
239241
Commands::BlueprintList => cmd_blueprint_list(sim),
240242
Commands::BlueprintBlippy(args) => cmd_blueprint_blippy(sim, args),
241243
Commands::BlueprintEdit(args) => cmd_blueprint_edit(sim, args),
@@ -298,6 +300,8 @@ enum Commands {
298300
InventoryList,
299301
/// generates an inventory collection from the configured sleds
300302
InventoryGenerate,
303+
/// show details about an inventory collection
304+
InventoryShow(InventoryShowArgs),
301305

302306
/// list all blueprints
303307
BlueprintList,
@@ -511,9 +515,16 @@ struct SiloAddRemoveArgs {
511515
}
512516

513517
#[derive(Debug, Args)]
514-
struct InventoryArgs {
515-
/// id of the inventory collection to use in planning
516-
collection_id: CollectionUuid,
518+
struct InventoryShowArgs {
519+
/// id of the inventory collection to show or "latest"
520+
collection_id: CollectionIdOpt,
521+
522+
/// show long strings in their entirety
523+
#[clap(long)]
524+
show_long_strings: bool,
525+
526+
#[clap(subcommand)]
527+
filter: Option<CollectionDisplayCliFilter>,
517528
}
518529

519530
#[derive(Debug, Args)]
@@ -992,14 +1003,6 @@ enum CliDnsGroup {
9921003
External,
9931004
}
9941005

995-
#[derive(Debug, Args)]
996-
struct BlueprintDiffInventoryArgs {
997-
/// id of the inventory collection
998-
collection_id: CollectionUuid,
999-
/// id of the blueprint, "latest", or "target"
1000-
blueprint_id: BlueprintIdOpt,
1001-
}
1002-
10031006
#[derive(Debug, Args)]
10041007
struct BlueprintSaveArgs {
10051008
/// id of the blueprint, "latest", or "target"
@@ -1463,6 +1466,24 @@ fn cmd_inventory_generate(
14631466
Ok(Some(rv))
14641467
}
14651468

1469+
fn cmd_inventory_show(
1470+
sim: &mut ReconfiguratorSim,
1471+
args: InventoryShowArgs,
1472+
) -> anyhow::Result<Option<String>> {
1473+
let state = sim.current_state();
1474+
let system = state.system();
1475+
let resolved = system.resolve_collection_id(args.collection_id.into())?;
1476+
let collection = system.get_collection(&resolved)?;
1477+
1478+
let mut display = collection.display();
1479+
if let Some(filter) = &args.filter {
1480+
display.apply_cli_filter(filter);
1481+
}
1482+
display.show_long_strings(args.show_long_strings);
1483+
1484+
Ok(Some(display.to_string()))
1485+
}
1486+
14661487
fn cmd_blueprint_list(
14671488
sim: &mut ReconfiguratorSim,
14681489
) -> anyhow::Result<Option<String>> {

dev-tools/reconfigurator-cli/tests/input/cmds-example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ load-example --seed test-basic --nsleds 3 --sled-policy 1:non-provisionable --sl
5252

5353
blueprint-list
5454
blueprint-show latest
55+
inventory-show latest
5556

5657
# Plan a blueprint run -- this will cause zones and disks on the expunged
5758
# sled to be expunged.

0 commit comments

Comments
 (0)