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 Enabled = TaggedType<bool, EnabledTag>;
71#[doc(hidden)]
72#[derive(tagged_types::Tag)]
73#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
74#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
75#[capability(inner_access)]
76pub enum EnabledTag {}
77
78pub type MacAddress<T> = TaggedType<T, MacAddressTag>;
83#[doc(hidden)]
84#[derive(tagged_types::Tag)]
85#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
86#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
87#[capability(inner_access)]
88pub enum MacAddressTag {}
89
90pub type UefiDevicePath<T> = TaggedType<T, UefiDevicePathTag>;
95#[doc(hidden)]
96#[derive(tagged_types::Tag)]
97#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
98#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
99#[capability(inner_access)]
100pub enum UefiDevicePathTag {}
101
102pub struct EthernetInterface<B: Bmc> {
106 data: Arc<EthernetInterfaceSchema>,
107 _marker: PhantomData<B>,
108}
109
110impl<B: Bmc> EthernetInterface<B> {
111 pub(crate) async fn new(
113 bmc: &NvBmc<B>,
114 nav: &NavProperty<EthernetInterfaceSchema>,
115 ) -> Result<Self, Error<B>> {
116 nav.get(bmc.as_ref())
117 .await
118 .map_err(crate::Error::Bmc)
119 .map(|data| Self {
120 data,
121 _marker: PhantomData,
122 })
123 }
124
125 #[must_use]
127 pub fn raw(&self) -> Arc<EthernetInterfaceSchema> {
128 self.data.clone()
129 }
130
131 #[must_use]
134 pub fn interface_enabled(&self) -> Option<Enabled> {
135 self.data
136 .interface_enabled
137 .as_ref()
138 .and_then(Option::as_ref)
139 .copied()
140 .map(Enabled::new)
141 }
142
143 #[must_use]
145 pub fn link_status(&self) -> Option<LinkStatus> {
146 self.data
147 .link_status
148 .as_ref()
149 .and_then(Option::as_ref)
150 .copied()
151 }
152
153 #[must_use]
155 pub fn mac_address(&self) -> Option<MacAddress<&String>> {
156 self.data
157 .mac_address
158 .as_ref()
159 .and_then(Option::as_ref)
160 .map(MacAddress::new)
161 }
162
163 #[must_use]
165 pub fn uefi_device_path(&self) -> Option<UefiDevicePath<&String>> {
166 self.data
167 .uefi_device_path
168 .as_ref()
169 .and_then(Option::as_ref)
170 .map(UefiDevicePath::new)
171 }
172}
173
174impl<B: Bmc> Resource for EthernetInterface<B> {
175 fn resource_ref(&self) -> &ResourceSchema {
176 &self.data.as_ref().base
177 }
178}