Skip to main content

nv_redfish/chassis/
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
16mod item;
17
18#[cfg(feature = "network-adapters")]
19mod network_adapter;
20#[cfg(feature = "power")]
21mod power;
22#[cfg(feature = "power-supplies")]
23mod power_supply;
24#[cfg(feature = "thermal")]
25mod thermal;
26
27use nv_redfish_core::Bmc;
28use std::sync::Arc;
29
30#[doc(inline)]
31pub use item::Chassis;
32#[doc(inline)]
33pub use item::Manufacturer;
34#[doc(inline)]
35pub use item::Model;
36#[doc(inline)]
37pub use item::PartNumber;
38#[doc(inline)]
39pub use item::SerialNumber;
40
41#[doc(inline)]
42#[cfg(feature = "network-adapters")]
43pub use network_adapter::Manufacturer as NetworkAdapterManufacturer;
44#[doc(inline)]
45#[cfg(feature = "network-adapters")]
46pub use network_adapter::Model as NetworkAdapterModel;
47#[doc(inline)]
48#[cfg(feature = "network-adapters")]
49pub use network_adapter::NetworkAdapter;
50#[cfg(feature = "network-adapters")]
51pub use network_adapter::NetworkAdapterCollection;
52#[doc(inline)]
53#[cfg(feature = "network-adapters")]
54pub use network_adapter::PartNumber as NetworkAdapterPartNumber;
55#[doc(inline)]
56#[cfg(feature = "network-adapters")]
57pub use network_adapter::SerialNumber as NetworkAdapterSerialNumber;
58#[doc(inline)]
59#[cfg(feature = "power")]
60pub use power::Power;
61#[doc(inline)]
62#[cfg(feature = "power-supplies")]
63pub use power_supply::PowerSupply;
64#[doc(inline)]
65#[cfg(feature = "thermal")]
66pub use thermal::Thermal;
67
68use crate::core::NavProperty;
69use crate::resource::Resource as _;
70use crate::schema::redfish::chassis_collection::ChassisCollection as ChassisCollectionSchema;
71use crate::{Error, NvBmc, ServiceRoot};
72
73/// Chassis collection.
74///
75/// Provides functions to access collection members.
76pub struct ChassisCollection<B: Bmc> {
77    bmc: NvBmc<B>,
78    collection: Arc<ChassisCollectionSchema>,
79    item_config: Arc<item::Config>,
80}
81
82impl<B: Bmc> ChassisCollection<B> {
83    pub(crate) async fn new(
84        bmc: &NvBmc<B>,
85        root: &ServiceRoot<B>,
86    ) -> Result<Option<Self>, Error<B>> {
87        if let Some(collection_ref) = &root.root.chassis {
88            bmc.expand_property(collection_ref).await.map(Some)
89        } else if root.bug_missing_root_nav_properties() {
90            bmc.expand_property(&NavProperty::new_reference(
91                format!("{}/Chassis", root.odata_id()).into(),
92            ))
93            .await
94            .map(Some)
95        } else {
96            Ok(None)
97        }
98        .map(|c| {
99            c.map(|collection| {
100                let item_config = item::Config::new(root).into();
101                Self {
102                    bmc: bmc.clone(),
103                    collection,
104                    item_config,
105                }
106            })
107        })
108    }
109
110    /// List all chassis avaiable in this BMC
111    ///
112    /// # Errors
113    ///
114    /// Returns an error if fetching collection data fails.
115    pub async fn members(&self) -> Result<Vec<Chassis<B>>, Error<B>> {
116        let mut chassis_members = Vec::new();
117        for chassis in &self.collection.members {
118            chassis_members.push(Chassis::new(&self.bmc, chassis, self.item_config.clone()).await?);
119        }
120
121        Ok(chassis_members)
122    }
123}