manta_server/service/
redfish_endpoints.rs

1//! Redfish endpoint CRUD operations (BMC registration and discovery management).
2
3use manta_backend_dispatcher::error::Error;
4use manta_backend_dispatcher::interfaces::hsm::redfish_endpoint::RedfishEndpointTrait;
5use manta_backend_dispatcher::types::hsm::inventory::{
6  RedfishEndpoint, RedfishEndpointArray,
7};
8
9use crate::server::common::app_context::InfraContext;
10pub use manta_shared::shared::params::redfish_endpoints::{
11  GetRedfishEndpointsParams, UpdateRedfishEndpointParams,
12};
13
14/// Fetch Redfish endpoint registrations from the backend.
15pub async fn get_redfish_endpoints(
16  infra: &InfraContext<'_>,
17  token: &str,
18  params: &GetRedfishEndpointsParams,
19) -> Result<RedfishEndpointArray, Error> {
20  tracing::info!("Get Redfish endpoints");
21
22  let result = infra
23    .backend
24    .get_redfish_endpoints(
25      token,
26      params.id.as_deref(),
27      params.fqdn.as_deref(),
28      None,
29      params.uuid.as_deref(),
30      params.macaddr.as_deref(),
31      params.ipaddress.as_deref(),
32      None,
33    )
34    .await?;
35
36  Ok(result)
37}
38
39/// Delete a Redfish endpoint registration by ID.
40pub async fn delete_redfish_endpoint(
41  infra: &InfraContext<'_>,
42  token: &str,
43  id: &str,
44) -> Result<(), Error> {
45  infra
46    .backend
47    .delete_redfish_endpoint(token, id)
48    .await
49    .map(|_| ())
50}
51
52/// Add (register) a new Redfish endpoint.
53pub async fn add_redfish_endpoint(
54  infra: &InfraContext<'_>,
55  token: &str,
56  params: UpdateRedfishEndpointParams,
57) -> Result<(), Error> {
58  let redfish_endpoint = RedfishEndpoint {
59    id: params.id,
60    name: params.name,
61    hostname: params.hostname,
62    domain: params.domain,
63    fqdn: params.fqdn,
64    enabled: Some(params.enabled),
65    user: params.user,
66    password: params.password,
67    use_ssdp: Some(params.use_ssdp),
68    mac_required: Some(params.mac_required),
69    mac_addr: params.mac_addr,
70    ip_address: params.ip_address,
71    rediscover_on_update: Some(params.rediscover_on_update),
72    template_id: params.template_id,
73    r#type: None,
74    uuid: None,
75    discovery_info: None,
76  };
77
78  let redfish_endpoint_array = RedfishEndpointArray {
79    redfish_endpoints: Some(vec![redfish_endpoint]),
80  };
81
82  infra
83    .backend
84    .add_redfish_endpoint(token, &redfish_endpoint_array)
85    .await?;
86
87  Ok(())
88}
89
90/// Update a Redfish endpoint registration.
91pub async fn update_redfish_endpoint(
92  infra: &InfraContext<'_>,
93  token: &str,
94  params: UpdateRedfishEndpointParams,
95) -> Result<(), Error> {
96  let redfish_endpoint = RedfishEndpoint {
97    id: params.id,
98    name: params.name,
99    hostname: params.hostname,
100    domain: params.domain,
101    fqdn: params.fqdn,
102    enabled: Some(params.enabled),
103    user: params.user,
104    password: params.password,
105    use_ssdp: Some(params.use_ssdp),
106    mac_required: Some(params.mac_required),
107    mac_addr: params.mac_addr,
108    ip_address: params.ip_address,
109    rediscover_on_update: Some(params.rediscover_on_update),
110    template_id: params.template_id,
111    r#type: None,
112    uuid: None,
113    discovery_info: None,
114  };
115
116  infra
117    .backend
118    .update_redfish_endpoint(token, &redfish_endpoint)
119    .await?;
120
121  Ok(())
122}