manta_server/service/
power.rs

1//! Power on/off/reset operations against PCS.
2
3use manta_backend_dispatcher::error::Error;
4use manta_backend_dispatcher::interfaces::pcs::PCSTrait;
5use manta_backend_dispatcher::types::pcs::transitions::types::TransitionResponse;
6
7use crate::server::common::app_context::InfraContext;
8pub use manta_shared::shared::params::power::{ApplyPowerParams, PowerAction};
9
10/// Dispatch the requested power action to the backend PCS trait.
11///
12/// `force` is ignored for [`PowerAction::On`] (the backend trait has no
13/// `force` parameter for the on transition).
14pub async fn apply_power(
15  infra: &InfraContext<'_>,
16  token: &str,
17  params: &ApplyPowerParams,
18) -> Result<TransitionResponse, Error> {
19  match params.action {
20    PowerAction::On => infra.backend.power_on_sync(token, &params.xnames).await,
21    PowerAction::Off => {
22      infra
23        .backend
24        .power_off_sync(token, &params.xnames, params.force)
25        .await
26    }
27    PowerAction::Reset => {
28      infra
29        .backend
30        .power_reset_sync(token, &params.xnames, params.force)
31        .await
32    }
33  }
34}