Skip to content

Commit

Permalink
blueprint-plan: allow omitted collection ID if exactly 1 exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jgallagher committed Jan 6, 2025
1 parent 275e24e commit a147954
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dev-tools/reconfigurator-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dropshot.workspace = true
humantime.workspace = true
indent_write.workspace = true
internal-dns-types.workspace = true
itertools.workspace = true
nexus-inventory.workspace = true
nexus-reconfigurator-planning.workspace = true
nexus-reconfigurator-simulation.workspace = true
Expand Down
21 changes: 19 additions & 2 deletions dev-tools/reconfigurator-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use clap::ValueEnum;
use clap::{Args, Parser, Subcommand};
use indent_write::fmt::IndentWriter;
use internal_dns_types::diff::DnsDiff;
use itertools::Itertools;
use nexus_inventory::CollectionBuilder;
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
use nexus_reconfigurator_planning::example::ExampleSystemBuilder;
Expand Down Expand Up @@ -396,7 +397,10 @@ struct BlueprintPlanArgs {
/// id of the blueprint on which this one will be based
parent_blueprint_id: Uuid,
/// id of the inventory collection to use in planning
collection_id: CollectionUuid,
///
/// Must be provided unless there is only one collection in the loaded
/// state.
collection_id: Option<CollectionUuid>,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -754,7 +758,20 @@ fn cmd_blueprint_plan(
let parent_blueprint_id = args.parent_blueprint_id;
let collection_id = args.collection_id;
let parent_blueprint = system.get_blueprint(parent_blueprint_id)?;
let collection = system.get_collection(collection_id)?;
let collection = match collection_id {
Some(collection_id) => system.get_collection(collection_id)?,
None => {
let mut all_collections_iter = system.all_collections();
match all_collections_iter.len() {
0 => bail!("cannot plan blueprint with no loaded collections"),
1 => all_collections_iter.next().expect("iter length is 1"),
_ => bail!(
"blueprint-plan: must specify collection ID (one of {:?})",
all_collections_iter.map(|c| c.id).join(", ")
),
}
}
};

let creator = "reconfigurator-sim";
let planning_input = sim.planning_input(parent_blueprint)?;
Expand Down

0 comments on commit a147954

Please sign in to comment.