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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// GuestCustomizationManager is a singleton managed object that provides APIs
/// for guest customization of a running VM.
#[derive(Clone)]
pub struct VirtualMachineGuestCustomizationManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl VirtualMachineGuestCustomizationManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Abort any running guest customization process in the guest and remove
/// the guest customization lock in the guest as well.
///
/// As a result of the
/// operation, the guest configuration may be left in an undefined state,
/// which is however fine because guest customization is idempotent.
/// A later successful guest customization can set the guest configuration
/// to a valid state.
/// The virtual machine must be in the powered-on state and the VMware Tools
/// must be running.
/// The VM is typically a cloned VM after the InstantClone operation. See
/// *VirtualMachine.InstantClone_Task*.
///
/// ***Required privileges:*** VirtualMachine.Provisioning.Customize
///
/// ## Parameters:
///
/// ### vm
/// The Virtual Machine managed object reference.
///
/// Refers instance of *VirtualMachine*.
///
/// ### auth
/// The guest authentication data. See
/// *GuestAuthentication*.
///
/// ## Returns:
///
/// This method returns a *Task* object with which to monitor
/// the operation.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***TaskInProgress***: if the virtual machine is busy.
///
/// ***InvalidPowerState***: if the VM is not powered on.
///
/// ***InvalidState***: if the operation cannot be performed because of the
/// virtual machine's current state. For example, if the VMware
/// Tools is not running.
///
/// ***InvalidGuestLogin***: if the the guest authentication information
/// was not accepted.
///
/// ***GuestPermissionDenied***: if the provided guest authentication
/// is not sufficient to perform the guest customization.
///
/// ***CustomizationFault***: if a customization error occurs.
pub async fn abort_customization_task(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait) -> Result<crate::types::structs::ManagedObjectReference> {
let input = AbortCustomizationRequestType {vm, auth, };
let bytes = self.client.invoke("", "VirtualMachineGuestCustomizationManager", &self.mo_id, "AbortCustomization_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Customize a running virtual machine.
///
/// The virtual machine must be in the powered-on state and the VMware Tools
/// must be running.
/// The VM is typically a cloned VM after the InstantClone operation. See
/// *VirtualMachine.InstantClone_Task*.
///
/// ***Required privileges:*** VirtualMachine.Provisioning.Customize
///
/// ## Parameters:
///
/// ### vm
/// The Virtual Machine managed object reference.
///
/// Refers instance of *VirtualMachine*.
///
/// ### auth
/// The guest authentication data. See
/// *GuestAuthentication*.
///
/// ### spec
/// Is a *CustomizationSpec*.
/// It specifies the virtual machine's configuration.
///
/// ### config_params
/// addtional key/value pair list to support
/// third party customization.
///
/// ## Returns:
///
/// This method returns a *Task* object with which to monitor
/// the operation.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***TaskInProgress***: if the virtual machine is busy.
///
/// ***InvalidPowerState***: if the VM is not powered on.
///
/// ***InvalidState***: if the operation cannot be performed because of the
/// virtual machine's current state. For example, if the VMware
/// Tools is not running.
///
/// ***InvalidGuestLogin***: if the the guest authentication information
/// was not accepted.
///
/// ***GuestPermissionDenied***: if the provided guest authentication
/// is not sufficient to perform the guest customization.
///
/// ***CustomizationFault***: if a customization error occurs.
pub async fn customize_guest_task(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait, spec: &crate::types::structs::CustomizationSpec, config_params: Option<&[Box<dyn crate::types::traits::OptionValueTrait>]>) -> Result<crate::types::structs::ManagedObjectReference> {
let input = CustomizeGuestRequestType {vm, auth, spec, config_params, };
let bytes = self.client.invoke("", "VirtualMachineGuestCustomizationManager", &self.mo_id, "CustomizeGuest_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Start the network service in the guest, e.g.
///
/// acquire IPs from DHCP.
/// The virtual machine must be in the powered-on state and the VMware Tools
/// must be running.
/// The VM is typically a cloned VM after the InstantClone operation. See
/// *VirtualMachine.InstantClone_Task*.
///
/// ***Required privileges:*** VirtualMachine.Provisioning.Customize
///
/// ## Parameters:
///
/// ### vm
/// The Virtual Machine managed object reference.
///
/// Refers instance of *VirtualMachine*.
///
/// ### auth
/// The guest authentication data. See
/// *GuestAuthentication*.
///
/// ## Returns:
///
/// This method returns a *Task* object with which to monitor
/// the operation.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***TaskInProgress***: if the virtual machine is busy.
///
/// ***InvalidPowerState***: if the VM is not powered on.
///
/// ***InvalidState***: if the operation cannot be performed because of the
/// virtual machine's current state. For example, if the VMware
/// Tools is not running.
///
/// ***InvalidGuestLogin***: if the the guest authentication information
/// was not accepted.
///
/// ***GuestPermissionDenied***: if the provided guest authentication
/// is not sufficient to perform the guest customization.
///
/// ***CustomizationFault***: if a customization error occurs.
pub async fn start_guest_network_task(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait) -> Result<crate::types::structs::ManagedObjectReference> {
let input = StartGuestNetworkRequestType {vm, auth, };
let bytes = self.client.invoke("", "VirtualMachineGuestCustomizationManager", &self.mo_id, "StartGuestNetwork_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
}
struct AbortCustomizationRequestType<'a> {
vm: &'a crate::types::structs::ManagedObjectReference,
auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
}
impl<'a> miniserde::Serialize for AbortCustomizationRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(AbortCustomizationRequestTypeSer { data: self, seq: 0 }))
}
}
struct AbortCustomizationRequestTypeSer<'b, 'a> {
data: &'b AbortCustomizationRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for AbortCustomizationRequestTypeSer<'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"), &"AbortCustomizationRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("vm"), &self.data.vm as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("auth"), &self.data.auth as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct CustomizeGuestRequestType<'a> {
vm: &'a crate::types::structs::ManagedObjectReference,
auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
spec: &'a crate::types::structs::CustomizationSpec,
config_params: Option<&'a [Box<dyn crate::types::traits::OptionValueTrait>]>,
}
impl<'a> miniserde::Serialize for CustomizeGuestRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(CustomizeGuestRequestTypeSer { data: self, seq: 0 }))
}
}
struct CustomizeGuestRequestTypeSer<'b, 'a> {
data: &'b CustomizeGuestRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for CustomizeGuestRequestTypeSer<'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"), &"CustomizeGuestRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("vm"), &self.data.vm as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("auth"), &self.data.auth as &dyn miniserde::Serialize)),
3 => return Some((std::borrow::Cow::Borrowed("spec"), &self.data.spec as &dyn miniserde::Serialize)),
4 => {
let Some(ref val) = self.data.config_params else { continue; };
return Some((std::borrow::Cow::Borrowed("configParams"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct StartGuestNetworkRequestType<'a> {
vm: &'a crate::types::structs::ManagedObjectReference,
auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
}
impl<'a> miniserde::Serialize for StartGuestNetworkRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(StartGuestNetworkRequestTypeSer { data: self, seq: 0 }))
}
}
struct StartGuestNetworkRequestTypeSer<'b, 'a> {
data: &'b StartGuestNetworkRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for StartGuestNetworkRequestTypeSer<'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"), &"StartGuestNetworkRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("vm"), &self.data.vm as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("auth"), &self.data.auth as &dyn miniserde::Serialize)),
_ => return None,
}
}
}