nv_redfish/computer_system/
boot_option.rs1use crate::computer_system::BootOptionReference;
19use crate::schema::redfish::boot_option::BootOption as BootOptionSchema;
20use crate::schema::redfish::boot_option_collection::BootOptionCollection as BootOptionCollectionSchema;
21use crate::Error;
22use crate::NvBmc;
23use crate::Resource;
24use crate::ResourceSchema;
25use nv_redfish_core::Bmc;
26use nv_redfish_core::NavProperty;
27use std::convert::identity;
28use std::marker::PhantomData;
29use std::sync::Arc;
30use tagged_types::TaggedType;
31
32pub struct BootOptionCollection<B: Bmc> {
36 bmc: NvBmc<B>,
37 collection: Arc<BootOptionCollectionSchema>,
38}
39
40impl<B: Bmc> BootOptionCollection<B> {
41 pub(crate) async fn new(
43 bmc: &NvBmc<B>,
44 nav: &NavProperty<BootOptionCollectionSchema>,
45 ) -> Result<Self, Error<B>> {
46 let collection = bmc.expand_property(nav).await?;
47 Ok(Self {
48 bmc: bmc.clone(),
49 collection,
50 })
51 }
52
53 pub async fn members(&self) -> Result<Vec<BootOption<B>>, Error<B>> {
59 let mut members = Vec::new();
60 for m in &self.collection.members {
61 members.push(BootOption::new(&self.bmc, m).await?);
62 }
63 Ok(members)
64 }
65}
66
67pub type UefiDevicePath<T> = TaggedType<T, UefiDevicePathTag>;
72#[doc(hidden)]
73#[derive(tagged_types::Tag)]
74#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
75#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
76#[capability(inner_access, cloned)]
77pub enum UefiDevicePathTag {}
78
79pub type DisplayName<T> = TaggedType<T, DisplayNameTag>;
82#[doc(hidden)]
83#[derive(tagged_types::Tag)]
84#[implement(Clone, Copy)]
85#[transparent(Debug, Display, Serialize, Deserialize)]
86#[capability(inner_access, cloned)]
87pub enum DisplayNameTag {}
88
89pub struct BootOption<B: Bmc> {
93 data: Arc<BootOptionSchema>,
94 _marker: PhantomData<B>,
95}
96
97impl<B: Bmc> BootOption<B> {
98 pub(crate) async fn new(
100 bmc: &NvBmc<B>,
101 nav: &NavProperty<BootOptionSchema>,
102 ) -> Result<Self, Error<B>> {
103 nav.get(bmc.as_ref())
104 .await
105 .map_err(crate::Error::Bmc)
106 .map(|data| Self {
107 data,
108 _marker: PhantomData,
109 })
110 }
111
112 #[must_use]
114 pub fn raw(&self) -> Arc<BootOptionSchema> {
115 self.data.clone()
116 }
117
118 #[must_use]
121 pub fn boot_reference(&self) -> BootOptionReference<&str> {
122 BootOptionReference::new(self.id().inner())
123 }
124
125 #[must_use]
127 pub fn enabled(&self) -> Option<bool> {
128 self.data.boot_option_enabled.and_then(identity)
129 }
130
131 #[must_use]
134 pub fn display_name(&self) -> Option<DisplayName<&str>> {
135 self.data
136 .display_name
137 .as_ref()
138 .and_then(Option::as_ref)
139 .map(String::as_str)
140 .map(DisplayName::new)
141 }
142
143 #[must_use]
145 pub fn uefi_device_path(&self) -> Option<UefiDevicePath<&str>> {
146 self.data
147 .uefi_device_path
148 .as_ref()
149 .and_then(Option::as_ref)
150 .map(String::as_str)
151 .map(UefiDevicePath::new)
152 }
153}
154
155impl<B: Bmc> Resource for BootOption<B> {
156 fn resource_ref(&self) -> &ResourceSchema {
157 &self.data.as_ref().base
158 }
159}