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 Enabled = TaggedType<bool, EnabledTag>;
69#[doc(hidden)]
70#[derive(tagged_types::Tag)]
71#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
72#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
73#[capability(inner_access)]
74pub enum EnabledTag {}
75
76pub type UefiDevicePath<T> = TaggedType<T, UefiDevicePathTag>;
81#[doc(hidden)]
82#[derive(tagged_types::Tag)]
83#[implement(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
84#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
85#[capability(inner_access, cloned)]
86pub enum UefiDevicePathTag {}
87
88pub type DisplayName<T> = TaggedType<T, DisplayNameTag>;
91#[doc(hidden)]
92#[derive(tagged_types::Tag)]
93#[implement(Clone, Copy)]
94#[transparent(Debug, Display, Serialize, Deserialize)]
95#[capability(inner_access, cloned)]
96pub enum DisplayNameTag {}
97
98pub struct BootOption<B: Bmc> {
102 data: Arc<BootOptionSchema>,
103 _marker: PhantomData<B>,
104}
105
106impl<B: Bmc> BootOption<B> {
107 pub(crate) async fn new(
109 bmc: &NvBmc<B>,
110 nav: &NavProperty<BootOptionSchema>,
111 ) -> Result<Self, Error<B>> {
112 nav.get(bmc.as_ref())
113 .await
114 .map_err(crate::Error::Bmc)
115 .map(|data| Self {
116 data,
117 _marker: PhantomData,
118 })
119 }
120
121 #[must_use]
123 pub fn raw(&self) -> Arc<BootOptionSchema> {
124 self.data.clone()
125 }
126
127 #[must_use]
130 pub fn boot_reference(&self) -> BootOptionReference<&String> {
131 BootOptionReference::new(self.id().inner())
132 }
133
134 #[must_use]
136 pub fn enabled(&self) -> Option<Enabled> {
137 self.data
138 .boot_option_enabled
139 .and_then(identity)
140 .map(Enabled::new)
141 }
142
143 #[must_use]
146 pub fn display_name(&self) -> Option<DisplayName<&String>> {
147 self.data
148 .display_name
149 .as_ref()
150 .and_then(Option::as_ref)
151 .map(DisplayName::new)
152 }
153
154 #[must_use]
156 pub fn uefi_device_path(&self) -> Option<UefiDevicePath<&String>> {
157 self.data
158 .uefi_device_path
159 .as_ref()
160 .and_then(Option::as_ref)
161 .map(UefiDevicePath::new)
162 }
163}
164
165impl<B: Bmc> Resource for BootOption<B> {
166 fn resource_ref(&self) -> &ResourceSchema {
167 &self.data.as_ref().base
168 }
169}