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;
36use tokio::io::{AsyncRead, AsyncWrite};
37
38use manta_backend_dispatcher::error::Error;
39use manta_backend_dispatcher::interfaces::apply_hw_cluster_pin::ApplyHwClusterPin;
40use manta_backend_dispatcher::interfaces::apply_sat_file::{
41  ApplyConfigurationParams, ApplyImageCreateSessionParams, ApplyImageParams,
42  ApplyImageStampParams, ApplySatFileParams, ApplySessionTemplateParams,
43  SatTrait,
44};
45use manta_backend_dispatcher::interfaces::apply_session::ApplySessionTrait;
46use manta_backend_dispatcher::interfaces::authentication::AuthenticationTrait;
47use manta_backend_dispatcher::interfaces::bos::{
48  ClusterSessionTrait, ClusterTemplateTrait,
49};
50use manta_backend_dispatcher::interfaces::bss::BootParametersTrait;
51use manta_backend_dispatcher::interfaces::cfs::CfsTrait;
52use manta_backend_dispatcher::interfaces::console::ConsoleTrait;
53use manta_backend_dispatcher::interfaces::delete_configurations_and_data_related::DeleteConfigurationsAndDataRelatedTrait;
54use manta_backend_dispatcher::interfaces::hsm::component::ComponentTrait;
55use manta_backend_dispatcher::interfaces::hsm::group::GroupTrait;
56use manta_backend_dispatcher::interfaces::hsm::hardware_inventory::HardwareInventory;
57use manta_backend_dispatcher::interfaces::hsm::redfish_endpoint::RedfishEndpointTrait;
58use manta_backend_dispatcher::interfaces::ims::{
59  GetImagesAndDetailsTrait, ImsTrait,
60};
61use manta_backend_dispatcher::interfaces::migrate_backup::MigrateBackupTrait;
62use manta_backend_dispatcher::interfaces::migrate_restore::MigrateRestoreTrait;
63use manta_backend_dispatcher::interfaces::pcs::PCSTrait;
64use manta_backend_dispatcher::types::{
65  self, Component, ComponentArrayPostArray, Group, HWInventory,
66  HWInventoryByLocationList, HsmActionResponse, K8sDetails, NodeMetadataArray,
67  NodeSummary,
68};
69use manta_backend_dispatcher::types::bos::session::BosSession;
70use manta_backend_dispatcher::types::bos::session_template::BosSessionTemplate;
71use manta_backend_dispatcher::types::bss::BootParameters;
72use manta_backend_dispatcher::types::cfs::cfs_configuration_details::LayerDetails;
73use manta_backend_dispatcher::types::cfs::cfs_configuration_request::CfsConfigurationRequest;
74use manta_backend_dispatcher::types::cfs::cfs_configuration_response::{
75  CfsConfigurationResponse, Layer,
76};
77use manta_backend_dispatcher::types::cfs::component::Component as CfsComponent;
78use manta_backend_dispatcher::types::cfs::session::{
79  CfsSessionGetResponse, CfsSessionPostRequest,
80};
81use manta_backend_dispatcher::types::hsm::inventory::{
82  RedfishEndpoint, RedfishEndpointArray,
83};
84use manta_backend_dispatcher::types::ims::{Image, PatchImage};
85use manta_backend_dispatcher::types::pcs::transitions::types::{
86  TransitionResponse, TransitionStartOutput,
87};
88
89use crate::dispatcher::StaticBackendDispatcher;
90use StaticBackendDispatcher::*;
91
92/// Dispatches a method call to the underlying backend variant.
93///
94/// Both `CSM` and `OCHAMI` variants always delegate to the same
95/// method on the wrapped client with identical arguments, so this
96/// macro eliminates the repetitive `match self` boilerplate found in
97/// every trait impl in this module.
98///
99/// # Usage
100///
101/// ```ignore
102/// // async method (default):
103/// dispatch!(self, method_name, arg1, arg2)
104/// // sync method:
105/// dispatch!(sync self, method_name, arg1)
106/// ```
107///
108/// The async form expands to a `match self` whose arms call the named
109/// method and `.await` the result; the `sync` form omits the
110/// `.await`. The macro is intentionally minimal — when CSM and OCHAMI
111/// diverge in their method names or arguments, write a manual
112/// `match self` body instead.
113macro_rules! dispatch {
114  // async (default): adds `.await` after the call
115  ($self:ident, $method:ident $(, $arg:expr)*) => {
116    match $self {
117      CSM(b) => b.$method($($arg),*).await,
118      OCHAMI(b) => b.$method($($arg),*).await,
119    }
120  };
121  // sync: no `.await`
122  (sync $self:ident, $method:ident $(, $arg:expr)*) => {
123    match $self {
124      CSM(b) => b.$method($($arg),*),
125      OCHAMI(b) => b.$method($($arg),*),
126    }
127  };
128}
129
130mod apply_hw_cluster_pin;
131mod apply_session;
132mod authentication;
133mod boot_parameters;
134mod cfs;
135mod cluster_session;
136mod cluster_template;
137mod component;
138mod component_ethernet_interface;
139mod console;
140mod delete_configurations;
141mod get_images;
142mod group;
143mod hardware_inventory;
144mod ims;
145mod migrate_backup;
146mod migrate_restore;
147mod pcs;
148mod redfish_endpoint;
149mod sat;