Skip to content

Commit b062e95

Browse files
authored
[MGS] Add "component clear status" endpoint (#2286)
This is currently only useful with the `monorail` component of a sidecar's SP, for which it resets the packet counters for each port.
1 parent b231a80 commit b062e95

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

gateway-cli/src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ async fn main() -> Result<()> {
435435
.into_inner();
436436
dumper.dump(&info)?;
437437
}
438-
Command::ComponentClearStatus { .. } => {
439-
todo!("missing MGS endpoint");
438+
Command::ComponentClearStatus { sp, component } => {
439+
client
440+
.sp_component_clear_status(sp.type_, sp.slot, &component)
441+
.await?;
440442
}
441443
Command::UsartAttach {
442444
sp,

gateway/src/http_entrypoints.rs

+23
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,28 @@ async fn sp_component_get(
621621
Ok(HttpResponseOk(details.entries.into_iter().map(Into::into).collect()))
622622
}
623623

624+
/// Clear status of a component
625+
///
626+
/// For components that maintain event counters (e.g., the sidecar `monorail`),
627+
/// this will reset the event counters to zero.
628+
#[endpoint {
629+
method = POST,
630+
path = "/sp/{type}/{slot}/component/{component}/clear-status",
631+
}]
632+
async fn sp_component_clear_status(
633+
rqctx: RequestContext<Arc<ServerContext>>,
634+
path: Path<PathSpComponent>,
635+
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
636+
let apictx = rqctx.context();
637+
let PathSpComponent { sp, component } = path.into_inner();
638+
let sp = apictx.mgmt_switch.sp(sp.into())?;
639+
let component = component_from_str(&component)?;
640+
641+
sp.component_clear_status(component).await.map_err(SpCommsError::from)?;
642+
643+
Ok(HttpResponseUpdatedNoContent {})
644+
}
645+
624646
/// Get the currently-active slot for an SP component
625647
///
626648
/// Note that the meaning of "current" in "currently-active" may vary depending
@@ -1052,6 +1074,7 @@ pub fn api() -> GatewayApiDescription {
10521074
api.register(sp_power_state_set)?;
10531075
api.register(sp_component_list)?;
10541076
api.register(sp_component_get)?;
1077+
api.register(sp_component_clear_status)?;
10551078
api.register(sp_component_active_slot_get)?;
10561079
api.register(sp_component_active_slot_set)?;
10571080
api.register(sp_component_serial_console_attach)?;

openapi/gateway.json

+47
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,53 @@
452452
}
453453
}
454454
},
455+
"/sp/{type}/{slot}/component/{component}/clear-status": {
456+
"post": {
457+
"summary": "Clear status of a component",
458+
"description": "For components that maintain event counters (e.g., the sidecar `monorail`), this will reset the event counters to zero.",
459+
"operationId": "sp_component_clear_status",
460+
"parameters": [
461+
{
462+
"in": "path",
463+
"name": "component",
464+
"description": "ID for the component of the SP; this is the internal identifier used by the SP itself to identify its components.",
465+
"required": true,
466+
"schema": {
467+
"type": "string"
468+
}
469+
},
470+
{
471+
"in": "path",
472+
"name": "slot",
473+
"required": true,
474+
"schema": {
475+
"type": "integer",
476+
"format": "uint32",
477+
"minimum": 0
478+
}
479+
},
480+
{
481+
"in": "path",
482+
"name": "type",
483+
"required": true,
484+
"schema": {
485+
"$ref": "#/components/schemas/SpType"
486+
}
487+
}
488+
],
489+
"responses": {
490+
"204": {
491+
"description": "resource updated"
492+
},
493+
"4XX": {
494+
"$ref": "#/components/responses/Error"
495+
},
496+
"5XX": {
497+
"$ref": "#/components/responses/Error"
498+
}
499+
}
500+
}
501+
},
455502
"/sp/{type}/{slot}/component/{component}/serial-console/attach": {
456503
"get": {
457504
"summary": "Upgrade into a websocket connection attached to the given SP component's",

0 commit comments

Comments
 (0)