nv_redfish/manager/
item.rs1use crate::schema::redfish::manager::Manager as ManagerSchema;
17use crate::Error;
18use crate::NvBmc;
19use crate::Resource;
20use crate::ResourceSchema;
21use nv_redfish_core::Bmc;
22use nv_redfish_core::NavProperty;
23use std::sync::Arc;
24
25#[cfg(feature = "ethernet-interfaces")]
26use crate::ethernet_interface::EthernetInterfaceCollection;
27#[cfg(feature = "host-interfaces")]
28use crate::host_interface::HostInterfaceCollection;
29#[cfg(feature = "log-services")]
30use crate::log_service::LogService;
31#[cfg(feature = "oem-dell-attributes")]
32use crate::oem::dell::attributes::DellAttributes;
33#[cfg(feature = "oem-hpe")]
34use crate::oem::hpe::manager::HpeManager;
35#[cfg(feature = "oem-lenovo")]
36use crate::oem::lenovo::manager::LenovoManager;
37#[cfg(feature = "oem-supermicro")]
38use crate::oem::supermicro::manager::SupermicroManager;
39
40pub struct Manager<B: Bmc> {
44 #[allow(dead_code)] bmc: NvBmc<B>,
46 data: Arc<ManagerSchema>,
47}
48
49impl<B: Bmc> Manager<B> {
50 pub(crate) async fn new(
52 bmc: &NvBmc<B>,
53 nav: &NavProperty<ManagerSchema>,
54 ) -> Result<Self, Error<B>> {
55 nav.get(bmc.as_ref())
56 .await
57 .map_err(Error::Bmc)
58 .map(|data| Self {
59 bmc: bmc.clone(),
60 data,
61 })
62 }
63
64 #[must_use]
69 pub fn raw(&self) -> Arc<ManagerSchema> {
70 self.data.clone()
71 }
72
73 #[cfg(feature = "ethernet-interfaces")]
81 pub async fn ethernet_interfaces(
82 &self,
83 ) -> Result<Option<EthernetInterfaceCollection<B>>, crate::Error<B>> {
84 if let Some(p) = &self.data.ethernet_interfaces {
85 EthernetInterfaceCollection::new(&self.bmc, p)
86 .await
87 .map(Some)
88 } else {
89 Ok(None)
90 }
91 }
92
93 #[cfg(feature = "host-interfaces")]
101 pub async fn host_interfaces(
102 &self,
103 ) -> Result<Option<HostInterfaceCollection<B>>, crate::Error<B>> {
104 if let Some(p) = &self.data.host_interfaces {
105 HostInterfaceCollection::new(&self.bmc, p).await.map(Some)
106 } else {
107 Ok(None)
108 }
109 }
110
111 #[cfg(feature = "log-services")]
119 pub async fn log_services(&self) -> Result<Option<Vec<LogService<B>>>, crate::Error<B>> {
120 if let Some(log_services_ref) = &self.data.log_services {
121 let log_services_collection = log_services_ref
122 .get(self.bmc.as_ref())
123 .await
124 .map_err(crate::Error::Bmc)?;
125
126 let mut log_services = Vec::new();
127 for m in &log_services_collection.members {
128 log_services.push(LogService::new(&self.bmc, m).await?);
129 }
130
131 Ok(Some(log_services))
132 } else {
133 Ok(None)
134 }
135 }
136
137 #[cfg(feature = "oem-dell-attributes")]
145 pub async fn oem_dell_attributes(&self) -> Result<Option<DellAttributes<B>>, Error<B>> {
146 DellAttributes::manager_attributes(&self.bmc, &self.data).await
147 }
148
149 #[cfg(feature = "oem-lenovo")]
157 pub fn oem_lenovo(&self) -> Result<Option<LenovoManager<B>>, Error<B>> {
158 LenovoManager::new(&self.bmc, &self.data)
159 }
160
161 #[cfg(feature = "oem-hpe")]
169 pub fn oem_hpe(&self) -> Result<Option<HpeManager<B>>, Error<B>> {
170 HpeManager::new(&self.bmc, &self.data)
171 }
172
173 #[cfg(feature = "oem-supermicro")]
181 pub fn oem_supermicro(&self) -> Result<Option<SupermicroManager<B>>, Error<B>> {
182 SupermicroManager::new(&self.bmc, &self.data)
183 }
184}
185
186impl<B: Bmc> Resource for Manager<B> {
187 fn resource_ref(&self) -> &ResourceSchema {
188 &self.data.as_ref().base
189 }
190}