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};
/// This managed object type is used for managing key/value pair
/// options.
/// - You can define options on the fly only if the option is supported
///   by the concrete implementation, in a logical tree using a dot notation
///   for keys. For example, "Ethernet.Connection" describes the Connection
///   option as child of the Ethernet option.
/// - Options can be updated even if not visible in supportedOption or
///   settings or the queryMethod returned values only if supported by the
///   concrete implementation.
/// - Attempt to add random Options that are not supported by the concrete
///   implementation may result in unexpected side-effects.
/// - You can use the queryMethod to retrieve a single property or
///   a subset of properties based on the dot notation path.
#[derive(Clone)]
pub struct OptionManager {
    client: Arc<dyn VimClient>,
    mo_id: String,
}
impl OptionManager {
    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
        Self {
            client,
            mo_id: mo_id.to_string(),
        }
    }
    /// Returns a specific node or nodes in the option hierarchy.
    /// 
    /// This method might require any of the following privileges depending
    /// on where the property fits in the inventory tree.
    /// - System.View on the root folder, if this is used to read settings
    ///   in the &quot;client&quot; subtree.
    /// - System.Read on the root folder, if this is used to read all settings
    ///   or any settings beside those in the &quot;client&quot; subtree.
    /// - System.Read on the host, if this is used to read the advanced
    ///   options for a host configuration.
    ///   
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### name
    /// -
    ///
    /// ## Returns:
    ///
    /// The option with the given name. If the name ends with a
    /// dot, all options for that subtree are returned.
    ///
    /// ## Errors:
    ///
    /// ***InvalidName***: if no option or subtree exists with the
    /// given name.
    pub async fn query_options(&self, name: Option<&str>) -> Result<Option<Vec<Box<dyn crate::types::traits::OptionValueTrait>>>> {
        let input = QueryOptionsRequestType {name, };
        let bytes_opt = self.client.invoke_optional("", "OptionManager", &self.mo_id, "QueryOptions", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Updates one or more options.
    /// 
    /// The options are changed one by one, and the operation is not atomic.
    /// This means that on failure some of the options may not be changed.
    /// 
    /// A nested option setting can be named using a dot notation; for example,
    /// system.cacheSize.
    /// 
    /// This method might require any of the following privileges depending
    /// on where the property fits in the inventory tree.
    /// - Global.Settings on the root folder, if this is used to modify the
    ///   settings in the service node.
    /// - Host.Config.AdvancedConfig on the host, if this is used to set the
    ///   advanced options in the host configuration.
    ///
    /// ## Parameters:
    ///
    /// ### changed_value
    /// -
    ///
    /// ## Errors:
    ///
    /// ***InvalidName***: if one or more OptionValue objects refers to a
    /// non-existent option.
    /// 
    /// ***InvalidArgument***: if one or more OptionValue contains an
    /// invalid value.
    pub async fn update_options(&self, changed_value: &[Box<dyn crate::types::traits::OptionValueTrait>]) -> Result<()> {
        let input = UpdateOptionsRequestType {changed_value, };
        self.client.invoke_void("", "OptionManager", &self.mo_id, "UpdateOptions", Some(&input)).await
    }
    /// A list of the current settings for the key/value pair options.
    pub async fn setting(&self) -> Result<Option<Vec<Box<dyn crate::types::traits::OptionValueTrait>>>> {
        let pv_opt = self.client.fetch_property_raw("", "OptionManager", &self.mo_id, "setting").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
    /// A list of supported key/value pair options including their
    /// type information.
    pub async fn supported_option(&self) -> Result<Option<Vec<crate::types::structs::OptionDef>>> {
        let pv_opt = self.client.fetch_property_raw("", "OptionManager", &self.mo_id, "supportedOption").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
}
struct QueryOptionsRequestType<'a> {
    name: Option<&'a str>,
}

impl<'a> miniserde::Serialize for QueryOptionsRequestType<'a> {
    fn begin(&self) -> miniserde::ser::Fragment<'_> {
        miniserde::ser::Fragment::Map(Box::new(QueryOptionsRequestTypeSer { data: self, seq: 0 }))
    }
}

struct QueryOptionsRequestTypeSer<'b, 'a> {
    data: &'b QueryOptionsRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for QueryOptionsRequestTypeSer<'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"), &"QueryOptionsRequestType")),
                1 => {
                    let Some(ref val) = self.data.name else { continue; };
                    return Some((std::borrow::Cow::Borrowed("name"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct UpdateOptionsRequestType<'a> {
    changed_value: &'a [Box<dyn crate::types::traits::OptionValueTrait>],
}

impl<'a> miniserde::Serialize for UpdateOptionsRequestType<'a> {
    fn begin(&self) -> miniserde::ser::Fragment<'_> {
        miniserde::ser::Fragment::Map(Box::new(UpdateOptionsRequestTypeSer { data: self, seq: 0 }))
    }
}

struct UpdateOptionsRequestTypeSer<'b, 'a> {
    data: &'b UpdateOptionsRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for UpdateOptionsRequestTypeSer<'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"), &"UpdateOptionsRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("changedValue"), &self.data.changed_value as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}