nv_redfish/
service_root.rs1use crate::schema::redfish::service_root::ServiceRoot as SchemaServiceRoot;
17use crate::Error;
18use crate::NvBmc;
19use crate::ProtocolFeatures;
20use crate::Resource;
21use crate::ResourceSchema;
22use nv_redfish_core::Bmc;
23use nv_redfish_core::NavProperty;
24use nv_redfish_core::ODataId;
25use std::sync::Arc;
26use tagged_types::TaggedType;
27
28#[cfg(feature = "accounts")]
29use crate::account::AccountService;
30#[cfg(feature = "accounts")]
31use crate::account::SlotDefinedConfig as SlotDefinedUserAccountsConfig;
32#[cfg(feature = "chassis")]
33use crate::chassis::ChassisCollection;
34#[cfg(feature = "computer-systems")]
35use crate::computer_system::SystemCollection;
36#[cfg(feature = "managers")]
37use crate::manager::ManagerCollection;
38#[cfg(feature = "update-service")]
39use crate::update_service::UpdateService;
40
41pub type Vendor<T> = TaggedType<T, VendorTag>;
43#[doc(hidden)]
44#[derive(tagged_types::Tag)]
45#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
46#[transparent(Debug, Display, Serialize, Deserialize)]
47#[capability(inner_access, cloned)]
48pub enum VendorTag {}
49
50pub type Product<T> = TaggedType<T, ProductTag>;
52#[doc(hidden)]
53#[derive(tagged_types::Tag)]
54#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
55#[transparent(Debug, Display, Serialize, Deserialize)]
56#[capability(inner_access, cloned)]
57pub enum ProductTag {}
58
59#[derive(Clone)]
61pub struct ServiceRoot<B: Bmc> {
62 pub root: Arc<SchemaServiceRoot>,
64 #[allow(dead_code)] bmc: NvBmc<B>,
66}
67
68impl<B: Bmc> ServiceRoot<B> {
69 pub async fn new(bmc: Arc<B>) -> Result<Self, Error<B>> {
75 let root = NavProperty::<SchemaServiceRoot>::new_reference(ODataId::service_root())
76 .get(bmc.as_ref())
77 .await
78 .map_err(Error::Bmc)?;
79 let mut protocol_features = root
80 .protocol_features_supported
81 .as_ref()
82 .map(ProtocolFeatures::new)
83 .unwrap_or_default();
84
85 if Self::expand_is_not_working_properly(&root) {
86 protocol_features.expand.expand_all = false;
87 protocol_features.expand.no_links = false;
88 }
89
90 let bmc = NvBmc::new(bmc, protocol_features);
91 Ok(Self { root, bmc })
92 }
93
94 pub fn vendor(&self) -> Option<Vendor<&String>> {
96 self.root
97 .vendor
98 .as_ref()
99 .and_then(Option::as_ref)
100 .map(Vendor::new)
101 }
102
103 pub fn product(&self) -> Option<Product<&String>> {
105 self.root
106 .product
107 .as_ref()
108 .and_then(Option::as_ref)
109 .map(Product::new)
110 }
111
112 #[cfg(feature = "accounts")]
118 pub async fn account_service(&self) -> Result<AccountService<B>, Error<B>> {
119 AccountService::new(&self.bmc, self).await
120 }
121
122 #[cfg(feature = "chassis")]
128 pub async fn chassis(&self) -> Result<ChassisCollection<B>, Error<B>> {
129 ChassisCollection::new(&self.bmc, self).await
130 }
131
132 #[cfg(feature = "computer-systems")]
138 pub async fn systems(&self) -> Result<SystemCollection<B>, Error<B>> {
139 SystemCollection::new(&self.bmc, self).await
140 }
141
142 #[cfg(feature = "update-service")]
148 pub async fn update_service(&self) -> Result<UpdateService<B>, Error<B>> {
149 UpdateService::new(&self.bmc, self).await
150 }
151
152 #[cfg(feature = "managers")]
158 pub async fn managers(&self) -> Result<ManagerCollection<B>, Error<B>> {
159 ManagerCollection::new(&self.bmc, self).await
160 }
161}
162
163impl<B: Bmc> ServiceRoot<B> {
165 #[cfg(feature = "accounts")]
170 pub(crate) fn bug_no_account_type_in_accounts(&self) -> bool {
171 self.root
172 .vendor
173 .as_ref()
174 .and_then(Option::as_ref)
175 .is_some_and(|v| v == "HPE")
176 }
177
178 #[cfg(feature = "accounts")]
184 pub(crate) fn slot_defined_user_accounts(&self) -> Option<SlotDefinedUserAccountsConfig> {
185 if self
186 .root
187 .vendor
188 .as_ref()
189 .and_then(Option::as_ref)
190 .is_some_and(|v| v == "Dell")
191 {
192 Some(SlotDefinedUserAccountsConfig {
193 min_slot: Some(3),
194 hide_disabled: true,
195 disable_account_on_delete: true,
196 })
197 } else {
198 None
199 }
200 }
201
202 #[cfg(feature = "update-service")]
206 pub(crate) fn fw_inventory_wrong_release_date(&self) -> bool {
207 self.root
208 .vendor
209 .as_ref()
210 .and_then(Option::as_ref)
211 .is_some_and(|v| v == "Dell")
212 }
213
214 #[cfg(feature = "chassis")]
217 pub(crate) fn bug_invalid_contained_by_fields(&self) -> bool {
218 self.root
219 .vendor
220 .as_ref()
221 .and_then(Option::as_ref)
222 .is_some_and(|v| v == "AMI")
223 && self
224 .root
225 .redfish_version
226 .as_ref()
227 .is_some_and(|version| version == "1.11.0")
228 }
229
230 #[cfg(feature = "computer-systems")]
235 pub(crate) fn computer_systems_wrong_last_reset_time(&self) -> bool {
236 self.root
237 .vendor
238 .as_ref()
239 .and_then(Option::as_ref)
240 .is_some_and(|v| v == "Dell")
241 }
242
243 fn expand_is_not_working_properly(root: &SchemaServiceRoot) -> bool {
247 root.vendor
248 .as_ref()
249 .and_then(Option::as_ref)
250 .is_some_and(|v| v == "AMI")
251 && root
252 .redfish_version
253 .as_ref()
254 .is_some_and(|version| version == "1.11.0")
255 }
256}
257
258impl<B: Bmc> Resource for ServiceRoot<B> {
259 fn resource_ref(&self) -> &ResourceSchema {
260 &self.root.as_ref().base
261 }
262}