nv_redfish/chassis/power.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::power::Power as PowerSchema;
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 Power resource wrapper.
27///
28/// This represents the deprecated `Chassis/Power` resource used in older
29/// Redfish implementations. For modern BMCs, prefer using direct sensor
30/// links via `crate::metrics::HasMetrics` or the `PowerSubsystem` 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 Power<B: Bmc> {
35 data: Arc<PowerSchema>,
36 _marker: PhantomData<B>,
37}
38
39impl<B: Bmc> Power<B> {
40 /// Create a new power resource handle.
41 pub(crate) async fn new(
42 bmc: &NvBmc<B>,
43 nav: &NavProperty<PowerSchema>,
44 ) -> Result<Self, Error<B>> {
45 nav.get(bmc.as_ref())
46 .await
47 .map_err(Error::Bmc)
48 .map(|data| Self {
49 data,
50 _marker: PhantomData,
51 })
52 }
53
54 /// Get the raw schema data for this power resource.
55 ///
56 /// Returns an `Arc` to the underlying schema, allowing cheap cloning
57 /// and sharing of the data. The schema contains arrays of power supplies,
58 /// voltages, and power control information.
59 #[must_use]
60 pub fn raw(&self) -> Arc<PowerSchema> {
61 self.data.clone()
62 }
63}
64
65impl<B: Bmc> Resource for Power<B> {
66 fn resource_ref(&self) -> &ResourceSchema {
67 &self.data.as_ref().base
68 }
69}