Skip to content

Commit

Permalink
Rename API to sled_add and take Baseboard as param
Browse files Browse the repository at this point in the history
This is the second half of the fix for #4607
  • Loading branch information
andrewjstone committed Dec 15, 2023
1 parent 0937a89 commit 7caa858
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 38 deletions.
28 changes: 13 additions & 15 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,33 +933,33 @@ impl super::Nexus {
}

/// Add a sled to an intialized rack
pub(crate) async fn add_sled_to_initialized_rack(
pub(crate) async fn sled_add(
&self,
opctx: &OpContext,
sled: UninitializedSled,
sled: Baseboard,
) -> Result<(), Error> {
let baseboard_id = sled.baseboard.clone().into();
let baseboard_id = sled.clone().into();
let hw_baseboard_id =
self.db_datastore.find_hw_baseboard_id(opctx, baseboard_id).await?;

let subnet = self.db_datastore.rack_subnet(opctx, sled.rack_id).await?;
let subnet = self.db_datastore.rack_subnet(opctx, self.rack_id).await?;
let rack_subnet =
Ipv6Subnet::<RACK_PREFIX>::from(rack_subnet(Some(subnet))?);

let allocation = self
.db_datastore
.allocate_sled_underlay_subnet_octets(
opctx,
sled.rack_id,
self.rack_id,
hw_baseboard_id,
)
.await?;

// Convert the baseboard as necessary
let baseboard = sled_agent_client::types::Baseboard::Gimlet {
identifier: sled.baseboard.serial.clone(),
model: sled.baseboard.part.clone(),
revision: sled.baseboard.revision,
identifier: sled.serial.clone(),
model: sled.part.clone(),
revision: sled.revision,
};

// Make the call to sled-agent
Expand All @@ -985,13 +985,11 @@ impl super::Nexus {
},
};
let sa = self.get_any_sled_agent(opctx).await?;
sa.add_sled_to_initialized_rack(&req).await.map_err(|e| {
Error::InternalError {
internal_message: format!(
"failed to add sled with baseboard {:?} to rack {}: {e}",
sled.baseboard, allocation.rack_id
),
}
sa.sled_add(&req).await.map_err(|e| Error::InternalError {
internal_message: format!(
"failed to add sled with baseboard {:?} to rack {}: {e}",
sled, allocation.rack_id
),
})?;

Ok(())
Expand Down
12 changes: 7 additions & 5 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ use nexus_db_queries::db::model::Name;
use nexus_db_queries::{
authz::ApiResource, db::fixed_data::silo::INTERNAL_SILO_ID,
};
use nexus_types::external_api::{params::ProjectSelector, views::SiloQuotas};
use nexus_types::external_api::{
params::ProjectSelector, shared::Baseboard, views::SiloQuotas,
};
use nexus_types::{
external_api::views::{SledInstance, Switch},
identity::AssetIdentityMetadata,
Expand Down Expand Up @@ -229,7 +231,7 @@ pub(crate) fn external_api() -> NexusApiDescription {
api.register(switch_list)?;
api.register(switch_view)?;
api.register(sled_list_uninitialized)?;
api.register(add_sled_to_initialized_rack)?;
api.register(sled_add)?;

api.register(user_builtin_list)?;
api.register(user_builtin_view)?;
Expand Down Expand Up @@ -4597,15 +4599,15 @@ async fn sled_list_uninitialized(
path = "/v1/system/hardware/sleds/",
tags = ["system/hardware"]
}]
async fn add_sled_to_initialized_rack(
async fn sled_add(
rqctx: RequestContext<Arc<ServerContext>>,
sled: TypedBody<UninitializedSled>,
sled: TypedBody<Baseboard>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
let handler = async {
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
nexus.add_sled_to_initialized_rack(&opctx, sled.into_inner()).await?;
nexus.sled_add(&opctx, sled.into_inner()).await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
Expand Down
14 changes: 4 additions & 10 deletions nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use nexus_types::external_api::shared;
use nexus_types::external_api::shared::Baseboard;
use nexus_types::external_api::shared::IpRange;
use nexus_types::external_api::shared::Ipv4Range;
use nexus_types::external_api::shared::UninitializedSled;
use omicron_common::api::external::AddressLotKind;
use omicron_common::api::external::ByteCount;
use omicron_common::api::external::IdentityMetadataCreateParams;
Expand All @@ -41,7 +40,6 @@ use omicron_test_utils::certificates::CertificateChain;
use std::net::IpAddr;
use std::net::Ipv4Addr;
use std::str::FromStr;
use uuid::Uuid;

lazy_static! {
pub static ref HARDWARE_RACK_URL: String =
Expand All @@ -66,14 +64,10 @@ lazy_static! {
pub static ref SLED_INSTANCES_URL: String =
format!("/v1/system/hardware/sleds/{}/instances", SLED_AGENT_UUID);

pub static ref DEMO_UNINITIALIZED_SLED: UninitializedSled = UninitializedSled {
baseboard: Baseboard {
serial: "demo-serial".to_string(),
part: "demo-part".to_string(),
revision: 6
},
rack_id: Uuid::new_v4(),
cubby: 1
pub static ref DEMO_UNINITIALIZED_SLED: Baseboard = Baseboard {
serial: "demo-serial".to_string(),
part: "demo-part".to_string(),
revision: 6
};

// Global policy
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ snapshot_view GET /v1/snapshots/{snapshot}

API operations found with tag "system/hardware"
OPERATION ID METHOD URL PATH
add_sled_to_initialized_rack POST /v1/system/hardware/sleds
networking_switch_port_apply_settings POST /v1/system/hardware/switch-port/{port}/settings
networking_switch_port_clear_settings DELETE /v1/system/hardware/switch-port/{port}/settings
networking_switch_port_list GET /v1/system/hardware/switch-port
physical_disk_list GET /v1/system/hardware/disks
rack_list GET /v1/system/hardware/racks
rack_view GET /v1/system/hardware/racks/{rack_id}
sled_add POST /v1/system/hardware/sleds
sled_instance_list GET /v1/system/hardware/sleds/{sled_id}/instances
sled_list GET /v1/system/hardware/sleds
sled_list_uninitialized GET /v1/system/hardware/uninitialized-sleds
Expand Down
4 changes: 2 additions & 2 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -3765,12 +3765,12 @@
"system/hardware"
],
"summary": "Add a sled to an initialized rack",
"operationId": "add_sled_to_initialized_rack",
"operationId": "sled_add",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UninitializedSled"
"$ref": "#/components/schemas/Baseboard"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@
"/sleds": {
"put": {
"summary": "Add a sled to a rack that was already initialized via RSS",
"operationId": "add_sled_to_initialized_rack",
"operationId": "sled_add",
"requestBody": {
"content": {
"application/json": {
Expand Down
6 changes: 3 additions & 3 deletions sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn api() -> SledApiDescription {
api.register(uplink_ensure)?;
api.register(read_network_bootstore_config_cache)?;
api.register(write_network_bootstore_config)?;
api.register(add_sled_to_initialized_rack)?;
api.register(sled_add)?;
api.register(metrics_collect)?;
api.register(host_os_write_start)?;
api.register(host_os_write_status_get)?;
Expand Down Expand Up @@ -713,7 +713,7 @@ async fn write_network_bootstore_config(
method = PUT,
path = "/sleds"
}]
async fn add_sled_to_initialized_rack(
async fn sled_add(
rqctx: RequestContext<SledAgent>,
body: TypedBody<AddSledRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
Expand All @@ -731,7 +731,7 @@ async fn add_sled_to_initialized_rack(
));
}

crate::sled_agent::add_sled_to_initialized_rack(
crate::sled_agent::sled_add(
sa.logger().clone(),
request.sled_id,
request.start_request,
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ pub enum AddSledError {
}

/// Add a sled to an initialized rack.
pub async fn add_sled_to_initialized_rack(
pub async fn sled_add(
log: Logger,
sled_id: Baseboard,
request: StartSledAgentRequest,
Expand Down

0 comments on commit 7caa858

Please sign in to comment.