manta_server/backend_dispatcher/pcs.rs
1//! [`PCSTrait`] (power control) impl for [`StaticBackendDispatcher`].
2//!
3//! Forwards to the CSM PCS (Power Control Service)
4//! `/apis/power-control/v1/{power-status,transitions}` endpoints.
5//! Both CSM and Ochami implement this trait natively.
6//!
7//! `POST /transitions` returns immediately with a transition id (via
8//! [`pcs_transitions_post`](StaticBackendDispatcher::pcs_transitions_post));
9//! the CLI then polls
10//! [`pcs_transitions_get`](StaticBackendDispatcher::pcs_transitions_get)
11//! until the transition is `completed`. The older blocking
12//! `power_*_sync` trait methods (server-side polling loop) have been
13//! removed.
14
15use manta_backend_dispatcher::types::pcs::power_status::types::PowerStatusAll;
16
17use super::*;
18
19impl PCSTrait for StaticBackendDispatcher {
20 /// `GET /power-status?xname=...` — current power state for each
21 /// `nodes` entry. `power_status_filter` and `management_state_filter`
22 /// map to the upstream `powerStatusFilter` / `managementStateFilter`
23 /// query parameters.
24 async fn power_status(
25 &self,
26 auth_token: &str,
27 nodes: &[String],
28 power_status_filter: Option<&str>,
29 management_state_filter: Option<&str>,
30 ) -> Result<PowerStatusAll, Error> {
31 dispatch!(
32 self,
33 power_status,
34 auth_token,
35 nodes,
36 power_status_filter,
37 management_state_filter
38 )
39 }
40
41 /// `POST /transitions` — start a power `operation` (e.g. `on`,
42 /// `off`, `soft-restart`) against `nodes`. Returns the transition
43 /// id; the caller polls
44 /// [`pcs_transitions_get`](Self::pcs_transitions_get) for the
45 /// outcome.
46 async fn pcs_transitions_post(
47 &self,
48 auth_token: &str,
49 operation: &str,
50 nodes: &[String],
51 ) -> Result<TransitionStartOutput, Error> {
52 // Same trait-vs-inherent name clash as `pcs_transitions_get`:
53 // disambiguate explicitly.
54 match self {
55 Self::CSM(b) => {
56 PCSTrait::pcs_transitions_post(b, auth_token, operation, nodes).await
57 }
58 Self::OCHAMI(b) => {
59 PCSTrait::pcs_transitions_post(b, auth_token, operation, nodes).await
60 }
61 }
62 }
63
64 /// `GET /transitions/{id}` — single transition's progress / final
65 /// status. Polled by the CLI to drive the power-op wait loop.
66 async fn pcs_transitions_get(
67 &self,
68 auth_token: &str,
69 transition_id: &str,
70 ) -> Result<TransitionResponse, Error> {
71 // ShastaClient has an inherent `pcs_transitions_get` that takes
72 // only the token and returns a Vec. Disambiguate via the trait so
73 // the resolver picks the trait method (single transition by id),
74 // not the inherent one.
75 match self {
76 Self::CSM(b) => {
77 PCSTrait::pcs_transitions_get(b, auth_token, transition_id).await
78 }
79 Self::OCHAMI(b) => {
80 PCSTrait::pcs_transitions_get(b, auth_token, transition_id).await
81 }
82 }
83 }
84}