manta_shared/types/api/power.rs
1//! HTTP request/response bodies and CLI-built parameter structs for
2//! the power endpoints (`/api/v1/power`).
3
4use serde::{Deserialize, Serialize};
5use utoipa::ToSchema;
6
7/// Request body for `POST /api/v1/power`.
8///
9/// The interpretation of `host_expression` depends on [`PowerTargetType`];
10/// the action itself is one of [`PowerAction`]'s variants.
11///
12/// # Wire shape
13///
14/// ```json
15/// {
16/// "action": "on",
17/// "host_expression": "x3000c0s1b0n[0-3]",
18/// "target_type": "nodes",
19/// "force": false
20/// }
21/// ```
22#[derive(Debug, Serialize, Deserialize, ToSchema)]
23pub struct PowerRequest {
24 /// Power operation to perform.
25 pub action: PowerAction,
26 /// For `Nodes`: hosts expression (xnames, NIDs, or hostlist
27 /// notation). For `Cluster`: the HSM group name.
28 pub host_expression: String,
29 /// Whether `host_expression` is a node expression or a cluster
30 /// name.
31 pub target_type: PowerTargetType,
32 /// Pass `--force` to the underlying power operation (forceful
33 /// shutdown/reset).
34 #[serde(default)]
35 pub force: bool,
36}
37
38/// The power operation to apply to a list of xnames.
39#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
40#[serde(rename_all = "lowercase")]
41pub enum PowerAction {
42 /// Power on (cold start) the listed xnames.
43 On,
44 /// Power off the listed xnames; graceful unless `force` is set.
45 Off,
46 /// Power-cycle (reset) the listed xnames; graceful unless `force`
47 /// is set.
48 Reset,
49}
50
51/// Whether the caller's `host_expression` is a hosts expression
52/// (xnames / NIDs / hostlist) or a single HSM group name whose
53/// members should be targeted.
54#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
55#[serde(rename_all = "lowercase")]
56pub enum PowerTargetType {
57 /// `host_expression` is a hosts expression.
58 Nodes,
59 /// `host_expression` is a single HSM group name.
60 Cluster,
61}
62
63/// Typed parameters for the power-action service call.
64pub struct ApplyPowerParams {
65 /// Power operation to perform on every entry in `xnames`.
66 pub action: PowerAction,
67 /// Resolved list of xnames (already expanded from any HSM-group
68 /// or hostlist expression by the caller).
69 pub xnames: Vec<String>,
70 /// When true, perform a hard power off / reset without the
71 /// graceful shutdown path.
72 pub force: bool,
73}