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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// AuthManager is the managed object that provides APIs
/// to manipulate the guest operating authentication.
#[derive(Clone)]
pub struct GuestAuthManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl GuestAuthManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Authenticates in the guest and returns a *GuestAuthentication* object
/// with the acquired credentials for use in subsequent guest operation calls.
///
/// This can be used to authenticate inside the guest and obtain a
/// *GuestAuthentication* object for supported authentication types.
/// This operation is not needed for Name and Password Authentication. To use
/// Name and Password Authentication, see *NamePasswordAuthentication*.
/// For SSPI authentication, requestAuth should be of the type *SSPIAuthentication*.
///
/// ## Parameters:
///
/// ### vm
/// MoRef of the VM to perform the operation on.
///
/// ***Required privileges:*** VirtualMachine.GuestOperations.Query
///
/// Refers instance of *VirtualMachine*.
///
/// ### requested_auth
/// The guest authentication data used to acquire credentials.
/// See *GuestAuthentication*.
///
/// ### session_id
/// The sessionID number should be provided only when
/// responding to a server challenge. The sessionID number to be used with
/// the challenge is found in the
/// *GuestAuthenticationChallenge* object.
///
/// ## Returns:
///
/// Returns a *GuestAuthentication* object that can be used in
/// guest operation calls.
///
/// ## 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.
///
/// ***GuestAuthenticationChallenge***: if the credential information
/// provided requires a challenge to authenticate.
///
/// ***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.
///
/// ***TooManyGuestLogons***: if there are too many concurrent login
/// sessions active in the guest.
///
/// ***InvalidGuestLogin***: if the the guest authentication information
/// was not accepted.
pub async fn acquire_credentials_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, requested_auth: &dyn crate::types::traits::GuestAuthenticationTrait, session_id: Option<i64>) -> Result<Box<dyn crate::types::traits::GuestAuthenticationTrait>> {
let input = AcquireCredentialsInGuestRequestType {vm, requested_auth, session_id, };
let bytes = self.client.invoke("", "GuestAuthManager", &self.mo_id, "AcquireCredentialsInGuest", Some(&input)).await?;
let result: Box<dyn crate::types::traits::GuestAuthenticationTrait> = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Releases session data and resources associated with
/// a *GuestAuthentication* object returned by *GuestAuthManager.AcquireCredentialsInGuest*.
///
/// This frees any resources and session data associated with a
/// *GuestAuthentication* object returned by *GuestAuthManager.AcquireCredentialsInGuest*.
/// The *GuestAuthentication* object can no longer be used to
/// authenticate in the guest once released. Currently this operation is only
/// valid for *TicketedSessionAuthentication* objects.
///
/// ## Parameters:
///
/// ### vm
/// MoRef of the VM to perform the operation on.
///
/// ***Required privileges:*** VirtualMachine.GuestOperations.Query
///
/// Refers instance of *VirtualMachine*.
///
/// ### auth
/// The guest authentication data. See
/// *GuestAuthentication*.
///
/// ## 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.
///
/// ***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.
///
/// ***InvalidGuestLogin***: if the the guest authentication information
/// was not accepted.
pub async fn release_credentials_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait) -> Result<()> {
let input = ReleaseCredentialsInGuestRequestType {vm, auth, };
self.client.invoke_void("", "GuestAuthManager", &self.mo_id, "ReleaseCredentialsInGuest", Some(&input)).await
}
/// Validates the *GuestAuthentication* credentials.
///
/// This can be used to check the authentication data, or
/// validate any authentication that has a timeout is still valid.
/// If the authentication is not valid, *GuestPermissionDenied*
/// will be thrown.
///
/// ## Parameters:
///
/// ### vm
/// MoRef of the VM to perform the operation on.
///
/// ***Required privileges:*** VirtualMachine.GuestOperations.Query
///
/// Refers instance of *VirtualMachine*.
///
/// ### auth
/// The guest authentication data. See
/// *GuestAuthentication*.
///
/// ## 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.
///
/// ***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.
///
/// ***InvalidGuestLogin***: if the the guest authentication information
/// was not accepted.
pub async fn validate_credentials_in_guest(&self, vm: &crate::types::structs::ManagedObjectReference, auth: &dyn crate::types::traits::GuestAuthenticationTrait) -> Result<()> {
let input = ValidateCredentialsInGuestRequestType {vm, auth, };
self.client.invoke_void("", "GuestAuthManager", &self.mo_id, "ValidateCredentialsInGuest", Some(&input)).await
}
}
struct AcquireCredentialsInGuestRequestType<'a> {
vm: &'a crate::types::structs::ManagedObjectReference,
requested_auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
session_id: Option<i64>,
}
impl<'a> miniserde::Serialize for AcquireCredentialsInGuestRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(AcquireCredentialsInGuestRequestTypeSer { data: self, seq: 0 }))
}
}
struct AcquireCredentialsInGuestRequestTypeSer<'b, 'a> {
data: &'b AcquireCredentialsInGuestRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for AcquireCredentialsInGuestRequestTypeSer<'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"), &"AcquireCredentialsInGuestRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("vm"), &self.data.vm as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("requestedAuth"), &self.data.requested_auth as &dyn miniserde::Serialize)),
3 => {
let Some(ref val) = self.data.session_id else { continue; };
return Some((std::borrow::Cow::Borrowed("sessionID"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct ReleaseCredentialsInGuestRequestType<'a> {
vm: &'a crate::types::structs::ManagedObjectReference,
auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
}
impl<'a> miniserde::Serialize for ReleaseCredentialsInGuestRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(ReleaseCredentialsInGuestRequestTypeSer { data: self, seq: 0 }))
}
}
struct ReleaseCredentialsInGuestRequestTypeSer<'b, 'a> {
data: &'b ReleaseCredentialsInGuestRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for ReleaseCredentialsInGuestRequestTypeSer<'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"), &"ReleaseCredentialsInGuestRequestType")),
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 ValidateCredentialsInGuestRequestType<'a> {
vm: &'a crate::types::structs::ManagedObjectReference,
auth: &'a dyn crate::types::traits::GuestAuthenticationTrait,
}
impl<'a> miniserde::Serialize for ValidateCredentialsInGuestRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(ValidateCredentialsInGuestRequestTypeSer { data: self, seq: 0 }))
}
}
struct ValidateCredentialsInGuestRequestTypeSer<'b, 'a> {
data: &'b ValidateCredentialsInGuestRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for ValidateCredentialsInGuestRequestTypeSer<'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"), &"ValidateCredentialsInGuestRequestType")),
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,
}
}
}