From d5d7678d4a08b0a5fc6964a562f4627d6aa40310 Mon Sep 17 00:00:00 2001 From: "Andrew J. Stone" Date: Thu, 16 Nov 2023 04:39:12 +0000 Subject: [PATCH] wip --- nexus/src/app/rack.rs | 20 ++---- nexus/src/external_api/http_entrypoints.rs | 6 +- nexus/tests/integration_tests/endpoints.rs | 4 +- nexus/tests/output/nexus_tags.txt | 2 +- openapi/nexus.json | 74 +++++++++------------- 5 files changed, 40 insertions(+), 66 deletions(-) diff --git a/nexus/src/app/rack.rs b/nexus/src/app/rack.rs index 1e85b04c6d2..aefe57dd0c5 100644 --- a/nexus/src/app/rack.rs +++ b/nexus/src/app/rack.rs @@ -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 { // Grab the SPs from the last collection let limit = NonZeroU32::new(50).unwrap(); @@ -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 = collection .sps .into_iter() @@ -759,17 +756,8 @@ impl super::Nexus { }) .collect(); - let sled_baseboards: BTreeSet = 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 = + 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)); diff --git a/nexus/src/external_api/http_entrypoints.rs b/nexus/src/external_api/http_entrypoints.rs index 99cd6dba28e..428632bcf5b 100644 --- a/nexus/src/external_api/http_entrypoints.rs +++ b/nexus/src/external_api/http_entrypoints.rs @@ -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>, - path_params: Path, ) -> Result>, 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 diff --git a/nexus/tests/integration_tests/endpoints.rs b/nexus/tests/integration_tests/endpoints.rs index 69a51641364..64790c49c20 100644 --- a/nexus/tests/integration_tests/endpoints.rs +++ b/nexus/tests/integration_tests/endpoints.rs @@ -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 = @@ -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], }, diff --git a/nexus/tests/output/nexus_tags.txt b/nexus/tests/output/nexus_tags.txt index a876e6080fe..7f0c30c471f 100644 --- a/nexus/tests/output/nexus_tags.txt +++ b/nexus/tests/output/nexus_tags.txt @@ -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 diff --git a/openapi/nexus.json b/openapi/nexus.json index 6fba0f3824d..e508670eb35 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -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": [ @@ -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": [