Skip to content

Commit

Permalink
[MGS] Add "component clear status" endpoint (#2286)
Browse files Browse the repository at this point in the history
This is currently only useful with the `monorail` component of a
sidecar's SP, for which it resets the packet counters for each port.
  • Loading branch information
jgallagher authored Feb 2, 2023
1 parent b231a80 commit b062e95
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gateway-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,10 @@ async fn main() -> Result<()> {
.into_inner();
dumper.dump(&info)?;
}
Command::ComponentClearStatus { .. } => {
todo!("missing MGS endpoint");
Command::ComponentClearStatus { sp, component } => {
client
.sp_component_clear_status(sp.type_, sp.slot, &component)
.await?;
}
Command::UsartAttach {
sp,
Expand Down
23 changes: 23 additions & 0 deletions gateway/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,28 @@ async fn sp_component_get(
Ok(HttpResponseOk(details.entries.into_iter().map(Into::into).collect()))
}

/// Clear status of a component
///
/// For components that maintain event counters (e.g., the sidecar `monorail`),
/// this will reset the event counters to zero.
#[endpoint {
method = POST,
path = "/sp/{type}/{slot}/component/{component}/clear-status",
}]
async fn sp_component_clear_status(
rqctx: RequestContext<Arc<ServerContext>>,
path: Path<PathSpComponent>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = rqctx.context();
let PathSpComponent { sp, component } = path.into_inner();
let sp = apictx.mgmt_switch.sp(sp.into())?;
let component = component_from_str(&component)?;

sp.component_clear_status(component).await.map_err(SpCommsError::from)?;

Ok(HttpResponseUpdatedNoContent {})
}

/// Get the currently-active slot for an SP component
///
/// Note that the meaning of "current" in "currently-active" may vary depending
Expand Down Expand Up @@ -1052,6 +1074,7 @@ pub fn api() -> GatewayApiDescription {
api.register(sp_power_state_set)?;
api.register(sp_component_list)?;
api.register(sp_component_get)?;
api.register(sp_component_clear_status)?;
api.register(sp_component_active_slot_get)?;
api.register(sp_component_active_slot_set)?;
api.register(sp_component_serial_console_attach)?;
Expand Down
47 changes: 47 additions & 0 deletions openapi/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,53 @@
}
}
},
"/sp/{type}/{slot}/component/{component}/clear-status": {
"post": {
"summary": "Clear status of a component",
"description": "For components that maintain event counters (e.g., the sidecar `monorail`), this will reset the event counters to zero.",
"operationId": "sp_component_clear_status",
"parameters": [
{
"in": "path",
"name": "component",
"description": "ID for the component of the SP; this is the internal identifier used by the SP itself to identify its components.",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "path",
"name": "slot",
"required": true,
"schema": {
"type": "integer",
"format": "uint32",
"minimum": 0
}
},
{
"in": "path",
"name": "type",
"required": true,
"schema": {
"$ref": "#/components/schemas/SpType"
}
}
],
"responses": {
"204": {
"description": "resource updated"
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/sp/{type}/{slot}/component/{component}/serial-console/attach": {
"get": {
"summary": "Upgrade into a websocket connection attached to the given SP component's",
Expand Down

0 comments on commit b062e95

Please sign in to comment.