Skip to main content

nv_redfish/chassis/
thermal.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
16use crate::schema::redfish::thermal::Thermal as ThermalSchema;
17use crate::Error;
18use crate::NvBmc;
19use crate::Resource;
20use crate::ResourceSchema;
21use nv_redfish_core::Bmc;
22use nv_redfish_core::NavProperty;
23use std::marker::PhantomData;
24use std::sync::Arc;
25
26/// Legacy Thermal resource wrapper.
27///
28/// This represents the deprecated `Chassis/Thermal` resource used in older
29/// Redfish implementations. For modern BMCs, prefer using direct sensor
30/// links via `crate::metrics::HasMetrics` or the `ThermalSubsystem` resource.
31///
32/// Note: This type intentionally does NOT implement `crate::metrics::HasMetrics`
33/// to encourage explicit handling of legacy vs modern approaches.
34pub struct Thermal<B: Bmc> {
35    data: Arc<ThermalSchema>,
36    _marker: PhantomData<B>,
37}
38
39impl<B: Bmc> Thermal<B> {
40    /// Create a new thermal resource handle.
41    pub(crate) async fn new(
42        bmc: &NvBmc<B>,
43        thermal_ref: &NavProperty<ThermalSchema>,
44    ) -> Result<Self, Error<B>> {
45        thermal_ref
46            .get(bmc.as_ref())
47            .await
48            .map_err(Error::Bmc)
49            .map(|data| Self {
50                data,
51                _marker: PhantomData,
52            })
53    }
54
55    /// Get the raw schema data for this thermal resource.
56    ///
57    /// Returns an `Arc` to the underlying schema, allowing cheap cloning
58    /// and sharing of the data. The schema contains arrays of temperatures,
59    /// fans, and thermal redundancy information.
60    #[must_use]
61    pub fn raw(&self) -> Arc<ThermalSchema> {
62        self.data.clone()
63    }
64}
65
66impl<B: Bmc> Resource for Thermal<B> {
67    fn resource_ref(&self) -> &ResourceSchema {
68        &self.data.as_ref().base
69    }
70}