nv_redfish/
network_device_function.rs1use crate::mac_address::MacAddress;
19use crate::schema::redfish::network_device_function::NetworkDeviceFunction as NetworkDeviceFunctionSchema;
20use crate::schema::redfish::network_device_function_collection::NetworkDeviceFunctionCollection as NetworkDeviceFunctionCollectionSchema;
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 NetworkDeviceFunctionCollection<B: Bmc> {
34 bmc: NvBmc<B>,
35 collection: Arc<NetworkDeviceFunctionCollectionSchema>,
36}
37
38impl<B: Bmc> NetworkDeviceFunctionCollection<B> {
39 pub(crate) async fn new(
41 bmc: &NvBmc<B>,
42 nav: &NavProperty<NetworkDeviceFunctionCollectionSchema>,
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<NetworkDeviceFunction<B>>, Error<B>> {
57 let mut members = Vec::new();
58 for m in &self.collection.members {
59 members.push(NetworkDeviceFunction::new(&self.bmc, m).await?);
60 }
61 Ok(members)
62 }
63}
64
65pub struct NetworkDeviceFunction<B: Bmc> {
69 data: Arc<NetworkDeviceFunctionSchema>,
70 _marker: PhantomData<B>,
71}
72
73impl<B: Bmc> NetworkDeviceFunction<B> {
74 pub(crate) async fn new(
76 bmc: &NvBmc<B>,
77 nav: &NavProperty<NetworkDeviceFunctionSchema>,
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<NetworkDeviceFunctionSchema> {
91 self.data.clone()
92 }
93
94 pub fn ethernet_permanent_mac_address(&self) -> Option<MacAddress<'_>> {
96 self.data
97 .ethernet
98 .as_ref()
99 .and_then(|eth| eth.permanent_mac_address.as_ref())
100 .and_then(Option::as_deref)
101 .map(MacAddress::new)
102 }
103}
104
105impl<B: Bmc> Resource for NetworkDeviceFunction<B> {
106 fn resource_ref(&self) -> &ResourceSchema {
107 &self.data.as_ref().base
108 }
109}