Skip to content

Commit

Permalink
List all uninitialized sleds
Browse files Browse the repository at this point in the history
As part of adding a sled to an already initialized rack, we need a way
for operators to be able to list sleds that are not part of a rack. This
PR adds an external nexus endpoint for doing just that. Like the `sleds`
endpoint, this endpoint is not tied to a rack.

The way this works is by looking at the SPs in the latest inventory
collection and finding all the Baseboards that are not in the `sled`
table in CRDB.

A follow up commit will allow an operator to add uninitialized sleds to
a rack with a new external nexus endpoint.
  • Loading branch information
andrewjstone committed Nov 16, 2023
1 parent f513182 commit 621a7a3
Show file tree
Hide file tree
Showing 9 changed files with 508 additions and 320 deletions.
18 changes: 13 additions & 5 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use nexus_db_model::Zpool;
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db;
use nexus_db_queries::db::datastore::DataStoreConnection;
use nexus_db_queries::db::datastore::DataStoreInventoryTest;
use nexus_db_queries::db::datastore::InstanceAndActiveVmm;
use nexus_db_queries::db::identity::Asset;
use nexus_db_queries::db::lookup::LookupPath;
Expand Down Expand Up @@ -383,8 +382,13 @@ impl DbArgs {
.await
}
DbCommands::Inventory(inventory_args) => {
cmd_db_inventory(&datastore, self.fetch_limit, inventory_args)
.await
cmd_db_inventory(
&opctx,
&datastore,
self.fetch_limit,
inventory_args,
)
.await
}
DbCommands::Services(ServicesArgs {
command: ServicesCommands::ListInstances,
Expand Down Expand Up @@ -1751,6 +1755,7 @@ fn format_record(record: &DnsRecord) -> impl Display {
// Inventory

async fn cmd_db_inventory(
opctx: &OpContext,
datastore: &DataStore,
limit: NonZeroU32,
inventory_args: &InventoryArgs,
Expand All @@ -1768,7 +1773,9 @@ async fn cmd_db_inventory(
}) => cmd_db_inventory_collections_list(&conn, limit).await,
InventoryCommands::Collections(CollectionsArgs {
command: CollectionsCommands::Show(CollectionsShowArgs { id }),
}) => cmd_db_inventory_collections_show(datastore, id, limit).await,
}) => {
cmd_db_inventory_collections_show(opctx, datastore, id, limit).await
}
}
}

Expand Down Expand Up @@ -1928,12 +1935,13 @@ async fn cmd_db_inventory_collections_list(
}

async fn cmd_db_inventory_collections_show(
opctx: &OpContext,
datastore: &DataStore,
id: Uuid,
limit: NonZeroU32,
) -> Result<(), anyhow::Error> {
let (collection, incomplete) = datastore
.inventory_collection_read_best_effort(id, limit)
.inventory_collection_read_best_effort(opctx, id, limit)
.await
.context("reading collection")?;
if incomplete {
Expand Down
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
Loading

0 comments on commit 621a7a3

Please sign in to comment.