vim_rs 0.4.4

Rust Bindings for the VMware by Broadcom vCenter VI JSON API
Documentation
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// The *HostSpecificationManager* provides the
/// functionality to update, restrieve and delete
/// *HostSpecification* and
/// *HostSubSpecification*.
#[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(),
        }
    }
    /// Delete the host specification of the specified host.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### host
    /// The specified host for which the specification will be
    /// deleted.
    /// 
    /// Refers instance of *HostSystem*.
    ///
    /// ## Errors:
    ///
    /// ***HostSpecificationOperationFailed***: If the method fails when delete
    /// the spec.
    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
    }
    /// Delete the host sub specification specified by the provided <code>
    /// subSpecname</code> of the specified host.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### host
    /// The specified host for which the sub specification will be
    /// deleted.
    /// 
    /// Refers instance of *HostSystem*.
    ///
    /// ### sub_spec_name
    /// The name of the host sub specification to be deleted.
    ///
    /// ## Errors:
    ///
    /// ***HostSpecificationOperationFailed***: If the method fails when delete
    /// the sub spec.
    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
    }
    /// Query the hosts whose specification was updated in the specified
    /// time period.
    /// 
    /// When the <code>startChangeID</code> isn't provided, it will
    /// return all the host updated before the <code>endChangeID</code>. When the
    /// <code>endChangeID</code> isn't provided, it will return all the hosts
    /// updated after <code>startChangeID</code>. If both aren't provided, all
    /// hosts having host spec will be returned.
    /// The format of the change ID is defined at
    /// *HostSpecification.changeID*.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### start_change_id
    /// The beginning of the time period.
    ///
    /// ### end_change_id
    /// The ending of the time period.
    ///
    /// ## Returns:
    ///
    /// The queried host list.
    /// 
    /// Refers instances of *HostSystem*.
    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),
        }
    }
    /// Retrieve the host specification.
    /// 
    /// When the parameter <code>fromHost</code>
    /// is <code>true</code>, the host specification is retrieved from the host;
    /// otherwise, it is from the host specification "database" for this manager.
    /// When retrieved from host, the copy in host specification "database" will
    /// be updated. On success, it will fire a
    /// <code>HostSpecificationChangedEvent</code>.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### host
    /// The specified host whose host specification will be retrieved.
    /// 
    /// Refers instance of *HostSystem*.
    ///
    /// ### from_host
    /// Whether retrieve from the host.
    ///
    /// ## Returns:
    ///
    /// The host specification of the specified host.
    ///
    /// ## Errors:
    ///
    /// ***HostSpecificationOperationFailed***: If the method fails when retrieve
    /// from host.
    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)
    }
    /// Update the host specification with the provided copy.
    /// 
    /// If there is no host specification for the host, create the host
    /// specification for this host in the host specification "database";
    /// otherwise, update the host specification with the provided.
    /// *HostSpecification* object.
    /// On success, it will fire a <code>HostSpecificationChangedEvent</code>.
    /// 
    /// ***Required privileges:*** Profile.Edit
    ///
    /// ## Parameters:
    ///
    /// ### host
    /// The host whose specification will be updated.
    /// 
    /// Refers instance of *HostSystem*.
    ///
    /// ### host_spec
    /// The new host specification to be updated with.
    ///
    /// ## Errors:
    ///
    /// ***HostSpecificationOperationFailed***: If the method fails.
    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
    }
    /// Update the host specification with the provided host sub specification.
    /// 
    /// If there is no host specification for the host, create the host
    /// specification, which contains only the provided host sub specification,
    /// for this host; otherwise, add or update the host specification with the
    /// provided *HostSubSpecification* object.
    /// This method provides a way to incrementally build the host specification.
    /// On success, it will fire a <code>HostSpecificationChangedEvent</code>.
    /// 
    /// ***Required privileges:*** Profile.Edit
    ///
    /// ## Parameters:
    ///
    /// ### host
    /// The host whose specification will be updated.
    /// 
    /// Refers instance of *HostSystem*.
    ///
    /// ### host_sub_spec
    /// The data object for the new host sub specification.
    ///
    /// ## Errors:
    ///
    /// ***HostSpecificationOperationFailed***: If the method fails.
    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,
        }
    }
}