Skip to main content

nv_redfish/manager/
mod.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Manager entities and collections.
17//!
18//! This module provides types for working with Redfish Manager resources.
19
20mod item;
21
22use crate::core::NavProperty;
23use crate::resource::Resource as _;
24use crate::schema::redfish::manager_collection::ManagerCollection as ManagerCollectionSchema;
25use crate::Error;
26use crate::NvBmc;
27use crate::ServiceRoot;
28use nv_redfish_core::Bmc;
29use std::sync::Arc;
30
31pub use item::Manager;
32
33/// Manager collection.
34///
35/// Provides functions to access collection members.
36pub struct ManagerCollection<B: Bmc> {
37    bmc: NvBmc<B>,
38    collection: Arc<ManagerCollectionSchema>,
39}
40
41impl<B: Bmc> ManagerCollection<B> {
42    /// Create a new manager collection handle.
43    pub(crate) async fn new(
44        bmc: &NvBmc<B>,
45        root: &ServiceRoot<B>,
46    ) -> Result<Option<Self>, Error<B>> {
47        if let Some(collection_ref) = &root.root.managers {
48            bmc.expand_property(collection_ref).await.map(Some)
49        } else if root.bug_missing_root_nav_properties() {
50            bmc.expand_property(&NavProperty::new_reference(
51                format!("{}/Managers", root.odata_id()).into(),
52            ))
53            .await
54            .map(Some)
55        } else {
56            Ok(None)
57        }
58        .map(|c| {
59            c.map(|collection| Self {
60                bmc: bmc.clone(),
61                collection,
62            })
63        })
64    }
65
66    /// List all managers available in this BMC.
67    ///
68    /// # Errors
69    ///
70    /// Returns an error if fetching manager data fails.
71    pub async fn members(&self) -> Result<Vec<Manager<B>>, Error<B>> {
72        let mut members = Vec::new();
73        for m in &self.collection.members {
74            members.push(Manager::new(&self.bmc, m).await?);
75        }
76        Ok(members)
77    }
78}