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 self.data.boot_option_reference.as_deref().map_or_else(
123 || BootOptionReference::new(self.id().inner()),
124 BootOptionReference::new,
125 )
126 }
127
128 #[must_use]
130 pub fn enabled(&self) -> Option<bool> {
131 self.data.boot_option_enabled.and_then(identity)
132 }
133
134 #[must_use]
137 pub fn display_name(&self) -> Option<DisplayName<&str>> {
138 self.data
139 .display_name
140 .as_ref()
141 .and_then(Option::as_ref)
142 .map(String::as_str)
143 .map(DisplayName::new)
144 }
145
146 #[must_use]
148 pub fn uefi_device_path(&self) -> Option<UefiDevicePath<&str>> {
149 self.data
150 .uefi_device_path
151 .as_ref()
152 .and_then(Option::as_ref)
153 .map(String::as_str)
154 .map(UefiDevicePath::new)
155 }
156}
157
158impl<B: Bmc> Resource for BootOption<B> {
159 fn resource_ref(&self) -> &ResourceSchema {
160 &self.data.as_ref().base
161 }
162}