vim_rs 0.4.4

Rust Bindings for the VMware by Broadcom vCenter VI JSON API
Documentation
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// ProcessManager is the managed object that provides APIs
/// to manipulate the guest operating system processes.
#[derive(Clone)]
pub struct GuestProcessManager {
    client: Arc<dyn VimClient>,
    mo_id: String,
}
impl GuestProcessManager {
    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
        Self {
            client,
            mo_id: mo_id.to_string(),
        }
    }
    /// List the processes running in the guest operating system,
    /// plus those started by *GuestProcessManager.StartProgramInGuest*
    /// that have recently completed.
    ///
    /// ## Parameters:
    ///
    /// ### vm
    /// Virtual machine to perform the operation on.
    /// 
    /// ***Required privileges:*** VirtualMachine.GuestOperations.Query
    /// 
    /// Refers instance of *VirtualMachine*.
    ///
    /// ### auth
    /// The guest authentication data. See
    /// *GuestAuthentication*.
    ///
    /// ### pids
    /// If set, only return information about the specified processes.
    /// Otherwise, information about all processes are returned.
    /// If a specified processes does not exist, nothing will
    /// be returned for that process.
    ///
    /// ## Returns:
    ///
    /// The list running processes is returned in an array of
    /// *GuestProcessInfo* structures.
    ///
    /// ## Errors:
    ///
    /// ***GuestOperationsFault***: if there is an error processing a guest
    /// operation.
    /// 
    /// ***GuestOperationsUnavailable***: if the VM agent for guest operations
    /// is not running.
    /// 
    /// ***InvalidPowerState***: if the VM is not powered on.
    /// 
    /// ***InvalidState***: if the operation cannot be performed because of the
    /// virtual machine's current state.
    /// 
    /// ***TaskInProgress***: if the virtual machine is busy.
    /// 
    /// ***GuestPermissionDenied***: if there are insufficient permissions in
    /// the guest OS.
    /// 
    /// ***InvalidGuestLogin***: if the the guest authentication information
    /// was not accepted.
    /// 
    /// ***GuestComponentsOutOfDate***: if the guest agent is too old to support
    /// the operation.
    /// 
    /// ***OperationNotSupportedByGuest***: if the operation is not supported
    /// by the guest OS.
    /// 
    /// ***OperationDisabledByGuest***: if the operation is not enabled due to
    /// guest agent configuration.
    pub async fn list_processes_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait, pids: Option<&[i64]>) -> Result<Option<Vec<crate::types::structs::GuestProcessInfo>>> {
        let input = ListProcessesInGuestRequestType {vm, auth, pids, };
        let bytes_opt = self.client.invoke_optional("", "GuestProcessManager", &self.mo_id, "ListProcessesInGuest", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Reads an environment variable from the guest OS
    /// 
    /// If the authentication uses interactiveSession, then the
    /// environment being read will be that of the user logged into the desktop.
    /// Otherwise it's the environment of the user specified by the auth.
    ///
    /// ## Parameters:
    ///
    /// ### vm
    /// Virtual machine to perform the operation on.
    /// 
    /// ***Required privileges:*** VirtualMachine.GuestOperations.Query
    /// 
    /// Refers instance of *VirtualMachine*.
    ///
    /// ### auth
    /// The guest authentication data. See
    /// *GuestAuthentication*.
    ///
    /// ### names
    /// The names of the variables to be read. If not set, then
    /// all the environment variables are returned.
    ///
    /// ## Returns:
    ///
    /// A string array containing the value of the variables,
    /// or all environment variables if nothing is specified.
    /// The format of each string is "name=value".
    /// If any specified environment variable isn't set, then nothing is
    /// returned for that variable.
    ///
    /// ## Errors:
    ///
    /// ***GuestOperationsFault***: if there is an error processing a guest
    /// operation.
    /// 
    /// ***GuestOperationsUnavailable***: if the VM agent for guest operations
    /// is not running.
    /// 
    /// ***InvalidPowerState***: if the VM is not powered on.
    /// 
    /// ***InvalidState***: if the operation cannot be performed because of the
    /// virtual machine's current state.
    /// 
    /// ***TaskInProgress***: if the virtual machine is busy.
    /// accepted by the guest OS.
    /// 
    /// ***GuestPermissionDenied***: if there are insufficient permissions in
    /// the guest OS.
    /// 
    /// ***InvalidGuestLogin***: if the the guest authentication information
    /// was not accepted.
    /// 
    /// ***GuestComponentsOutOfDate***: if the guest agent is too old to support
    /// the operation.
    /// 
    /// ***OperationNotSupportedByGuest***: if the operation is not supported
    /// by the guest OS.
    /// 
    /// ***OperationDisabledByGuest***: if the operation is not enabled due to
    /// guest agent configuration.
    pub async fn read_environment_variable_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait, names: Option<&[String]>) -> Result<Option<Vec<String>>> {
        let input = ReadEnvironmentVariableInGuestRequestType {vm, auth, names, };
        let bytes_opt = self.client.invoke_optional("", "GuestProcessManager", &self.mo_id, "ReadEnvironmentVariableInGuest", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Starts a program in the guest operating system.
    /// 
    /// A process started this way can have its status queried with
    /// *GuestProcessManager.ListProcessesInGuest*.
    /// When the process completes, its exit code and end time will be
    /// available for 5 minutes after completion.
    /// 
    /// If VMware Tools is restarted, the exit code and end time will not
    /// be available.
    ///
    /// ## Parameters:
    ///
    /// ### vm
    /// Virtual machine to perform the operation on.
    /// 
    /// ***Required privileges:*** VirtualMachine.GuestOperations.Execute
    /// 
    /// Refers instance of *VirtualMachine*.
    ///
    /// ### auth
    /// The guest authentication data. See
    /// *GuestAuthentication*.
    ///
    /// ### spec
    /// The arguments describing the program to be started.
    ///
    /// ## Returns:
    ///
    /// The pid of the program started.
    ///
    /// ## Errors:
    ///
    /// ***GuestOperationsFault***: if there is an error processing a guest
    /// operation.
    /// 
    /// ***GuestOperationsUnavailable***: if the VM agent for guest operations
    /// is not running.
    /// 
    /// ***InvalidPowerState***: if the VM is not powered on.
    /// 
    /// ***InvalidState***: if the operation cannot be performed because of the
    /// virtual machine's current state.
    /// 
    /// ***TaskInProgress***: if the virtual machine is busy.
    /// 
    /// ***FileNotFound***: if the program path does not exist.
    /// 
    /// ***FileFault***: if there is a file error in the guest operating system.
    /// 
    /// ***CannotAccessFile***: if the program path cannot be accessed.
    /// 
    /// ***GuestPermissionDenied***: if the program path cannot be run because
    /// the guest authentication will not allow the operation.
    /// 
    /// ***InvalidGuestLogin***: if the the guest authentication information
    /// was not accepted.
    /// 
    /// ***GuestComponentsOutOfDate***: if the guest agent is too old to support
    /// the operation.
    /// 
    /// ***OperationNotSupportedByGuest***: if the operation is not supported by
    /// the guest OS.
    /// 
    /// ***OperationDisabledByGuest***: if the operation is not enabled due to
    /// guest agent configuration.
    pub async fn start_program_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait, spec: &dyn crate::types::traits::GuestProgramSpecTrait) -> Result<i64> {
        let input = StartProgramInGuestRequestType {vm, auth, spec, };
        let bytes = self.client.invoke("", "GuestProcessManager", &self.mo_id, "StartProgramInGuest", Some(&input)).await?;
        let result: i64 = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Terminates a process in the guest OS.
    ///
    /// ## Parameters:
    ///
    /// ### vm
    /// Virtual machine to perform the operation on.
    /// 
    /// ***Required privileges:*** VirtualMachine.GuestOperations.Execute
    /// 
    /// Refers instance of *VirtualMachine*.
    ///
    /// ### auth
    /// The guest authentication data. See
    /// *GuestAuthentication*.
    ///
    /// ### pid
    /// Process ID of the process to be terminated
    ///
    /// ## Errors:
    ///
    /// ***GuestOperationsFault***: if there is an error processing a guest
    /// operation.
    /// 
    /// ***GuestOperationsUnavailable***: if the VM agent for guest operations
    /// is not running.
    /// 
    /// ***InvalidPowerState***: if the VM is not powered on.
    /// 
    /// ***InvalidState***: if the operation cannot be performed because of the
    /// virtual machine's current state.
    /// 
    /// ***GuestProcessNotFound***: if the pid does not refer to a valid process.
    /// 
    /// ***TaskInProgress***: if the virtual machine is busy.
    /// 
    /// ***GuestPermissionDenied***: if the process cannot be terminated because
    /// the guest authentication will not allow the operation.
    /// 
    /// ***InvalidGuestLogin***: if the the guest authentication information
    /// was not accepted.
    /// 
    /// ***GuestComponentsOutOfDate***: if the guest agent is too old to
    /// support the operation.
    /// 
    /// ***OperationNotSupportedByGuest***: if the operation is not supported
    /// by the guest OS.
    /// 
    /// ***OperationDisabledByGuest***: if the operation is not enabled due
    /// to guest agent configuration.
    pub async fn terminate_process_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait, pid: i64) -> Result<()> {
        let input = TerminateProcessInGuestRequestType {vm, auth, pid, };
        self.client.invoke_void("", "GuestProcessManager", &self.mo_id, "TerminateProcessInGuest", Some(&input)).await
    }
}
struct ListProcessesInGuestRequestType<'a> {
    vm: &'a crate::types::structs::ManagedObjectReference,
    auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
    pids: Option<&'a [i64]>,
}

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

