nv_redfish/
service_root.rs1use std::sync::Arc;
17
18use nv_redfish_core::{Bmc, NavProperty, ODataId};
19use tagged_types::TaggedType;
20
21#[cfg(feature = "accounts")]
22use crate::account::AccountService;
23#[cfg(feature = "accounts")]
24use crate::account::SlotDefinedConfig as SlotDefinedUserAccountsConfig;
25#[cfg(feature = "chassis")]
26use crate::chassis::ChassisCollection;
27#[cfg(feature = "computer-systems")]
28use crate::computer_system::SystemCollection;
29#[cfg(feature = "managers")]
30use crate::manager::ManagerCollection;
31use crate::schema::redfish::service_root::ServiceRoot as SchemaServiceRoot;
32#[cfg(feature = "update-service")]
33use crate::update_service::UpdateService;
34use crate::{Error, NvBmc, ProtocolFeatures, Resource, ResourceSchema};
35
36pub type Vendor<T> = TaggedType<T, VendorTag>;
38#[doc(hidden)]
39#[derive(tagged_types::Tag)]
40#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
41#[transparent(Debug, Display, Serialize, Deserialize)]
42#[capability(inner_access, cloned)]
43pub enum VendorTag {}
44
45pub type Product<T> = TaggedType<T, ProductTag>;
47#[doc(hidden)]
48#[derive(tagged_types::Tag)]
49#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
50#[transparent(Debug, Display, Serialize, Deserialize)]
51#[capability(inner_access, cloned)]
52pub enum ProductTag {}
53
54#[derive(Clone)]
56pub struct ServiceRoot<B: Bmc> {
57 pub root: Arc<SchemaServiceRoot>,
59 #[allow(dead_code)] bmc: NvBmc<B>,
61}
62
63impl<B: Bmc> ServiceRoot<B> {
64 pub async fn new(bmc: Arc<B>) -> Result<Self, Error<B>> {
70 let root = NavProperty::<SchemaServiceRoot>::new_reference(ODataId::service_root())
71 .get(bmc.as_ref())
72 .await
73 .map_err(Error::Bmc)?;
74 let mut protocol_features = root
75 .protocol_features_supported
76 .as_ref()
77 .map(ProtocolFeatures::new)
78 .unwrap_or_default();
79
80 if Self::expand_is_not_working_properly(&root) {
81 protocol_features.expand.expand_all = false;
82 protocol_features.expand.no_links = false;
83 }
84
85 let bmc = NvBmc::new(bmc, protocol_features);
86 Ok(Self { root, bmc })
87 }
88
89 pub fn vendor(&self) -> Option<Vendor<&String>> {
91 self.root
92 .vendor
93 .as_ref()
94 .and_then(Option::as_ref)
95 .map(Vendor::new)
96 }
97
98 pub fn product(&self) -> Option<Product<&String>> {
100 self.root
101 .product
102 .as_ref()
103 .and_then(Option::as_ref)
104 .map(Product::new)
105 }
106
107 #[cfg(feature = "accounts")]
113 pub async fn account_service(&self) -> Result<AccountService<B>, Error<B>> {
114 AccountService::new(&self.bmc, self).await
115 }
116
117 #[cfg(feature = "chassis")]
123 pub async fn chassis(&self) -> Result<ChassisCollection<B>, Error<B>> {
124 ChassisCollection::new(&self.bmc, self).await
125 }
126
127 #[cfg(feature = "computer-systems")]
133 pub async fn systems(&self) -> Result<SystemCollection<B>, Error<B>> {
134 SystemCollection::new(&self.bmc, self).await
135 }
136
137 #[cfg(feature = "update-service")]
143 pub async fn update_service(&self) -> Result<UpdateService<B>, Error<B>> {
144 UpdateService::new(&self.bmc, self).await
145 }
146
147 #[cfg(feature = "managers")]
153 pub async fn managers(&self) -> Result<ManagerCollection<B>, Error<B>> {
154 ManagerCollection::new(&self.bmc, self).await
155 }
156}
157
158impl<B: Bmc> ServiceRoot<B> {
160 #[cfg(feature = "accounts")]
165 pub(crate) fn bug_no_account_type_in_accounts(&self) -> bool {
166 self.root
167 .vendor
168 .as_ref()
169 .and_then(Option::as_ref)
170 .is_some_and(|v| v == "HPE")
171 }
172
173 #[cfg(feature = "accounts")]
179 pub(crate) fn slot_defined_user_accounts(&self) -> Option<SlotDefinedUserAccountsConfig> {
180 if self
181 .root
182 .vendor
183 .as_ref()
184 .and_then(Option::as_ref)
185 .is_some_and(|v| v == "Dell")
186 {
187 Some(SlotDefinedUserAccountsConfig {
188 min_slot: Some(3),
189 hide_disabled: true,
190 disable_account_on_delete: true,
191 })
192 } else {
193 None
194 }
195 }
196
197 #[cfg(feature = "update-service")]
201 pub(crate) fn fw_inventory_wrong_release_date(&self) -> bool {
202 self.root
203 .vendor
204 .as_ref()
205 .and_then(Option::as_ref)
206 .is_some_and(|v| v == "Dell")
207 }
208
209 #[cfg(feature = "chassis")]
212 pub(crate) fn bug_invalid_contained_by_fields(&self) -> bool {
213 self.root
214 .vendor
215 .as_ref()
216 .and_then(Option::as_ref)
217 .is_some_and(|v| v == "AMI")
218 && self
219 .root
220 .redfish_version
221 .as_ref()
222 .is_some_and(|version| version == "1.11.0")
223 }
224
225 #[cfg(feature = "computer-systems")]
230 pub(crate) fn computer_systems_wrong_last_reset_time(&self) -> bool {
231 self.root
232 .vendor
233 .as_ref()
234 .and_then(Option::as_ref)
235 .is_some_and(|v| v == "Dell")
236 }
237
238 #[cfg(feature = "assembly")]
242 pub(crate) fn assembly_assemblies_without_odata_type(&self) -> bool {
243 self.root
244 .vendor
245 .as_ref()
246 .and_then(Option::as_ref)
247 .is_some_and(|v| v == "WIWYNN")
248 }
249
250 fn expand_is_not_working_properly(root: &SchemaServiceRoot) -> bool {
254 root.vendor
255 .as_ref()
256 .and_then(Option::as_ref)
257 .is_some_and(|v| v == "AMI")
258 && root
259 .redfish_version
260 .as_ref()
261 .is_some_and(|version| version == "1.11.0")
262 }
263}
264
265impl<B: Bmc> Resource for ServiceRoot<B> {
266 fn resource_ref(&self) -> &ResourceSchema {
267 &self.root.as_ref().base
268 }
269}