use crate::schema::redfish::host_interface::HostInterface as HostInterfaceSchema;
use crate::schema::redfish::host_interface_collection::HostInterfaceCollection as HostInterfaceCollectionSchema;
use crate::Error;
use crate::NvBmc;
use crate::Resource;
use crate::ResourceSchema;
use nv_redfish_core::Bmc;
use nv_redfish_core::NavProperty;
use std::marker::PhantomData;
use std::sync::Arc;
pub struct HostInterfaceCollection<B: Bmc> {
bmc: NvBmc<B>,
collection: Arc<HostInterfaceCollectionSchema>,
}
impl<B: Bmc> HostInterfaceCollection<B> {
pub(crate) async fn new(
bmc: &NvBmc<B>,
nav: &NavProperty<HostInterfaceCollectionSchema>,
) -> Result<Self, Error<B>> {
let collection = bmc.expand_property(nav).await?;
Ok(Self {
bmc: bmc.clone(),
collection,
})
}
pub async fn members(&self) -> Result<Vec<HostInterface<B>>, Error<B>> {
let mut members = Vec::new();
for m in &self.collection.members {
members.push(HostInterface::new(&self.bmc, m).await?);
}
Ok(members)
}
}
pub struct HostInterface<B: Bmc> {
data: Arc<HostInterfaceSchema>,
_marker: PhantomData<B>,
}
impl<B: Bmc> HostInterface<B> {
pub(crate) async fn new(
bmc: &NvBmc<B>,
nav: &NavProperty<HostInterfaceSchema>,
) -> Result<Self, Error<B>> {
nav.get(bmc.as_ref())
.await
.map_err(crate::Error::Bmc)
.map(|data| Self {
data,
_marker: PhantomData,
})
}
#[must_use]
pub fn raw(&self) -> Arc<HostInterfaceSchema> {
self.data.clone()
}
#[must_use]
pub fn interface_enabled(&self) -> Option<bool> {
self.data
.interface_enabled
.as_ref()
.and_then(Option::as_ref)
.copied()
}
}
impl<B: Bmc> Resource for HostInterface<B> {
fn resource_ref(&self) -> &ResourceSchema {
&self.data.as_ref().base
}
}