nv_redfish/
host_interface.rs1use crate::schema::redfish::host_interface::HostInterface as HostInterfaceSchema;
20use crate::schema::redfish::host_interface_collection::HostInterfaceCollection as HostInterfaceCollectionSchema;
21use crate::Error;
22use crate::NvBmc;
23use crate::Resource;
24use crate::ResourceSchema;
25use nv_redfish_core::Bmc;
26use nv_redfish_core::NavProperty;
27use std::marker::PhantomData;
28use std::sync::Arc;
29
30pub struct HostInterfaceCollection<B: Bmc> {
34 bmc: NvBmc<B>,
35 collection: Arc<HostInterfaceCollectionSchema>,
36}
37
38impl<B: Bmc> HostInterfaceCollection<B> {
39 pub(crate) async fn new(
41 bmc: &NvBmc<B>,
42 nav: &NavProperty<HostInterfaceCollectionSchema>,
43 ) -> Result<Self, Error<B>> {
44 let collection = bmc.expand_property(nav).await?;
45 Ok(Self {
46 bmc: bmc.clone(),
47 collection,
48 })
49 }
50
51 pub async fn members(&self) -> Result<Vec<HostInterface<B>>, Error<B>> {
57 let mut members = Vec::new();
58 for m in &self.collection.members {
59 members.push(HostInterface::new(&self.bmc, m).await?);
60 }
61 Ok(members)
62 }
63}
64
65pub struct HostInterface<B: Bmc> {
69 data: Arc<HostInterfaceSchema>,
70 _marker: PhantomData<B>,
71}
72
73impl<B: Bmc> HostInterface<B> {
74 pub(crate) async fn new(
76 bmc: &NvBmc<B>,
77 nav: &NavProperty<HostInterfaceSchema>,
78 ) -> Result<Self, Error<B>> {
79 nav.get(bmc.as_ref())
80 .await
81 .map_err(crate::Error::Bmc)
82 .map(|data| Self {
83 data,
84 _marker: PhantomData,
85 })
86 }
87
88 #[must_use]
90 pub fn raw(&self) -> Arc<HostInterfaceSchema> {
91 self.data.clone()
92 }
93
94 #[must_use]
97 pub fn interface_enabled(&self) -> Option<bool> {
98 self.data
99 .interface_enabled
100 .as_ref()
101 .and_then(Option::as_ref)
102 .copied()
103 }
104}
105
106impl<B: Bmc> Resource for HostInterface<B> {
107 fn resource_ref(&self) -> &ResourceSchema {
108 &self.data.as_ref().base
109 }
110}