struct ListProcessesInGuestRequestTypeSer<'b, 'a> {
    data: &'b ListProcessesInGuestRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for ListProcessesInGuestRequestTypeSer<'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"), &"ListProcessesInGuestRequestType")),
                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 => {
                    let Some(ref val) = self.data.pids else { continue; };
                    return Some((std::borrow::Cow::Borrowed("pids"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct ReadEnvironmentVariableInGuestRequestType<'a> {
    vm: &'a crate::types::structs::ManagedObjectReference,
    auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
    names: Option<&'a [String]>,
}

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

struct ReadEnvironmentVariableInGuestRequestTypeSer<'b, 'a> {
    data: &'b ReadEnvironmentVariableInGuestRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for ReadEnvironmentVariableInGuestRequestTypeSer<'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"), &"ReadEnvironmentVariableInGuestRequestType")),
                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 => {
                    let Some(ref val) = self.data.names else { continue; };
                    return Some((std::borrow::Cow::Borrowed("names"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct StartProgramInGuestRequestType<'a> {
    vm: &'a crate::types::structs::ManagedObjectReference,
    auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
    spec: &'a dyn crate::types::traits::GuestProgramSpecTrait,
}

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

struct StartProgramInGuestRequestTypeSer<'b, 'a> {
    data: &'b StartProgramInGuestRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for StartProgramInGuestRequestTypeSer<'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"), &"StartProgramInGuestRequestType")),
            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)),
            _ => return None,
        }
    }
}
struct TerminateProcessInGuestRequestType<'a> {
    vm: &'a crate::types::structs::ManagedObjectReference,
    auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
    pid: i64,
}

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

struct TerminateProcessInGuestRequestTypeSer<'b, 'a> {
    data: &'b TerminateProcessInGuestRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for TerminateProcessInGuestRequestTypeSer<'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"), &"TerminateProcessInGuestRequestType")),
            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("pid"), &self.data.pid as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}