manta_shared/types/api/template.rs
1//! HTTP request/response bodies and CLI-built parameter structs for
2//! the BOS session template endpoints (`/api/v1/templates`,
3//! `/api/v1/templates/{name}/sessions`).
4
5use serde::{Deserialize, Serialize};
6use utoipa::ToSchema;
7
8/// BOS session operation to run against the template's node list.
9#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
10#[serde(rename_all = "lowercase")]
11pub enum BosOperation {
12 /// Boot nodes that are currently off.
13 Boot,
14 /// Reboot (power-cycle) nodes.
15 Reboot,
16 /// Shut down nodes.
17 Shutdown,
18}
19
20impl BosOperation {
21 /// Wire-level string form expected by the backend (`"boot"` /
22 /// `"reboot"` / `"shutdown"`).
23 pub fn as_str(&self) -> &'static str {
24 match self {
25 Self::Boot => "boot",
26 Self::Reboot => "reboot",
27 Self::Shutdown => "shutdown",
28 }
29 }
30}
31
32/// Request body for `POST /api/v1/templates/{name}/sessions`.
33///
34/// Creates a BOS session from an existing session template (the
35/// `{name}` path segment).
36///
37/// # Wire shape
38///
39/// ```json
40/// {
41/// "operation": "reboot",
42/// "limit": "x3000c0s1b0n[0-3]",
43/// "session_name": null,
44/// "include_disabled": false,
45/// "dry_run": false
46/// }
47/// ```
48#[derive(Debug, Serialize, Deserialize, ToSchema)]
49pub struct PostTemplateSessionRequest {
50 /// BOS operation to run (boot, reboot, or shutdown).
51 pub operation: BosOperation,
52 /// Ansible limit expression restricting which template nodes are
53 /// targeted.
54 pub limit: String,
55 /// Optional explicit name for the BOS session; auto-generated when
56 /// absent.
57 pub session_name: Option<String>,
58 /// When true, include nodes marked as disabled.
59 #[serde(default)]
60 pub include_disabled: bool,
61 /// When true, validate the session parameters without creating a
62 /// BOS session.
63 #[serde(default)]
64 pub dry_run: bool,
65}
66
67/// Typed parameters for fetching BOS session templates.
68pub struct GetTemplateParams {
69 /// Exact template name.
70 pub name: Option<String>,
71 /// Group whose associated templates should be returned.
72 pub group_name: Option<String>,
73 /// Operator default from `cli.toml`'s `hsm_group`, used
74 /// as a fallback for `group_name`.
75 pub settings_group_name: Option<String>,
76 /// Cap on the number of templates returned (most recent first).
77 pub limit: Option<u8>,
78}
79
80impl GetTemplateParams {
81 /// Returns the effective group name, preferring the explicit
82 /// `--group` flag and falling back to the operator default from
83 /// `cli.toml`.
84 pub fn effective_group(&self) -> Option<&str> {
85 self
86 .group_name
87 .as_deref()
88 .or(self.settings_group_name.as_deref())
89 }
90}
91
92/// Parameters for applying a BOS session template.
93pub struct ApplyTemplateParams {
94 /// Optional explicit name for the created BOS session;
95 /// auto-generated when absent.
96 pub bos_session_name: Option<String>,
97 /// Name of an existing BOS session template to instantiate.
98 pub bos_sessiontemplate_name: String,
99 /// Operation to perform: `"boot"`, `"reboot"`, or `"shutdown"`.
100 pub bos_session_operation: String,
101 /// Ansible-style limit expression scoping which template nodes
102 /// are targeted (xnames, NIDs, groups, or roles).
103 pub limit: String,
104 /// When true, include nodes marked as disabled in the hardware
105 /// state manager.
106 pub include_disabled: bool,
107}