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::schema::redfish::manager_collection::ManagerCollection as ManagerCollectionSchema;
23use crate::Error;
24use crate::NvBmc;
25use crate::ServiceRoot;
26use nv_redfish_core::Bmc;
27use std::sync::Arc;
28
29pub use item::Manager;
30
31/// Manager collection.
32///
33/// Provides functions to access collection members.
34pub struct ManagerCollection<B: Bmc> {
35    bmc: NvBmc<B>,
36    collection: Arc<ManagerCollectionSchema>,
37}
38
39impl<B: Bmc> ManagerCollection<B> {
40    /// Create a new manager collection handle.
41    pub(crate) async fn new(bmc: &NvBmc<B>, root: &ServiceRoot<B>) -> Result<Self, Error<B>> {
42        let collection_ref = root
43            .root
44            .managers
45            .as_ref()
46            .ok_or(Error::ManagerNotSupported)?;
47
48        let collection = bmc.expand_property(collection_ref).await?;
49        Ok(Self {
50            bmc: bmc.clone(),
51            collection,
52        })
53    }
54
55    /// List all managers available in this BMC.
56    ///
57    /// # Errors
58    ///
59    /// Returns an error if fetching manager data fails.
60    pub async fn members(&self) -> Result<Vec<Manager<B>>, Error<B>> {
61        let mut members = Vec::new();
62        for m in &self.collection.members {
63            members.push(Manager::new(&self.bmc, m).await?);
64        }
65        Ok(members)
66    }
67}