1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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 "client" subtree.
/// - System.Read on the root folder, if this is used to read all settings
/// or any settings beside those in the "client" 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,
}
}
}