manta_shared/types/api/
kernel_parameters.rs

1//! HTTP request/response bodies and CLI-built parameter structs for
2//! the kernel-parameter endpoints (`/api/v1/kernel-parameters/*`).
3//!
4//! The internal `KernelParamOperation` enum used by the server's
5//! kernel-parameter orchestration is not exposed here — it lives in
6//! `crate::service::kernel_parameters` because it carries operational
7//! logic (mutate, handles_sbps_images) rather than wire data.
8
9use serde::{Deserialize, Serialize};
10use utoipa::ToSchema;
11
12/// Which kernel-parameter mutation to perform on
13/// `POST /api/v1/kernel-parameters/apply`.
14#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
15#[serde(rename_all = "lowercase")]
16pub enum KernelParamOp {
17  /// Merge new parameters into the existing set.
18  Add,
19  /// Replace the entire parameter set.
20  Apply,
21  /// Remove the named parameters from the existing set.
22  Delete,
23}
24
25/// Request body for `POST /api/v1/kernel-parameters/apply`.
26///
27/// One of `xnames_expression` or `hsm_group` must be set (not both).
28/// The chosen [`KernelParamOp`] determines what `params` means:
29/// merge-keys, replace-set, or remove-set.
30///
31/// # Wire shape
32///
33/// ```json
34/// {
35///   "xnames_expression": "x3000c0s1b0n[0-3]",
36///   "hsm_group": null,
37///   "operation": "add",
38///   "params": "console=ttyS0 nosmt",
39///   "overwrite": false,
40///   "project_sbps": true,
41///   "dry_run": false
42/// }
43/// ```
44#[derive(Debug, Serialize, Deserialize, ToSchema)]
45pub struct ApplyKernelParametersRequest {
46  /// Hosts expression (xnames, NIDs, or hostlist notation); mutually
47  /// exclusive with `hsm_group`.
48  pub xnames_expression: Option<String>,
49  /// Target HSM group; all members are resolved to xnames.
50  pub hsm_group: Option<String>,
51  /// Which mutation to perform: add, apply (replace), or delete.
52  pub operation: KernelParamOp,
53  /// Space-separated kernel parameter `key=value` pairs.
54  pub params: String,
55  /// Only relevant for the `Add` operation.
56  #[serde(default)]
57  pub overwrite: bool,
58  /// Whether to project SBPS images (default `true`).
59  #[serde(default = "default_true")]
60  pub project_sbps: bool,
61  /// When true, return the computed changeset without applying it.
62  #[serde(default)]
63  pub dry_run: bool,
64}
65
66/// Request body for `POST /api/v1/kernel-parameters/add` (append mode).
67#[derive(Debug, Serialize, Deserialize, ToSchema)]
68pub struct AddKernelParametersRequest {
69  /// Space-separated kernel parameter `key=value` pairs to add.
70  pub params: String,
71  /// Hosts expression (xnames, NIDs, or hostlist notation); mutually
72  /// exclusive with `hsm_group`.
73  pub xnames_expression: Option<String>,
74  /// Target HSM group; all members are resolved to xnames.
75  pub hsm_group: Option<String>,
76  /// When true, overwrite parameters that already exist.
77  #[serde(default)]
78  pub overwrite: bool,
79  /// Whether to project SBPS images (default `true`).
80  #[serde(default = "default_true")]
81  pub project_sbps: bool,
82  /// When true, return the computed changeset without applying it.
83  #[serde(default)]
84  pub dry_run: bool,
85}
86
87/// Request body for `DELETE /api/v1/kernel-parameters`.
88#[derive(Debug, Serialize, Deserialize, ToSchema)]
89pub struct DeleteKernelParametersRequest {
90  /// Space-separated parameter names (or `key=value` pairs) to
91  /// remove.
92  pub params: String,
93  /// Hosts expression (xnames, NIDs, or hostlist notation); mutually
94  /// exclusive with `hsm_group`.
95  pub xnames_expression: Option<String>,
96  /// Target HSM group; all members are resolved to xnames.
97  pub hsm_group: Option<String>,
98  /// When true, return the computed changeset without applying it.
99  #[serde(default)]
100  pub dry_run: bool,
101}
102
103fn default_true() -> bool {
104  true
105}
106
107/// Typed parameters for fetching kernel boot parameters.
108///
109/// Precedence: `nodes` > `group_name` > `settings_group_name`.
110/// At least one must resolve to a non-empty value.
111pub struct GetKernelParametersParams {
112  /// Group whose members' kernel parameters should be returned.
113  pub group_name: Option<String>,
114  /// Explicit comma-separated xnames; mutually exclusive with
115  /// `group_name`.
116  pub nodes: Option<String>,
117  /// Operator default from `cli.toml`'s `parent_group_group`, used
118  /// when neither `group_name` nor `nodes` is supplied.
119  pub settings_group_name: Option<String>,
120}
121
122impl GetKernelParametersParams {
123  /// Returns the effective group name, preferring the explicit
124  /// `--group` flag and falling back to the operator default from
125  /// `cli.toml`.
126  pub fn effective_group(&self) -> Option<&str> {
127    self
128      .group_name
129      .as_deref()
130      .or(self.settings_group_name.as_deref())
131  }
132}