use std::sync::Arc;
use crate::core::client::{VimClient, Result};
#[derive(Clone)]
pub struct HostSpecificationManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl HostSpecificationManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
pub async fn delete_host_specification(&self, host: &crate::types::structs::ManagedObjectReference) -> Result<()> {
let input = DeleteHostSpecificationRequestType {host, };
self.client.invoke_void("", "HostSpecificationManager", &self.mo_id, "DeleteHostSpecification", Some(&input)).await
}
pub async fn delete_host_sub_specification(&self, host: &crate::types::structs::ManagedObjectReference, sub_spec_name: &str) -> Result<()> {
let input = DeleteHostSubSpecificationRequestType {host, sub_spec_name, };
self.client.invoke_void("", "HostSpecificationManager", &self.mo_id, "DeleteHostSubSpecification", Some(&input)).await
}
pub async fn host_spec_get_updated_hosts(&self, start_change_id: Option<&str>, end_change_id: Option<&str>) -> Result<Option<Vec<crate::types::structs::ManagedObjectReference>>> {
let input = HostSpecGetUpdatedHostsRequestType {start_change_id, end_change_id, };
let bytes_opt = self.client.invoke_optional("", "HostSpecificationManager", &self.mo_id, "HostSpecGetUpdatedHosts", Some(&input)).await?;
match bytes_opt {
Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
None => Ok(None),
}
}
pub async fn retrieve_host_specification(&self, host: &crate::types::structs::ManagedObjectReference, from_host: bool) -> Result<crate::types::structs::HostSpecification> {
let input = RetrieveHostSpecificationRequestType {host, from_host, };
let bytes = self.client.invoke("", "HostSpecificationManager", &self.mo_id, "RetrieveHostSpecification", Some(&input)).await?;
let result: crate::types::structs::HostSpecification = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
pub async fn update_host_specification(&self, host: &crate::types::structs::ManagedObjectReference, host_spec: &crate::types::structs::HostSpecification) -> Result<()> {
let input = UpdateHostSpecificationRequestType {host, host_spec, };
self.client.invoke_void("", "HostSpecificationManager", &self.mo_id, "UpdateHostSpecification", Some(&input)).await
}
pub async fn update_host_sub_specification(&self, host: &crate::types::structs::ManagedObjectReference, host_sub_spec: &crate::types::structs::HostSubSpecification) -> Result<()> {
let input = UpdateHostSubSpecificationRequestType {host, host_sub_spec, };
self.client.invoke_void("", "HostSpecificationManager", &self.mo_id, "UpdateHostSubSpecification", Some(&input)).await
}
}
struct DeleteHostSpecificationRequestType<'a> {
host: &'a crate::types::structs::ManagedObjectReference,
}
impl<'a> miniserde::Serialize for DeleteHostSpecificationRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(DeleteHostSpecificationRequestTypeSer { data: self, seq: 0 }))
}
}
struct DeleteHostSpecificationRequestTypeSer<'b, 'a> {
data: &'b DeleteHostSpecificationRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for DeleteHostSpecificationRequestTypeSer<'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"), &"DeleteHostSpecificationRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("host"), &self.data.host as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct DeleteHostSubSpecificationRequestType<'a> {
host: &'a crate::types::structs::ManagedObjectReference,
sub_spec_name: &'a str,
}
impl<'a> miniserde::Serialize for DeleteHostSubSpecificationRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(DeleteHostSubSpecificationRequestTypeSer { data: self, seq: 0 }))
}
}
struct DeleteHostSubSpecificationRequestTypeSer<'b, 'a> {
data: &'b DeleteHostSubSpecificationRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for DeleteHostSubSpecificationRequestTypeSer<'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"), &"DeleteHostSubSpecificationRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("host"), &self.data.host as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("subSpecName"), &self.data.sub_spec_name as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct HostSpecGetUpdatedHostsRequestType<'a> {
start_change_id: Option<&'a str>,
end_change_id: Option<&'a str>,
}
impl<'a> miniserde::Serialize for HostSpecGetUpdatedHostsRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(HostSpecGetUpdatedHostsRequestTypeSer { data: self, seq: 0 }))
}
}
struct HostSpecGetUpdatedHostsRequestTypeSer<'b, 'a> {
data: &'b HostSpecGetUpdatedHostsRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for HostSpecGetUpdatedHostsRequestTypeSer<'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"), &"HostSpecGetUpdatedHostsRequestType")),
1 => {
let Some(ref val) = self.data.start_change_id else { continue; };
return Some((std::borrow::Cow::Borrowed("startChangeID"), val as &dyn miniserde::Serialize));
}
2 => {
let Some(ref val) = self.data.end_change_id else { continue; };
return Some((std::borrow::Cow::Borrowed("endChangeID"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct RetrieveHostSpecificationRequestType<'a> {
host: &'a crate::types::structs::ManagedObjectReference,
from_host: bool,
}
impl<'a> miniserde::Serialize for RetrieveHostSpecificationRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(RetrieveHostSpecificationRequestTypeSer { data: self, seq: 0 }))
}
}
struct RetrieveHostSpecificationRequestTypeSer<'b, 'a> {
data: &'b RetrieveHostSpecificationRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for RetrieveHostSpecificationRequestTypeSer<'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"), &"RetrieveHostSpecificationRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("host"), &self.data.host as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("fromHost"), &self.data.from_host as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct UpdateHostSpecificationRequestType<'a> {
host: &'a crate::types::structs::ManagedObjectReference,
host_spec: &'a crate::types::structs::HostSpecification,
}
impl<'a> miniserde::Serialize for UpdateHostSpecificationRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(UpdateHostSpecificationRequestTypeSer { data: self, seq: 0 }))
}
}
struct UpdateHostSpecificationRequestTypeSer<'b, 'a> {
data: &'b UpdateHostSpecificationRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for UpdateHostSpecificationRequestTypeSer<'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"), &"UpdateHostSpecificationRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("host"), &self.data.host as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("hostSpec"), &self.data.host_spec as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct UpdateHostSubSpecificationRequestType<'a> {
host: &'a crate::types::structs::ManagedObjectReference,
host_sub_spec: &'a crate::types::structs::HostSubSpecification,
}
impl<'a> miniserde::Serialize for UpdateHostSubSpecificationRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(UpdateHostSubSpecificationRequestTypeSer { data: self, seq: 0 }))
}
}
struct UpdateHostSubSpecificationRequestTypeSer<'b, 'a> {
data: &'b UpdateHostSubSpecificationRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for UpdateHostSubSpecificationRequestTypeSer<'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"), &"UpdateHostSubSpecificationRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("host"), &self.data.host as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("hostSubSpec"), &self.data.host_sub_spec as &dyn miniserde::Serialize)),
_ => return None,
}
}
}