Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Nov 16, 2023
1 parent 3055d51 commit d5d7678
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 66 deletions.
20 changes: 4 additions & 16 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,11 @@ impl super::Nexus {
Ok(result)
}

/// Return the list of sleds that are inserted into a given initialized rack
/// but not yet initialized as part of that rack.
/// Return the list of sleds that are inserted into an initialized rack
/// but not yet initialized as part of a rack.
pub(crate) async fn uninitialized_sled_list(
&self,
opctx: &OpContext,
rack_id: Uuid,
) -> ListResultVec<UninitializedSled> {
// Grab the SPs from the last collection
let limit = NonZeroU32::new(50).unwrap();
Expand All @@ -738,8 +737,6 @@ impl super::Nexus {
};
let sleds = self.db_datastore.sled_list(opctx, &pagparams).await?;

// TODO-correctness: There is no mechanism for filtering based on rack_id
// in the current inventory collections.
let mut uninitialized_sleds: Vec<UninitializedSled> = collection
.sps
.into_iter()
Expand All @@ -759,17 +756,8 @@ impl super::Nexus {
})
.collect();

let sled_baseboards: BTreeSet<Baseboard> = sleds
.into_iter()
.filter_map(|s| {
let sled = views::Sled::from(s);
if sled.rack_id == rack_id {
Some(sled.baseboard)
} else {
None
}
})
.collect();
let sled_baseboards: BTreeSet<Baseboard> =
sleds.into_iter().map(|s| views::Sled::from(s).baseboard).collect();

// Retain all sleds that exist but are not in the sled table
uninitialized_sleds.retain(|s| !sled_baseboards.contains(&s.baseboard));
Expand Down
6 changes: 2 additions & 4 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4386,19 +4386,17 @@ async fn rack_view(
/// List uninitialized sleds in a given rack
#[endpoint {
method = GET,
path = "/v1/system/hardware/racks/{rack_id}/uninitialized-sleds",
path = "/v1/system/hardware/uninitialized-sleds",
tags = ["system/hardware"]
}]
async fn uninitialized_sled_list(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<RackPathParam>,
) -> Result<HttpResponseOk<Vec<UninitializedSled>>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
let sleds = nexus.uninitialized_sled_list(&opctx, path.rack_id).await?;
let sleds = nexus.uninitialized_sled_list(&opctx).await?;
Ok(HttpResponseOk(sleds))
};
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
Expand Down
4 changes: 2 additions & 2 deletions nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ lazy_static! {
pub static ref HARDWARE_RACK_URL: String =
format!("/v1/system/hardware/racks/{}", RACK_UUID);
pub static ref HARDWARE_UNINITIALIZED_SLEDS: String =
format!("{}/uninitialized-sleds", *HARDWARE_RACK_URL);
format!("/v1/system/hardware/uninitialized-sleds");
pub static ref HARDWARE_SLED_URL: String =
format!("/v1/system/hardware/sleds/{}", SLED_AGENT_UUID);
pub static ref HARDWARE_SWITCH_URL: String =
Expand Down Expand Up @@ -1568,7 +1568,7 @@ lazy_static! {

VerifyEndpoint {
url: &HARDWARE_UNINITIALIZED_SLEDS,
visibility: Visibility::Protected,
visibility: Visibility::Public,
unprivileged_access: UnprivilegedAccess::None,
allowed_methods: vec![AllowedMethod::Get],
},
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 @@ -122,7 +122,7 @@ sled_physical_disk_list GET /v1/system/hardware/sleds/{sle
sled_view GET /v1/system/hardware/sleds/{sled_id}
switch_list GET /v1/system/hardware/switches
switch_view GET /v1/system/hardware/switches/{switch_id}
uninitialized_sled_list GET /v1/system/hardware/racks/{rack_id}/uninitialized-sleds
uninitialized_sled_list GET /v1/system/hardware/uninitialized-sleds

API operations found with tag "system/metrics"
OPERATION ID METHOD URL PATH
Expand Down
74 changes: 31 additions & 43 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -3553,49 +3553,6 @@
}
}
},
"/v1/system/hardware/racks/{rack_id}/uninitialized-sleds": {
"get": {
"tags": [
"system/hardware"
],
"summary": "List uninitialized sleds in a given rack",
"operationId": "uninitialized_sled_list",
"parameters": [
{
"in": "path",
"name": "rack_id",
"description": "The rack's unique ID.",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"title": "Array_of_UninitializedSled",
"type": "array",
"items": {
"$ref": "#/components/schemas/UninitializedSled"
}
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/v1/system/hardware/sleds": {
"get": {
"tags": [
Expand Down Expand Up @@ -4107,6 +4064,37 @@
}
}
},
"/v1/system/hardware/uninitialized-sleds": {
"get": {
"tags": [
"system/hardware"
],
"summary": "List uninitialized sleds in a given rack",
"operationId": "uninitialized_sled_list",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"title": "Array_of_UninitializedSled",
"type": "array",
"items": {
"$ref": "#/components/schemas/UninitializedSled"
}
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/v1/system/identity-providers": {
"get": {
"tags": [
Expand Down

0 comments on commit d5d7678

Please sign in to comment.