nv_redfish/manager/
mod.rs1mod item;
21#[cfg(feature = "manager-network-protocol")]
22mod network_protocol;
23
24use crate::core::NavProperty;
25use crate::patch_support::CollectionWithPatch;
26use crate::patch_support::FilterFn;
27use crate::patch_support::JsonValue;
28use crate::resource::Resource as _;
29use crate::schema::manager::Manager as ManagerSchema;
30use crate::schema::manager_collection::ManagerCollection as ManagerCollectionSchema;
31use crate::schema::resource::ResourceCollection;
32use crate::Error;
33use crate::NvBmc;
34use crate::ServiceRoot;
35use nv_redfish_core::Bmc;
36use std::convert::identity;
37use std::sync::Arc;
38
39pub use item::Manager;
40#[cfg(feature = "manager-network-protocol")]
41pub use network_protocol::ManagerNetworkProtocol;
42
43#[doc(inline)]
44pub use crate::schema::manager::ResetToDefaultsType as ManagerResetToDefaultsType;
45
46pub struct ManagerCollection<B: Bmc> {
50 bmc: NvBmc<B>,
51 collection: Arc<ManagerCollectionSchema>,
52}
53
54impl<B: Bmc> ManagerCollection<B> {
55 pub(crate) async fn new(
57 bmc: &NvBmc<B>,
58 root: &ServiceRoot<B>,
59 ) -> Result<Option<Self>, Error<B>> {
60 let mut filters = Vec::new();
61 if let Some(odata_id_filter) = bmc.quirks.filter_manager_odata_ids() {
62 filters.push(Box::new(move |js: &JsonValue| {
63 js.get("@odata.id")
64 .and_then(|v| v.as_str())
65 .map(odata_id_filter)
66 .is_some_and(identity)
67 }));
68 }
69 let filters_fn = (!filters.is_empty())
70 .then(move || Arc::new(move |v: &JsonValue| filters.iter().any(|f| f(v))) as FilterFn);
71
72 if let Some(collection_ref) = &root.root.managers {
73 Self::expand_collection(bmc, collection_ref, None, filters_fn.as_ref())
74 .await
75 .map(Some)
76 } else if bmc.quirks.bug_missing_root_nav_properties() {
77 bmc.expand_property(&NavProperty::new_reference(
78 format!("{}/Managers", root.odata_id()).into(),
79 ))
80 .await
81 .map(Some)
82 } else {
83 Ok(None)
84 }
85 .map(|c| {
86 c.map(|collection| Self {
87 bmc: bmc.clone(),
88 collection,
89 })
90 })
91 }
92
93 pub async fn members(&self) -> Result<Vec<Manager<B>>, Error<B>> {
99 let mut members = Vec::new();
100 for m in &self.collection.members {
101 members.push(Manager::new(&self.bmc, m).await?);
102 }
103 Ok(members)
104 }
105}
106
107impl<B: Bmc> CollectionWithPatch<ManagerCollectionSchema, ManagerSchema, B>
108 for ManagerCollection<B>
109{
110 fn convert_patched(
111 base: ResourceCollection,
112 members: Vec<NavProperty<ManagerSchema>>,
113 ) -> ManagerCollectionSchema {
114 ManagerCollectionSchema { base, members }
115 }
116}