Skip to content

Commit

Permalink
remove one XXX
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Jan 11, 2024
1 parent a2abb97 commit f0b0451
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 28 deletions.
13 changes: 13 additions & 0 deletions common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ impl ReservedRackSubnet {
}
}

/// Return the list of DNS servers for the rack, given any address in the AZ
/// subnet
pub fn get_internal_dns_server_addresses(addr: Ipv6Addr) -> Vec<IpAddr> {
let az_subnet = Ipv6Subnet::<AZ_PREFIX>::new(addr);
let reserved_rack_subnet = ReservedRackSubnet::new(az_subnet);
let dns_subnets =
&reserved_rack_subnet.get_dns_subnets()[0..DNS_REDUNDANCY];
dns_subnets
.iter()
.map(|dns_subnet| IpAddr::from(dns_subnet.dns_address().ip()))
.collect()
}

const SLED_AGENT_ADDRESS_INDEX: usize = 1;
const SWITCH_ZONE_ADDRESS_INDEX: usize = 2;

Expand Down
53 changes: 47 additions & 6 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ enum BlueprintsCommands {
/// Delete a blueprint
Delete(BlueprintIdArgs),
/// Set the current target blueprint
SetTarget(BlueprintIdArgs),
Target(BlueprintsTargetArgs),
/// Generate an initial blueprint from the current state
GenerateCurrent,
/// Generate a new blueprint
Expand All @@ -86,6 +86,20 @@ struct BlueprintIdArgs {
blueprint_id: Uuid,
}

#[derive(Debug, Args)]
struct BlueprintsTargetArgs {
#[command(subcommand)]
command: BlueprintTargetCommands,
}

#[derive(Debug, Subcommand)]
enum BlueprintTargetCommands {
/// Show the current target blueprint
Show,
/// Change the current target blueprint
Set(BlueprintIdArgs),
}

impl NexusArgs {
/// Run a `omdb nexus` subcommand.
pub(crate) async fn run_cmd(
Expand Down Expand Up @@ -136,8 +150,17 @@ impl NexusArgs {
command: BlueprintsCommands::Delete(args),
}) => cmd_nexus_blueprints_delete(&client, args).await,
NexusCommands::Blueprints(BlueprintsArgs {
command: BlueprintsCommands::SetTarget(args),
}) => cmd_nexus_blueprints_set_target(&client, args).await,
command:
BlueprintsCommands::Target(BlueprintsTargetArgs {
command: BlueprintTargetCommands::Show,
}),
}) => cmd_nexus_blueprints_target_show(&client).await,
NexusCommands::Blueprints(BlueprintsArgs {
command:
BlueprintsCommands::Target(BlueprintsTargetArgs {
command: BlueprintTargetCommands::Set(args),
}),
}) => cmd_nexus_blueprints_target_set(&client, args).await,
NexusCommands::Blueprints(BlueprintsArgs {
command: BlueprintsCommands::Regenerate,
}) => cmd_nexus_blueprints_regenerate(&client).await,
Expand Down Expand Up @@ -804,15 +827,33 @@ async fn cmd_nexus_blueprints_delete(
// XXX-dap diff blueprint against latest inventory
// XXX-dap diff blueprint against another blueprint

async fn cmd_nexus_blueprints_set_target(
async fn cmd_nexus_blueprints_target_show(
client: &nexus_client::Client,
) -> Result<(), anyhow::Error> {
let target = client
.blueprint_target_view()
.await
.context("fetching target blueprint")?;
println!("target blueprint: {}", target.target_id);
println!("set at: {}", target.time_set);
println!("enabled: {}", target.enabled);
Ok(())
}

async fn cmd_nexus_blueprints_target_set(
client: &nexus_client::Client,
args: &BlueprintIdArgs,
) -> Result<(), anyhow::Error> {
// Try to preserve the value of "enabled", if possible.
let enabled = client
.blueprint_target_view()
.await
.map(|current| current.into_inner().enabled)
.unwrap_or(true);
client
.blueprint_target_set(&nexus_client::types::BlueprintTargetSet {
target_id: args.blueprint_id,
// XXX-dap ideally keep existing value
enabled: true,
enabled,
})
.await
.with_context(|| {
Expand Down
20 changes: 3 additions & 17 deletions nexus/deployment/src/blueprint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ use nexus_types::deployment::Policy;
use nexus_types::deployment::SledResources;
use nexus_types::deployment::ZpoolName;
use nexus_types::inventory::Collection;
use omicron_common::address::get_internal_dns_server_addresses;
use omicron_common::address::get_sled_address;
use omicron_common::address::get_switch_zone_address;
use omicron_common::address::Ipv6Subnet;
use omicron_common::address::ReservedRackSubnet;
use omicron_common::address::AZ_PREFIX;
use omicron_common::address::CP_SERVICES_RESERVED_ADDRESSES;
use omicron_common::address::DNS_REDUNDANCY;
use omicron_common::address::NTP_PORT;
use omicron_common::address::SLED_RESERVED_ADDRESSES;
use omicron_common::api::external::Generation;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::net::IpAddr;
use std::net::Ipv6Addr;
use std::net::SocketAddrV6;
use thiserror::Error;
Expand Down Expand Up @@ -232,18 +228,8 @@ impl<'a> BlueprintBuilder<'a> {
// actually deployed. Instead, we take the same approach as RSS:
// these are at known, fixed addresses relative to the AZ subnet
// (which itself is a known-prefix parent subnet of the sled subnet).
// XXX-dap commonize with RSS?
let dns_servers: Vec<IpAddr> = {
let az_subnet =
Ipv6Subnet::<AZ_PREFIX>::new(sled_subnet.net().network());
let reserved_rack_subnet = ReservedRackSubnet::new(az_subnet);
let dns_subnets =
&reserved_rack_subnet.get_dns_subnets()[0..DNS_REDUNDANCY];
dns_subnets
.iter()
.map(|dns_subnet| IpAddr::from(dns_subnet.dns_address().ip()))
.collect()
};
let dns_servers =
get_internal_dns_server_addresses(sled_subnet.net().network());

// The list of boundary NTP servers is not necessarily stored
// anywhere (unless there happens to be another internal NTP zone
Expand Down
4 changes: 2 additions & 2 deletions nexus/types/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub mod views {
/// This should generally be left enabled.
pub enabled: bool,
/// when this blueprint was made the target
pub set_at: chrono::DateTime<chrono::Utc>,
pub time_set: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Error)]
Expand All @@ -205,7 +205,7 @@ pub mod views {
Ok(BlueprintTarget {
target_id: value.target_id.ok_or(NoTargetBlueprint)?,
enabled: value.enabled,
set_at: value.time_set,
time_set: value.time_set,
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@
"description": "policy: should the system actively work towards this blueprint\n\nThis should generally be left enabled.",
"type": "boolean"
},
"set_at": {
"time_set": {
"description": "when this blueprint was made the target",
"type": "string",
"format": "date-time"
Expand All @@ -2166,7 +2166,7 @@
},
"required": [
"enabled",
"set_at",
"time_set",
"target_id"
]
},
Expand Down Expand Up @@ -6559,4 +6559,4 @@
}
}
}
}
}

0 comments on commit f0b0451

Please sign in to comment.