use std::sync::Arc;
use crate::core::client::{VimClient, Result};
#[derive(Clone)]
pub struct HostVFlashManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl HostVFlashManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
pub async fn host_config_v_flash_cache(&self, spec: &crate::types::structs::HostVFlashManagerVFlashCacheConfigSpec) -> Result<()> {
let input = HostConfigVFlashCacheRequestType {spec, };
self.client.invoke_void("", "HostVFlashManager", &self.mo_id, "HostConfigVFlashCache", Some(&input)).await
}
pub async fn host_configure_v_flash_resource(&self, spec: &crate::types::structs::HostVFlashManagerVFlashResourceConfigSpec) -> Result<()> {
let input = HostConfigureVFlashResourceRequestType {spec, };
self.client.invoke_void("", "HostVFlashManager", &self.mo_id, "HostConfigureVFlashResource", Some(&input)).await
}
pub async fn configure_v_flash_resource_ex_task(&self, device_path: Option<&[String]>) -> Result<crate::types::structs::ManagedObjectReference> {
let input = ConfigureVFlashResourceExRequestType {device_path, };
let bytes = self.client.invoke("", "HostVFlashManager", &self.mo_id, "ConfigureVFlashResourceEx_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
pub async fn host_get_v_flash_module_default_config(&self, v_flash_module: &str) -> Result<crate::types::structs::VirtualDiskVFlashCacheConfigInfo> {
let input = HostGetVFlashModuleDefaultConfigRequestType {v_flash_module, };
let bytes = self.client.invoke("", "HostVFlashManager", &self.mo_id, "HostGetVFlashModuleDefaultConfig", Some(&input)).await?;
let result: crate::types::structs::VirtualDiskVFlashCacheConfigInfo = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
pub async fn host_remove_v_flash_resource(&self) -> Result<()> {
self.client.invoke_void("", "HostVFlashManager", &self.mo_id, "HostRemoveVFlashResource", None).await
}
pub async fn v_flash_config_info(&self) -> Result<Option<crate::types::structs::HostVFlashManagerVFlashConfigInfo>> {
let pv_opt = self.client.fetch_property_raw("", "HostVFlashManager", &self.mo_id, "vFlashConfigInfo").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
}
struct HostConfigVFlashCacheRequestType<'a> {
spec: &'a crate::types::structs::HostVFlashManagerVFlashCacheConfigSpec,
}
impl<'a> miniserde::Serialize for HostConfigVFlashCacheRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(HostConfigVFlashCacheRequestTypeSer { data: self, seq: 0 }))
}
}
struct HostConfigVFlashCacheRequestTypeSer<'b, 'a> {
data: &'b HostConfigVFlashCacheRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for HostConfigVFlashCacheRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"HostConfigVFlashCacheRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("spec"), &self.data.spec as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct HostConfigureVFlashResourceRequestType<'a> {
spec: &'a crate::types::structs::HostVFlashManagerVFlashResourceConfigSpec,
}
impl<'a> miniserde::Serialize for HostConfigureVFlashResourceRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(HostConfigureVFlashResourceRequestTypeSer { data: self, seq: 0 }))
}
}
struct HostConfigureVFlashResourceRequestTypeSer<'b, 'a> {
data: &'b HostConfigureVFlashResourceRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for HostConfigureVFlashResourceRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"HostConfigureVFlashResourceRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("spec"), &self.data.spec as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct ConfigureVFlashResourceExRequestType<'a> {
device_path: Option<&'a [String]>,
}
impl<'a> miniserde::Serialize for ConfigureVFlashResourceExRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(ConfigureVFlashResourceExRequestTypeSer { data: self, seq: 0 }))
}
}
struct ConfigureVFlashResourceExRequestTypeSer<'b, 'a> {
data: &'b ConfigureVFlashResourceExRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for ConfigureVFlashResourceExRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"ConfigureVFlashResourceExRequestType")),
1 => {
let Some(ref val) = self.data.device_path else { continue; };
return Some((std::borrow::Cow::Borrowed("devicePath"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct HostGetVFlashModuleDefaultConfigRequestType<'a> {
v_flash_module: &'a str,
}
impl<'a> miniserde::Serialize for HostGetVFlashModuleDefaultConfigRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(HostGetVFlashModuleDefaultConfigRequestTypeSer { data: self, seq: 0 }))
}
}
struct HostGetVFlashModuleDefaultConfigRequestTypeSer<'b, 'a> {
data: &'b HostGetVFlashModuleDefaultConfigRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for HostGetVFlashModuleDefaultConfigRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"HostGetVFlashModuleDefaultConfigRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("vFlashModule"), &self.data.v_flash_module as &dyn miniserde::Serialize)),
_ => return None,
}
}
}