nv_redfish/
ethernet_interface.rs1use crate::schema::redfish::ethernet_interface::EthernetInterface as EthernetInterfaceSchema;
20use crate::schema::redfish::ethernet_interface_collection::EthernetInterfaceCollection as EthernetInterfaceCollectionSchema;
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;
29use tagged_types::TaggedType;
30
31#[doc(inline)]
32pub use crate::schema::redfish::ethernet_interface::LinkStatus;
33
34pub struct EthernetInterfaceCollection<B: Bmc> {
38 bmc: NvBmc<B>,
39 collection: Arc<EthernetInterfaceCollectionSchema>,
40}
41
42impl<B: Bmc> EthernetInterfaceCollection<B> {
43 pub(crate) async fn new(
45 bmc: &NvBmc<B>,
46 nav: &NavProperty<EthernetInterfaceCollectionSchema>,
47 ) -> Result<Self, Error<B>> {
48 let collection = bmc.expand_property(nav).await?;
49 Ok(Self {
50 bmc: bmc.clone(),
51 collection,
52 })
53 }
54
55 pub async fn members(&self) -> Result<Vec<EthernetInterface<B>>, Error<B>> {
61 let mut members = Vec::new();
62 for m in &self.collection.members {
63 members.push(EthernetInterface::new(&self.bmc, m).await?);
64 }
65 Ok(members)
66 }
67}
68
69pub type MacAddress<T> = TaggedType<T, MacAddressTag>;
74#[doc(hidden)]
75#[derive(tagged_types::Tag)]
76#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
77#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
78#[capability(inner_access)]
79pub enum MacAddressTag {}
80
81pub type UefiDevicePath<T> = TaggedType<T, UefiDevicePathTag>;
86#[doc(hidden)]
87#[derive(tagged_types::Tag)]
88#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
89#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
90#[capability(inner_access)]
91pub enum UefiDevicePathTag {}
92
93pub struct EthernetInterface<B: Bmc> {
97 data: Arc<EthernetInterfaceSchema>,
98 _marker: PhantomData<B>,
99}
100
101impl<B: Bmc> EthernetInterface<B> {
102 pub(crate) async fn new(
104 bmc: &NvBmc<B>,
105 nav: &NavProperty<EthernetInterfaceSchema>,
106 ) -> Result<Self, Error<B>> {
107 nav.get(bmc.as_ref())
108 .await
109 .map_err(crate::Error::Bmc)
110 .map(|data| Self {
111 data,
112 _marker: PhantomData,
113 })
114 }
115
116 #[must_use]
118 pub fn raw(&self) -> Arc<EthernetInterfaceSchema> {
119 self.data.clone()
120 }
121
122 #[must_use]
125 pub fn interface_enabled(&self) -> Option<bool> {
126 self.data
127 .interface_enabled
128 .as_ref()
129 .and_then(Option::as_ref)
130 .copied()
131 }
132
133 #[must_use]
135 pub fn link_status(&self) -> Option<LinkStatus> {
136 self.data
137 .link_status
138 .as_ref()
139 .and_then(Option::as_ref)
140 .copied()
141 }
142
143 #[must_use]
145 pub fn mac_address(&self) -> Option<MacAddress<&str>> {
146 self.data
147 .mac_address
148 .as_ref()
149 .and_then(Option::as_ref)
150 .map(String::as_str)
151 .map(MacAddress::new)
152 }
153
154 #[must_use]
156 pub fn uefi_device_path(&self) -> Option<UefiDevicePath<&str>> {
157 self.data
158 .uefi_device_path
159 .as_ref()
160 .and_then(Option::as_ref)
161 .map(String::as_str)
162 .map(UefiDevicePath::new)
163 }
164}
165
166impl<B: Bmc> Resource for EthernetInterface<B> {
167 fn resource_ref(&self) -> &ResourceSchema {
168 &self.data.as_ref().base
169 }
170}