Skip to content

Commit

Permalink
Add sled_agent_get to nexus internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Feb 27, 2024
1 parent bedf0c1 commit 7bdf2e3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 13 deletions.
29 changes: 28 additions & 1 deletion nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use crate::schema::{physical_disk, service, sled, zpool};
use crate::{ipv6, SledProvisionState};
use chrono::{DateTime, Utc};
use db_macros::Asset;
use nexus_types::{external_api::shared, external_api::views, identity::Asset};
use nexus_types::{
external_api::{shared, views},
identity::Asset,
internal_api::params,
};
use std::net::Ipv6Addr;
use std::net::SocketAddrV6;
use uuid::Uuid;
Expand Down Expand Up @@ -106,6 +110,29 @@ impl From<Sled> for views::Sled {
}
}

impl From<Sled> for params::SledAgentInfo {
fn from(sled: Sled) -> Self {
let role = if sled.is_scrimlet {
params::SledRole::Scrimlet
} else {
params::SledRole::Gimlet
};
Self {
sa_address: sled.address(),
role,
baseboard: params::Baseboard {
serial_number: sled.serial_number.clone(),
part_number: sled.part_number.clone(),
revision: sled.revision,
},
usable_hardware_threads: sled.usable_hardware_threads.into(),
usable_physical_ram: sled.usable_physical_ram.into(),
reservoir_size: sled.reservoir_size.into(),
generation: sled.rcgen.into(),
}
}
}

