Skip to main content

vim_rs/mo/
host_v_flash_manager.rs

1use std::sync::Arc;
2use crate::core::client::{VimClient, Result};
3/// The VFlash Manager object is used to configure vFlash resource
4/// and vFlash cache on the ESX host.
5#[derive(Clone)]
6pub struct HostVFlashManager {
7    client: Arc<dyn VimClient>,
8    mo_id: String,
9}
10impl HostVFlashManager {
11    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
12        Self {
13            client,
14            mo_id: mo_id.to_string(),
15        }
16    }
17    /// Configure vFlash cache on the host.
18    /// 
19    /// ***Required privileges:*** Host.Config.AdvancedConfig
20    ///
21    /// ## Parameters:
22    ///
23    /// ### spec
24    /// Specification for host cache configuration.
25    ///
26    /// ## Errors:
27    ///
28    /// ***HostConfigFault***: If the swap cache cannot be configured on the host.
29    /// 
30    /// ***InaccessibleVFlashSource***: vFlash resource is not accessible.
31    /// 
32    /// ***ResourceInUse***: The contained VFFS volume is being used.
33    pub async fn host_config_v_flash_cache(&self, spec: &crate::types::structs::HostVFlashManagerVFlashCacheConfigSpec) -> Result<()> {
34        let input = HostConfigVFlashCacheRequestType {spec, };
35        self.client.invoke_void("", "HostVFlashManager", &self.mo_id, "HostConfigVFlashCache", Some(&input)).await
36    }
37    /// Configure vFlash resource on the host by attaching to a backend VFFS volume.
38    /// 
39    /// ***Required privileges:*** Host.Config.Storage
40    ///
41    /// ## Parameters:
42    ///
43    /// ### spec
44    /// the vFlash resource specification.
45    ///
46    /// ## Errors:
47    ///
48    /// ***HostConfigFault***: If vFlash resource cannot be configured on the host
49    /// 
50    /// ***ResourceInUse***: The contained VFFS volume is being used.
51    pub async fn host_configure_v_flash_resource(&self, spec: &crate::types::structs::HostVFlashManagerVFlashResourceConfigSpec) -> Result<()> {
52        let input = HostConfigureVFlashResourceRequestType {spec, };
53        self.client.invoke_void("", "HostVFlashManager", &self.mo_id, "HostConfigureVFlashResource", Some(&input)).await
54    }
55    /// Configure vFlash resource on a list of SSD disks.
56    /// 
57    /// If the host does not have
58    /// a VFFS volume, host will format the volume first and then extend the volume
59    /// on the rest of the SSDs; otherwise host will extend the existing VFFS volume
60    /// on the passed SSDs. Finally host will configure the vFlash resource on the
61    /// VFFS volume.
62    /// 
63    /// It will return *HostVFlashResourceConfigurationResult*
64    /// describing success or failure associated with each device.
65    /// 
66    /// ***Required privileges:*** Host.Config.Storage
67    ///
68    /// ## Parameters:
69    ///
70    /// ### device_path
71    /// An array of device path names that identify disks.
72    /// See *ScsiDisk*.
73    ///
74    /// ## Returns:
75    ///
76    /// This method returns a *Task* object with which to monitor the
77    /// operation. The *info.result* property in the
78    /// *Task* contains *HostVFlashResourceConfigurationResult*
79    /// describing success or failure associated with each device.
80    /// 
81    /// Refers instance of *Task*.
82    ///
83    /// ## Errors:
84    ///
85    /// ***HostConfigFault***: if batch operation fails on the host.
86    /// Because the returned VFlashResourceConfigurationResult contains the configuration
87    /// success or fault for each device, as of vSphere API 5.x, we won't throw fault when
88    /// batch operation fails.
89    pub async fn configure_v_flash_resource_ex_task(&self, device_path: Option<&[String]>) -> Result<crate::types::structs::ManagedObjectReference> {
90        let input = ConfigureVFlashResourceExRequestType {device_path, };
91        let bytes = self.client.invoke("", "HostVFlashManager", &self.mo_id, "ConfigureVFlashResourceEx_Task", Some(&input)).await?;
92        let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
93        Ok(result)
94    }
95    /// Retrieve the default supported configuration for a given vFlash module
96    /// 
97    /// ***Required privileges:*** Host.Config.AdvancedConfig
98    ///
99    /// ## Parameters:
100    ///
101    /// ### v_flash_module
102    /// Name of the vFlash module
103    ///
104    /// ## Returns:
105    ///
106    /// The supported default vFlash cache configuration
107    ///
108    /// ## Errors:
109    ///
110    /// ***NotFound***: If vFlash resource is not configured or the contained VFFS volume
111    /// cannot be found on the host.
112    /// 
113    /// ***HostConfigFault***: If the default vFlash module configuration option cannot be
114    /// retrieved.
115    pub async fn host_get_v_flash_module_default_config(&self, v_flash_module: &str) -> Result<crate::types::structs::VirtualDiskVFlashCacheConfigInfo> {
116        let input = HostGetVFlashModuleDefaultConfigRequestType {v_flash_module, };
117        let bytes = self.client.invoke("", "HostVFlashManager", &self.mo_id, "HostGetVFlashModuleDefaultConfig", Some(&input)).await?;
118        let result: crate::types::structs::VirtualDiskVFlashCacheConfigInfo = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
119        Ok(result)
120    }
121    /// Remove vFlash resource on the host by destroying the contained VFFS volume.
122    /// 
123    /// ***Required privileges:*** Host.Config.Storage
124    ///
125    /// ## Errors:
126    ///
127    /// ***NotFound***: If vFlash resource is not configured or the contained VFFS volume
128    /// cannot be found on the host.
129    /// 
130    /// ***HostConfigFault***: If vFlash resource or the contained VFFS volume cannot
131    /// be removed from the host.
132    /// 
133    /// ***ResourceInUse***: The contained VFFS volume is being used.
134    pub async fn host_remove_v_flash_resource(&self) -> Result<()> {
135        self.client.invoke_void("", "HostVFlashManager", &self.mo_id, "HostRemoveVFlashResource", None).await
136    }
137    /// Host vFlash configuration information.
138    pub async fn v_flash_config_info(&self) -> Result<Option<crate::types::structs::HostVFlashManagerVFlashConfigInfo>> {
139        let pv_opt = self.client.fetch_property_raw("", "HostVFlashManager", &self.mo_id, "vFlashConfigInfo").await?;
140        match pv_opt {
141            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
142            None => Ok(None),
143        }
144    }
145}
146struct HostConfigVFlashCacheRequestType<'a> {
147    spec: &'a crate::types::structs::HostVFlashManagerVFlashCacheConfigSpec,
148}
149
150impl<'a> miniserde::Serialize for HostConfigVFlashCacheRequestType<'a> {
151    fn begin(&self) -> miniserde::ser::Fragment<'_> {
152        miniserde::ser::Fragment::Map(Box::new(HostConfigVFlashCacheRequestTypeSer { data: self, seq: 0 }))
153    }
154}
155
156struct HostConfigVFlashCacheRequestTypeSer<'b, 'a> {
157    data: &'b HostConfigVFlashCacheRequestType<'a>,
158    seq: usize,
159}
160
161impl<'b, 'a> miniserde::ser::Map for HostConfigVFlashCacheRequestTypeSer<'b, 'a> {
162    fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
163        let seq = self.seq;
164        self.seq += 1;
165        match seq {
166            0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"HostConfigVFlashCacheRequestType")),
167            1 => return Some((std::borrow::Cow::Borrowed("spec"), &self.data.spec as &dyn miniserde::Serialize)),
168            _ => return None,
169        }
170    }
171}
172struct HostConfigureVFlashResourceRequestType<'a> {
173    spec: &'a crate::types::structs::HostVFlashManagerVFlashResourceConfigSpec,
174}
175
176impl<'a> miniserde::Serialize for HostConfigureVFlashResourceRequestType<'a> {
177    fn begin(&self) -> miniserde::ser::Fragment<'_> {
178        miniserde::ser::Fragment::Map(Box::new(HostConfigureVFlashResourceRequestTypeSer { data: self, seq: 0 }))
179    }
180}
181
182struct HostConfigureVFlashResourceRequestTypeSer<'b, 'a> {
183    data: &'b HostConfigureVFlashResourceRequestType<'a>,
184    seq: usize,
185}
186
187impl<'b, 'a> miniserde::ser::Map for HostConfigureVFlashResourceRequestTypeSer<'b, 'a> {
188    fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
189        let seq = self.seq;
190        self.seq += 1;
191        match seq {
192            0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"HostConfigureVFlashResourceRequestType")),
193            1 => return Some((std::borrow::Cow::Borrowed("spec"), &self.data.spec as &dyn miniserde::Serialize)),
194            _ => return None,
195        }
196    }
197}
198struct ConfigureVFlashResourceExRequestType<'a> {
199    device_path: Option<&'a [String]>,
200}
201
202impl<'a> miniserde::Serialize for ConfigureVFlashResourceExRequestType<'a> {
203    fn begin(&self) -> miniserde::ser::Fragment<'_> {
204        miniserde::ser::Fragment::Map(Box::new(ConfigureVFlashResourceExRequestTypeSer { data: self, seq: 0 }))
205    }
206}
207
208struct ConfigureVFlashResourceExRequestTypeSer<'b, 'a> {
209    data: &'b ConfigureVFlashResourceExRequestType<'a>,
210    seq: usize,
211}
212
213impl<'b, 'a> miniserde::ser::Map for ConfigureVFlashResourceExRequestTypeSer<'b, 'a> {
214    fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
215        loop {
216            let seq = self.seq;
217            self.seq += 1;
218            match seq {
219                0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"ConfigureVFlashResourceExRequestType")),
220                1 => {
221                    let Some(ref val) = self.data.device_path else { continue; };
222                    return Some((std::borrow::Cow::Borrowed("devicePath"), val as &dyn miniserde::Serialize));
223                }
224                _ => return None,
225            }
226        }
227    }
228}
229struct HostGetVFlashModuleDefaultConfigRequestType<'a> {
230    v_flash_module: &'a str,
231}
232
233impl<'a> miniserde::Serialize for HostGetVFlashModuleDefaultConfigRequestType<'a> {
234    fn begin(&self) -> miniserde::ser::Fragment<'_> {
235        miniserde::ser::Fragment::Map(Box::new(HostGetVFlashModuleDefaultConfigRequestTypeSer { data: self, seq: 0 }))
236    }
237}
238
239struct HostGetVFlashModuleDefaultConfigRequestTypeSer<'b, 'a> {
240    data: &'b HostGetVFlashModuleDefaultConfigRequestType<'a>,
241    seq: usize,
242}
243
244impl<'b, 'a> miniserde::ser::Map for HostGetVFlashModuleDefaultConfigRequestTypeSer<'b, 'a> {
245    fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
246        let seq = self.seq;
247        self.seq += 1;
248        match seq {
249            0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"HostGetVFlashModuleDefaultConfigRequestType")),
250            1 => return Some((std::borrow::Cow::Borrowed("vFlashModule"), &self.data.v_flash_module as &dyn miniserde::Serialize)),
251            _ => return None,
252        }
253    }
254}