Skip to content

Commit 668f1a2

Browse files
bnaeckerNieuwejaar
authored andcommitted
Remove option when fetching a transceiver (#1109)
* Remove option when fetching a transceiver - Return a `Transceiver`, rather than an `Option` of one, when fetching a single transceiver in the `dpd` API. If there is no transceiver, return a 404. - Fixes #1107 * Fixup cloned call
1 parent 7b7abe2 commit 668f1a2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

dpd/src/api_server.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ async fn transceivers_list(
12101210
async fn transceiver_get(
12111211
rqctx: RequestContext<Arc<Switch>>,
12121212
path: Path<PortIdPathParams>,
1213-
) -> Result<HttpResponseOk<Option<Transceiver>>, HttpError> {
1213+
) -> Result<HttpResponseOk<Transceiver>, HttpError> {
12141214
let switch = rqctx.context();
12151215
let port_id = path.into_inner().port_id;
12161216
match switch.switch_ports.ports.get(&port_id).as_ref() {
@@ -1219,7 +1219,19 @@ async fn transceiver_get(
12191219
let switch_port = sp.lock().await;
12201220
match &switch_port.fixed_side {
12211221
FixedSideDevice::Qsfp { device, .. } => {
1222-
Ok(HttpResponseOk(device.transceiver.clone()))
1222+
match device.transceiver.as_ref().cloned() {
1223+
Some(tr) => Ok(HttpResponseOk(tr)),
1224+
None => {
1225+
let PortId::Qsfp(qsfp_port) = port_id else {
1226+
let msg = format!(
1227+
"Expected port {port_id} to be a QSFP port!"
1228+
);
1229+
return Err(HttpError::for_internal_error(msg));
1230+
};
1231+
Err(DpdError::MissingTransceiver { qsfp_port }
1232+
.into())
1233+
}
1234+
}
12231235
}
12241236
_ => Err(DpdError::NotAQsfpPort { port_id }.into()),
12251237
}

0 commit comments

Comments
 (0)