manta_server/backend_dispatcher/
mod.rs

1//! `StaticBackendDispatcher` trait implementations.
2//!
3//! [`crate::dispatcher::StaticBackendDispatcher`] is the enum that
4//! wraps a CSM or an OCHAMI backend; the trait impls live here so the
5//! enum stays a pure data type and the routing logic lives next door
6//! to the imports it needs. Each backend trait from
7//! `manta-backend-dispatcher::interfaces::*` gets its own sibling file
8//! under this module.
9//!
10//! # Structure
11//!
12//! Sibling files do `use super::*;` to pick up the shared trait,
13//! type, and macro imports defined here, so an individual impl file
14//! only needs to declare the `impl` block. The `dispatch!` macro
15//! is textually scoped: it's visible to every `mod` declaration that
16//! follows it in this file.
17//!
18//! # Why every trait needs an explicit forward
19//!
20//! Some traits in `manta-backend-dispatcher` ship a default
21//! "not implemented" body for each method. If a trait isn't
22//! explicitly implemented here, every method call falls through to
23//! that default — silently returning "not implemented" even when the
24//! underlying CSM or OCHAMI backend would have handled it. The
25//! `apply_sat_image_create_session` regression was exactly this
26//! shape, so the rule is: any trait a handler reaches through must
27//! have a sibling file under this module, even if the body is a
28//! straight `dispatch!` forward.
29
30use std::collections::HashMap;
31use std::pin::Pin;
32
33use chrono::NaiveDateTime;
34use futures::AsyncBufRead;
35use serde_json::Value;
36
37use manta_backend_dispatcher::error::Error;
38use manta_backend_dispatcher::interfaces::apply_hw_cluster_pin::ApplyHwClusterPin;
39use manta_backend_dispatcher::interfaces::apply_sat_file::{
40  ApplyConfigurationParams, ApplyImageCreateSessionParams, ApplyImageParams,
41  ApplyImageStampParams, ApplySatFileParams, ApplySessionTemplateParams,
42  SatTrait, ValidateSatFileParams,
43};
44use manta_backend_dispatcher::interfaces::apply_session::ApplySessionTrait;
45use manta_backend_dispatcher::interfaces::authentication::AuthenticationTrait;
46use manta_backend_dispatcher::interfaces::bos::{
47  ClusterSessionTrait, ClusterTemplateTrait,
48};
49use manta_backend_dispatcher::interfaces::bss::BootParametersTrait;
50use manta_backend_dispatcher::interfaces::cfs::CfsTrait;
51use manta_backend_dispatcher::interfaces::console::ConsoleTrait;
52use manta_backend_dispatcher::interfaces::delete_configurations_and_data_related::DeleteConfigurationsAndDataRelatedTrait;
53use manta_backend_dispatcher::interfaces::hsm::component::ComponentTrait;
54use manta_backend_dispatcher::interfaces::hsm::group::GroupTrait;
55use manta_backend_dispatcher::interfaces::hsm::hardware_inventory::HardwareInventory;
56use manta_backend_dispatcher::interfaces::hsm::redfish_endpoint::RedfishEndpointTrait;
57use manta_backend_dispatcher::interfaces::ims::{
58  GetImagesAndDetailsTrait, ImsTrait,
59};
60use manta_backend_dispatcher::interfaces::migrate_backup::MigrateBackupTrait;
61use manta_backend_dispatcher::interfaces::migrate_restore::MigrateRestoreTrait;
62use manta_backend_dispatcher::interfaces::pcs::PCSTrait;
63use manta_backend_dispatcher::types::{
64  self, Component, ComponentArrayPostArray, Group, HWInventory,
65  HWInventoryByLocationList, HsmActionResponse, K8sDetails, NodeMetadataArray,
66  NodeSummary,
67};
68use manta_backend_dispatcher::types::bos::session::BosSession;
69use manta_backend_dispatcher::types::bos::session_template::BosSessionTemplate;
70use manta_backend_dispatcher::types::bss::BootParameters;
71use manta_backend_dispatcher::types::cfs::cfs_configuration_details::LayerDetails;
72use manta_backend_dispatcher::types::cfs::cfs_configuration_request::CfsConfigurationRequest;
73use manta_backend_dispatcher::types::cfs::cfs_configuration_response::{
74  CfsConfigurationResponse, Layer,
75};
76use manta_backend_dispatcher::types::cfs::component::Component as CfsComponent;
77use manta_backend_dispatcher::types::cfs::session::{
78  CfsSessionGetResponse, CfsSessionPostRequest,
79};
80use manta_backend_dispatcher::types::hsm::inventory::{
81  RedfishEndpoint, RedfishEndpointArray,
82};
83use manta_backend_dispatcher::types::ims::{Image, PatchImage};
84use manta_backend_dispatcher::types::pcs::transitions::types::{
85  TransitionResponse, TransitionStartOutput,
86};
87
88use crate::dispatcher::StaticBackendDispatcher;
89use StaticBackendDispatcher::*;
90
91/// Dispatches a method call to the underlying backend variant.
92///
93/// Both `CSM` and `OCHAMI` variants always delegate to the same
94/// method on the wrapped client with identical arguments, so this
95/// macro eliminates the repetitive `match self` boilerplate found in
96/// every trait impl in this module.
97///
98/// # Usage
99///
100/// ```ignore
101/// // async method (default):
102/// dispatch!(self, method_name, arg1, arg2)
103/// // sync method:
104/// dispatch!(sync self, method_name, arg1)
105/// ```
106///
107/// The async form expands to a `match self` whose arms call the named
108/// method and `.await` the result; the `sync` form omits the
109/// `.await`. The macro is intentionally minimal — when CSM and OCHAMI
110/// diverge in their method names or arguments, write a manual
111/// `match self` body instead.
112macro_rules! dispatch {
113  // async (default): adds `.await` after the call
114  ($self:ident, $method:ident $(, $arg:expr)*) => {
115    match $self {
116      CSM(b) => b.$method($($arg),*).await,
117      OCHAMI(b) => b.$method($($arg),*).await,
118    }
119  };
120  // sync: no `.await`
121  (sync $self:ident, $method:ident $(, $arg:expr)*) => {
122    match $self {
123      CSM(b) => b.$method($($arg),*),
124      OCHAMI(b) => b.$method($($arg),*),
125    }
126  };
127}
128
129mod apply_hw_cluster_pin;
130mod apply_session;
131mod authentication;
132mod boot_parameters;
133mod cfs;
134mod cluster_session;
135mod cluster_template;
136mod component;
137mod component_ethernet_interface;
138mod console;
139mod delete_configurations;
140mod get_images;
141mod group;
142mod hardware_inventory;
143mod ims;
144mod migrate_backup;
145mod migrate_restore;
146mod pcs;
147mod redfish_endpoint;
148mod sat;