Skip to content

Commit

Permalink
add diff, simplify some types
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Jan 12, 2024
1 parent d8ad0ee commit c39c75d
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 62 deletions.
6 changes: 6 additions & 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 clients/nexus-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "MPL-2.0"
chrono.workspace = true
futures.workspace = true
ipnetwork.workspace = true
nexus-types.workspace = true
omicron-common.workspace = true
omicron-passwords.workspace = true
progenitor.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ progenitor::generate_api!(
slog::debug!(log, "client response"; "result" => ?result);
}),
replace = {
// It's kind of unfortunate to pull in such a complex and unstable type
// as "blueprint" this way, but we have really useful functionality
// (e.g., diff'ing) that's implemented on our local type.
Blueprint = nexus_types::deployment::Blueprint,
Generation = omicron_common::api::external::Generation,
Ipv4Network = ipnetwork::Ipv4Network,
Ipv6Network = ipnetwork::Ipv6Network,
Expand Down
29 changes: 29 additions & 0 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ enum BlueprintsCommands {
List,
/// Show a blueprint
Show(BlueprintIdArgs),
/// Diff two blueprint
Diff(BlueprintIdsArgs),
/// Delete a blueprint
Delete(BlueprintIdArgs),
/// Set the current target blueprint
Expand All @@ -86,6 +88,14 @@ struct BlueprintIdArgs {
blueprint_id: Uuid,
}

#[derive(Debug, Args)]
struct BlueprintIdsArgs {
/// id of first blueprint
blueprint1_id: Uuid,
/// id of second blueprint
blueprint2_id: Uuid,
}

#[derive(Debug, Args)]
struct BlueprintsTargetArgs {
#[command(subcommand)]
Expand Down Expand Up @@ -146,6 +156,9 @@ impl NexusArgs {
NexusCommands::Blueprints(BlueprintsArgs {
command: BlueprintsCommands::Show(args),
}) => cmd_nexus_blueprints_show(&client, args).await,
NexusCommands::Blueprints(BlueprintsArgs {
command: BlueprintsCommands::Diff(args),
}) => cmd_nexus_blueprints_diff(&client, args).await,
NexusCommands::Blueprints(BlueprintsArgs {
command: BlueprintsCommands::Delete(args),
}) => cmd_nexus_blueprints_delete(&client, args).await,
Expand Down Expand Up @@ -810,6 +823,22 @@ async fn cmd_nexus_blueprints_show(
Ok(())
}

async fn cmd_nexus_blueprints_diff(
client: &nexus_client::Client,
args: &BlueprintIdsArgs,
) -> Result<(), anyhow::Error> {
let b1 = client
.blueprint_view(&args.blueprint1_id)
.await
.with_context(|| format!("fetching blueprint {}", args.blueprint1_id))?;
let b2 = client
.blueprint_view(&args.blueprint2_id)
.await
.with_context(|| format!("fetching blueprint {}", args.blueprint2_id))?;
println!("{}", b1.diff(&b2));
Ok(())
}

async fn cmd_nexus_blueprints_delete(
client: &nexus_client::Client,
args: &BlueprintIdArgs,
Expand Down
7 changes: 7 additions & 0 deletions nexus/deployment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ thiserror.workspace = true
uuid.workspace = true

omicron-workspace-hack.workspace = true

[dev-dependencies]
expectorate.workspace = true
nexus-inventory.workspace = true
omicron-test-utils.workspace = true
rand.workspace = true
sled-agent-client.workspace = true
17 changes: 8 additions & 9 deletions nexus/deployment/src/blueprint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ impl<'a> BlueprintBuilder<'a> {
policy: &'a Policy,
creator: &str,
) -> Result<Blueprint, Error> {
let sleds: BTreeSet<_> = policy.sleds.keys().copied().collect();
let omicron_zones = sleds
.iter()
let omicron_zones = policy
.sleds
.keys()
.map(|sled_id| {
let zones = collection
.omicron_zones
Expand Down Expand Up @@ -114,7 +114,6 @@ impl<'a> BlueprintBuilder<'a> {
collection.all_omicron_zones().map(|z| z.id).collect();
Ok(Blueprint {
id: Uuid::new_v4(),
sleds_in_cluster: sleds,
omicron_zones: omicron_zones,
zones_in_service,
parent_blueprint_id: None,
Expand Down Expand Up @@ -145,9 +144,10 @@ impl<'a> BlueprintBuilder<'a> {
/// Assemble a final [`Blueprint`] based on the contents of the builder
pub fn build(mut self) -> Blueprint {
// Collect the Omicron zones config for each in-service sled.
let sleds: BTreeSet<_> = self.policy.sleds.keys().copied().collect();
let omicron_zones = sleds
.iter()
let omicron_zones = self
.policy
.sleds
.keys()
.map(|sled_id| {
// Start with self.omicron_zones, which contains entries for any
// sled whose zones config is changing in this blueprint.
Expand All @@ -174,7 +174,6 @@ impl<'a> BlueprintBuilder<'a> {
.collect();
Blueprint {
id: Uuid::new_v4(),
sleds_in_cluster: sleds,
omicron_zones: omicron_zones,
zones_in_service: self.zones_in_service,
parent_blueprint_id: Some(self.parent_blueprint.id),
Expand Down Expand Up @@ -238,7 +237,7 @@ impl<'a> BlueprintBuilder<'a> {
let ntp_servers = self
.parent_blueprint
.all_omicron_zones()
.filter_map(|z| {
.filter_map(|(_, z)| {
if matches!(z.zone_type, OmicronZoneType::BoundaryNtp { .. }) {
Some(format!("{}.host.{}", z.id, DNS_ZONE))
} else {
Expand Down
Loading

0 comments on commit c39c75d

Please sign in to comment.