Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Nov 15, 2023
1 parent 9b6882c commit dd4c3fc
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 21 deletions.
61 changes: 56 additions & 5 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::external_api::params;
use crate::external_api::params::CertificateCreate;
use crate::external_api::shared::ServiceUsingCertificate;
use crate::internal_api::params::RackInitializationRequest;
use gateway_client::types::SpType;
use ipnetwork::IpNetwork;
use nexus_db_model::DnsGroup;
use nexus_db_model::InitialDnsGroup;
Expand All @@ -31,6 +32,8 @@ use nexus_types::external_api::params::{
use nexus_types::external_api::shared::FleetRole;
use nexus_types::external_api::shared::SiloIdentityMode;
use nexus_types::external_api::shared::SiloRole;
use nexus_types::external_api::views;
use nexus_types::external_api::views::Baseboard;
use nexus_types::external_api::views::UninitializedSled;
use nexus_types::internal_api::params::DnsRecord;
use omicron_common::api::external::AddressLotKind;
Expand All @@ -52,6 +55,7 @@ use std::collections::BTreeSet;
use std::collections::HashMap;
use std::net::IpAddr;
use std::net::Ipv4Addr;
use std::num::NonZeroU32;
use std::str::FromStr;
use uuid::Uuid;

Expand Down Expand Up @@ -713,15 +717,62 @@ impl super::Nexus {
Ok(result)
}

async fn unintialized_sled_list(
/// Return the list of sleds that are inserted into a given initialized rack
/// but not yet initialized as part of that rack.
pub(crate) async fn uninitialized_sled_list(
&self,
opctx: &OpContext,
rack_id: Uuid,
pagparams: &DataPageParams<'_, Uuid>,
) -> ListResultVec<UninitializedSled> {
//let rack = self.rack_lookup(opctx, &self.rack_id).await?;
//let subnet = rack.get_subnet()?;

// Grab the SPs from the last collection
let limit = NonZeroU32::new(50).unwrap();
let collection = self
.db_datastore
.inventory_get_latest_collection(opctx, limit)
.await?;
let pagparams = DataPageParams {
marker: None,
direction: dropshot::PaginationOrder::Descending,
// TODO: This limit is only suitable for a single sled cluster
limit: NonZeroU32::new(32).unwrap(),
};
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()
.filter_map(|(k, v)| {
if v.sp_type == SpType::Sled {
Some(UninitializedSled {
baseboard: Baseboard {
serial: k.serial_number.clone(),
part: k.part_number.clone(),
revision: v.baseboard_revision.into(),
},
cubby: v.sp_slot,
})
} else {
None
}
})
.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();

// Retain all sleds that exist but are not in the sled table
uninitialized_sleds.retain(|s| !sled_baseboards.contains(&s.baseboard));
Ok(uninitialized_sleds)
}
}
19 changes: 6 additions & 13 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use super::{
console_api, device_auth, params,
views::{
self, Certificate, Group, IdentityProvider, Image, IpPool, IpPoolRange,
PhysicalDisk, Project, Rack, Role, Silo, Sled, Snapshot, SshKey, User,
UserBuiltin, Vpc, VpcRouter, VpcSubnet,
PhysicalDisk, Project, Rack, Role, Silo, Sled, Snapshot, SshKey,
UninitializedSled, User, UserBuiltin, Vpc, VpcRouter, VpcSubnet,
},
};
use crate::external_api::shared;
Expand Down Expand Up @@ -222,6 +222,7 @@ pub(crate) fn external_api() -> NexusApiDescription {
api.register(physical_disk_list)?;
api.register(switch_list)?;
api.register(switch_view)?;
api.register(uninitialized_sled_list)?;

api.register(user_builtin_list)?;
api.register(user_builtin_view)?;
Expand Down Expand Up @@ -4391,21 +4392,13 @@ async fn rack_view(
async fn uninitialized_sled_list(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<RackPathParam>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<UninitializedSled>>, HttpError> {
) -> Result<HttpResponseOk<Vec<UninitializedSled>>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = apictx.nexus;
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let query = query_params.into_inner();
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
let sleds = nexus
.uninitialized_sled_list(
&opctx,
&path.rack_id,
&data_page_params_for(&rqctx, &query)?,
)
.await?;
let sleds = nexus.uninitialized_sled_list(&opctx, path.rack_id).await?;
Ok(HttpResponseOk(sleds))
};
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
Expand Down
27 changes: 24 additions & 3 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,36 @@ pub struct Rack {
}

/// View of a sled that has not been added to an initialized rack yet
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[derive(
Clone,
Debug,
Serialize,
Deserialize,
JsonSchema,
PartialOrd,
Ord,
PartialEq,
Eq,
)]
pub struct UninitializedSled {
baseboard: Baseboard,
pub baseboard: Baseboard,
pub cubby: u16,
}

// FRUs

/// Properties that uniquely identify an Oxide hardware component
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[derive(
Clone,
Debug,
Serialize,
Deserialize,
JsonSchema,
PartialOrd,
Ord,
PartialEq,
Eq,
)]
pub struct Baseboard {
pub serial: String,
pub part: String,
Expand Down

0 comments on commit dd4c3fc

Please sign in to comment.