impl DatastoreCollectionConfig<super::PhysicalDisk> for Sled {
type CollectionId = Uuid;
type GenerationNumberColumn = sled::dsl::rcgen;
Expand Down
6 changes: 3 additions & 3 deletions nexus/src/app/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! Sleds, and the hardware and services within them.
use crate::internal_api::params::{
PhysicalDiskDeleteRequest, PhysicalDiskPutRequest, SledAgentStartupInfo,
SledRole, ZpoolPutRequest,
PhysicalDiskDeleteRequest, PhysicalDiskPutRequest, SledAgentInfo, SledRole,
ZpoolPutRequest,
};
use nexus_db_queries::authz;
use nexus_db_queries::context::OpContext;
Expand Down Expand Up @@ -43,7 +43,7 @@ impl super::Nexus {
&self,
_opctx: &OpContext,
id: Uuid,
info: SledAgentStartupInfo,
info: SledAgentInfo,
) -> Result<(), Error> {
info!(self.log, "registered sled agent"; "sled_uuid" => id.to_string());

Expand Down
26 changes: 24 additions & 2 deletions nexus/src/internal_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::ServerContext;

use super::params::{
OximeterInfo, PhysicalDiskDeleteRequest, PhysicalDiskPutRequest,
PhysicalDiskPutResponse, RackInitializationRequest, SledAgentStartupInfo,
PhysicalDiskPutResponse, RackInitializationRequest, SledAgentInfo,
ZpoolPutRequest, ZpoolPutResponse,
};
use dropshot::endpoint;
Expand Down Expand Up @@ -56,6 +56,7 @@ type NexusApiDescription = ApiDescription<Arc<ServerContext>>;
/// Returns a description of the internal nexus API
pub(crate) fn internal_api() -> NexusApiDescription {
fn register_endpoints(api: &mut NexusApiDescription) -> Result<(), String> {
api.register(sled_agent_get)?;
api.register(sled_agent_put)?;
api.register(sled_firewall_rules_request)?;
api.register(switch_put)?;
Expand Down Expand Up @@ -104,6 +105,27 @@ struct SledAgentPathParam {
sled_id: Uuid,
}

/// Report that the sled agent for the specified sled has come online.
#[endpoint {
method = GET,
path = "/sled-agents/{sled_id}",
}]
async fn sled_agent_get(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<SledAgentPathParam>,
) -> Result<HttpResponseOk<SledAgentInfo>, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
let path = path_params.into_inner();
let sled_id = &path.sled_id;
let handler = async {
let (.., sled) = nexus.sled_lookup(&opctx, sled_id)?.fetch().await?;
Ok(HttpResponseOk(sled.into()))
};
apictx.internal_latencies.instrument_dropshot_handler(&rqctx, handler).await
}

/// Report that the sled agent for the specified sled has come online.
#[endpoint {
method = POST,
Expand All @@ -112,7 +134,7 @@ struct SledAgentPathParam {
async fn sled_agent_put(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<SledAgentPathParam>,
sled_info: TypedBody<SledAgentStartupInfo>,
sled_info: TypedBody<SledAgentInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
Expand Down
6 changes: 4 additions & 2 deletions nexus/tests/integration_tests/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ use nexus_types::external_api::params;
use nexus_types::external_api::shared::UninitializedSled;
use nexus_types::external_api::views::Rack;
use nexus_types::internal_api::params::Baseboard;
use nexus_types::internal_api::params::SledAgentStartupInfo;
use nexus_types::internal_api::params::SledAgentInfo;
use nexus_types::internal_api::params::SledRole;
use omicron_common::api::external::ByteCount;
use omicron_common::api::external::Generation;
use omicron_nexus::TestInterfaces;
use uuid::Uuid;

Expand Down Expand Up @@ -109,7 +110,7 @@ async fn test_sled_list_uninitialized(cptestctx: &ControlPlaneTestContext) {
// Just pick some random fields other than `baseboard`
let baseboard = uninitialized_sleds.pop().unwrap().baseboard;
let sled_uuid = Uuid::new_v4();
let sa = SledAgentStartupInfo {
let sa = SledAgentInfo {
sa_address: "[fd00:1122:3344:0100::1]:8080".parse().unwrap(),
role: SledRole::Gimlet,
baseboard: Baseboard {
Expand All @@ -120,6 +121,7 @@ async fn test_sled_list_uninitialized(cptestctx: &ControlPlaneTestContext) {
usable_hardware_threads: 32,
usable_physical_ram: ByteCount::from_gibibytes_u32(100),
reservoir_size: ByteCount::from_mebibytes_u32(100),
generation: Generation::new(),
};
internal_client
.make_request(
Expand Down
8 changes: 6 additions & 2 deletions nexus/types/src/internal_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::external_api::params::PhysicalDiskKind;
use crate::external_api::params::UserId;
use crate::external_api::shared::IpRange;
use omicron_common::api::external::ByteCount;
use omicron_common::api::external::Generation;
use omicron_common::api::external::MacAddr;
use omicron_common::api::external::Name;
use omicron_common::api::internal::shared::ExternalPortDiscovery;
Expand Down Expand Up @@ -44,9 +45,9 @@ pub struct Baseboard {
pub revision: i64,
}

/// Sent by a sled agent on startup to Nexus to request further instruction
/// Sent by a sled agent to Nexus to inform about resources
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct SledAgentStartupInfo {
pub struct SledAgentInfo {
/// The address of the sled agent's API endpoint
pub sa_address: SocketAddrV6,

Expand All @@ -66,6 +67,9 @@ pub struct SledAgentStartupInfo {
///
/// Must be smaller than "usable_physical_ram"
pub reservoir_size: ByteCount,

/// The generation number of this request from sled-agent
pub generation: Generation,
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
Expand Down
48 changes: 45 additions & 3 deletions openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,39 @@
}
},
"/sled-agents/{sled_id}": {
"get": {
"summary": "Report that the sled agent for the specified sled has come online.",
"operationId": "sled_agent_get",
"parameters": [
{
"in": "path",
"name": "sled_id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SledAgentInfo"
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
},
"post": {
"summary": "Report that the sled agent for the specified sled has come online.",
"operationId": "sled_agent_put",
Expand All @@ -816,7 +849,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SledAgentStartupInfo"
"$ref": "#/components/schemas/SledAgentInfo"
}
}
},
Expand Down Expand Up @@ -6343,8 +6376,8 @@
"sled_id"
]
},
"SledAgentStartupInfo": {
"description": "Sent by a sled agent on startup to Nexus to request further instruction",
"SledAgentInfo": {
"description": "Sent by a sled agent to Nexus to inform about resources",
"type": "object",
"properties": {
"baseboard": {
Expand All @@ -6355,6 +6388,14 @@
}
]
},
"generation": {
"description": "The generation number of this request from sled-agent",
"allOf": [
{
"$ref": "#/components/schemas/Generation"
}
]
},
"reservoir_size": {
"description": "Amount of RAM dedicated to the VMM reservoir\n\nMust be smaller than \"usable_physical_ram\"",
"allOf": [
Expand Down Expand Up @@ -6392,6 +6433,7 @@
},
"required": [
"baseboard",
"generation",
"reservoir_size",
"role",
"sa_address",
Expand Down

0 comments on commit 7bdf2e3

Please sign in to comment.