Skip to content

[nexus] add slot number to external API sled responses - #11077

Open
hawkw wants to merge 3 commits into
mainfrom
eliza/sled-location
Open

[nexus] add slot number to external API sled responses#11077
hawkw wants to merge 3 commits into
mainfrom
eliza/sled-location

Conversation

@hawkw

@hawkw hawkw commented Aug 12, 2026

Copy link
Copy Markdown
Member

As described in #11048, it would be nice if the public API /system/hardware inventory endpoints included the physical location of the inventoried baseboards. This PR adds that to the sled APIs, by consulting the inventory to look up the latest location for the sled baseboard's SP, if one exists. The returned slot number is nullable, as the inventory may not include an entry for the SP.

The code here is a bit tortured, because gluing together something from the inventory onto a DB query requires constructing the new API models pretty close to the actual HTTP API, rather than in nexus-db-models in a From conversion. I think this is probably not the worst thing, but it's a bit gross.

Fixes #11075

@hawkw hawkw added this to the 23 milestone Aug 12, 2026
@hawkw
hawkw requested review from jgallagher and smklein August 12, 2026 22:07
@hawkw hawkw added api Related to the API. fault-management Everything related to the fault-management initiative (RFD480 and others) labels Aug 12, 2026
Comment thread nexus/src/app/sled.rs Outdated
part_number: sled.part_number.clone(),
};
let sp = inv.sps.get(&bbid)?;
Some(sp.sp_slot as u8)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pretty strongly dislike as casts for their silent failure modes. I strongly suspect sp_slot being a u16 is the fault of 4-years-ago-me, but given that's what we're using, is there a reason not to use u16 over u8 for the sled slot too? Both allow plenty of "should be invalid today" values, but not having to convert seems nice.

If we really want to use u8, are we sure enough about that that this could be u8::try_from(sp.sp_slot).expect("...") to change the "silent failure mode" into "loud failure mode"?

Comment thread nexus/db-model/src/sled.rs Outdated
revision: SqlU32,
pub serial_number: String,
pub part_number: String,
pub revision: SqlU32,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to make all these fields pub is kind of a bummer. Not sure this is a good idea but thinking out loud about how we've handled this other places: could we keep these private if we hang a method off of Sled to do the conversion that's currently in db_sled_to_external, and let it take an extra arg (either the slot or the whole inventory) to fill in the missing info?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah, I think making the conversion a method on the db::model::Sled type is probably the nicer thing. I don't love having it take the slot as an argument because I didn't really want to permit you to construct a sled with any arbitrary slot --- ideally, the entire thing that does the SP slot lookup and constructing the external_api::Sled would be encapsulated. But I suppose it could just take the entire inventory reference, even though that feels a bit goofy.

},
"slot": {
"nullable": true,
"description": "The physical slot in the rack where this sled is currently located, or null if its location is not known at this time.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a turbo nit but I'm tempted to say this should say something like "was most recently located" or "was most recently observed" instead of "is currently located" as a nod toward the fact that inventory is always stale.

@hawkw
hawkw requested a review from jgallagher August 13, 2026 22:14
@hawkw

hawkw commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@jgallagher thanks for the review, I pretty much agree with all your suggestions. I think 602180c addresses everything?

"type": "integer",
"format": "uint16",
"minimum": 0
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can’t argue with that. API APPROVED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the API. fault-management Everything related to the fault-management initiative (RFD480 and others)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add sled slot to /system/hardware/sleds APIs

3 participants