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 f513182 commit 9b6882c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 16 deletions.
19 changes: 18 additions & 1 deletion nexus/db-model/src/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use crate::schema::rack;
use db_macros::Asset;
use ipnetwork::IpNetwork;
use ipnetwork::{IpNetwork, Ipv6Network};
use nexus_types::{external_api::views, identity::Asset};
use omicron_common::api;
use uuid::Uuid;

/// Information about a local rack.
Expand All @@ -28,6 +29,22 @@ impl Rack {
rack_subnet: None,
}
}

pub fn get_subnet(&self) -> Result<Ipv6Network, api::external::Error> {
match self.rack_subnet {
Some(IpNetwork::V6(subnet)) => Ok(subnet),
Some(IpNetwork::V4(_)) => {
return Err(api::external::Error::InternalError {
internal_message: "rack subnet not IPv6".into(),
})
}
None => {
return Err(api::external::Error::InternalError {
internal_message: "rack subnet not set".into(),
})
}
}
}
}

impl From<Rack> for views::Rack {
Expand Down
27 changes: 26 additions & 1 deletion nexus/db-queries/src/db/datastore/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,31 @@ impl DataStore {

Ok(())
}

/// Attempt to read the latest collection while limiting queries to `limit`
/// records
pub async fn inventory_get_latest_collection(
&self,
opctx: &OpContext,
limit: NonZeroU32,
) -> Result<Collection, Error> {
opctx.authorize(authz::Action::Read, &authz::INVENTORY).await?;
let conn = self.pool_connection_authorized(opctx).await?;
use db::schema::inv_collection::dsl;
let collection_id = dsl::inv_collection
.select(dsl::id)
.order_by(dsl::time_started.desc())
.limit(1)
.first_async::<Uuid>(&*conn)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))?;

// TODO: Fix me to return a proper error
Ok(self
.inventory_collection_read_all_or_nothing(collection_id, limit)
.await
.unwrap())
}
}

/// Extra interfaces that are not intended (and potentially unsafe) for use in
Expand Down Expand Up @@ -845,7 +870,7 @@ impl DataStoreInventoryTest for DataStore {
let conn = self
.pool_connection_for_tests()
.await
.context("getting connectoin")?;
.context("getting connection")?;
conn.transaction_async(|conn| async move {
conn.batch_execute_async(ALLOW_FULL_TABLE_SCAN_SQL)
.await
Expand Down
28 changes: 14 additions & 14 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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::UninitializedSled;
use nexus_types::internal_api::params::DnsRecord;
use omicron_common::api::external::AddressLotKind;
use omicron_common::api::external::DataPageParams;
Expand Down Expand Up @@ -614,20 +615,7 @@ impl super::Nexus {
opctx: &OpContext,
) -> Result<EarlyNetworkConfig, Error> {
let rack = self.rack_lookup(opctx, &self.rack_id).await?;

let subnet = match rack.rack_subnet {
Some(IpNetwork::V6(subnet)) => subnet,
Some(IpNetwork::V4(_)) => {
return Err(Error::InternalError {
internal_message: "rack subnet not IPv6".into(),
})
}
None => {
return Err(Error::InternalError {
internal_message: "rack subnet not set".into(),
})
}
};
let subnet = rack.get_subnet()?;

let db_ports = self.active_port_settings(opctx).await?;
let mut ports = Vec::new();
Expand Down Expand Up @@ -724,4 +712,16 @@ impl super::Nexus {

Ok(result)
}

async fn unintialized_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
}
}
29 changes: 29 additions & 0 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4382,6 +4382,35 @@ async fn rack_view(
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
}

/// List uninitialized sleds in a given rack
#[endpoint {
method = GET,
path = "/v1/system/hardware/racks/{rack_id}/uninitialized-sleds",
tags = ["system/hardware"]
}]
async fn uninitialized_sled_list(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<RackPathParam>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<UninitializedSled>>, HttpError> {
let apictx = rqctx.context();
let handler = async {
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?;
Ok(HttpResponseOk(sleds))
};
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
}

// Sleds

/// List sleds
Expand Down
6 changes: 6 additions & 0 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ pub struct Rack {
pub identity: AssetIdentityMetadata,
}

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

// FRUs

/// Properties that uniquely identify an Oxide hardware component
Expand Down

0 comments on commit 9b6882c

Please sign in to comment.