manta_shared/types/api/
hw_cluster.rs

1//! HTTP request/response bodies and shared types for the
2//! `POST /api/v1/hardware-clusters/{target}/*` and
3//! `DELETE /api/v1/hardware-clusters/{target}/members` endpoints.
4
5use serde::{Deserialize, Serialize};
6use utoipa::ToSchema;
7
8/// Request body for `POST /api/v1/hardware-clusters/{target}/members`.
9///
10/// Moves nodes matching `pattern` out of `parent_cluster` and into
11/// the path-level target cluster. The reverse direction lives in
12/// [`DeleteHwComponentRequest`]; both operations are also expressible
13/// in unified form via [`ApplyHwConfigurationRequest`] with
14/// [`HwClusterMode::Pin`] vs [`HwClusterMode::Unpin`].
15#[derive(Debug, Serialize, Deserialize, ToSchema)]
16pub struct AddHwComponentRequest {
17  /// Source HSM group that donates nodes matching `pattern`.
18  pub parent_cluster: String,
19  /// Hardware component pattern used to select which nodes to move.
20  pub pattern: String,
21  /// Create the target HSM group if it does not already exist.
22  #[serde(default)]
23  pub create_hsm_group: bool,
24  /// When true, return the planned changes without modifying group
25  /// membership.
26  #[serde(default)]
27  pub dry_run: bool,
28}
29
30/// Request body for `DELETE /api/v1/hardware-clusters/{target}/members`.
31///
32/// Reverse of [`AddHwComponentRequest`]: moves nodes matching
33/// `pattern` out of the path-level target cluster and back to
34/// `parent_cluster`.
35#[derive(Debug, Serialize, Deserialize, ToSchema)]
36pub struct DeleteHwComponentRequest {
37  /// Destination HSM group that receives nodes moved out of the
38  /// target cluster.
39  pub parent_cluster: String,
40  /// Hardware component pattern used to select which nodes to move
41  /// back.
42  pub pattern: String,
43  /// Delete the target HSM group if it becomes empty after the
44  /// operation.
45  #[serde(default)]
46  pub delete_hsm_group: bool,
47  /// When true, return the planned changes without modifying group
48  /// membership.
49  #[serde(default)]
50  pub dry_run: bool,
51}
52
53/// Request body for
54/// `POST /api/v1/hardware-clusters/{target}/configuration`.
55#[derive(Debug, Serialize, Deserialize, ToSchema)]
56pub struct ApplyHwConfigurationRequest {
57  /// Source (parent) HSM group supplying nodes.
58  pub parent_cluster: String,
59  /// Hardware component pattern selecting which nodes to pin/unpin.
60  pub pattern: String,
61  /// Whether to pin nodes into the target cluster or unpin them back
62  /// to the parent. Defaults to `Pin`.
63  #[serde(default)]
64  pub mode: HwClusterMode,
65  /// Create the target HSM group if absent (default `true`).
66  #[serde(default = "default_true")]
67  pub create_target_hsm_group: bool,
68  /// Delete the parent HSM group if it becomes empty (default `true`).
69  #[serde(default = "default_true")]
70  pub delete_empty_parent_hsm_group: bool,
71  /// When true, return the planned changes without modifying group
72  /// membership.
73  #[serde(default)]
74  pub dry_run: bool,
75}
76
77fn default_true() -> bool {
78  true
79}
80
81/// Whether the hw cluster operation moves nodes into the target (Pin) or
82/// releases them back (Unpin).
83#[derive(
84  Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, ToSchema,
85)]
86#[serde(rename_all = "lowercase")]
87pub enum HwClusterMode {
88  /// Move nodes matching the hardware pattern from the parent cluster
89  /// into the target cluster.
90  #[default]
91  Pin,
92  /// Move nodes matching the hardware pattern from the target cluster
93  /// back to the parent cluster.
94  Unpin,
95}