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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// This managed object type provides directory and basic management
/// services for all registered extensions.
/// 
/// Clients use the ExtensionManager, available in
/// *ServiceInstance*,
/// to access extension objects.
/// 
/// While several authentication methods are available for extension
/// servers to use (see *SessionManager*), only one
/// authentication method is valid for an extension at any given
/// time.
#[derive(Clone)]
pub struct ExtensionManager {
    client: Arc<dyn VimClient>,
    mo_id: String,
}
impl ExtensionManager {
    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
        Self {
            client,
            mo_id: mo_id.to_string(),
        }
    }
    /// Returns extension with the given key, if any.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### extension_key
    /// Key to search for.
    ///
    /// ## Returns:
    ///
    /// Extension that matches given key, if any.
    pub async fn find_extension(&self, extension_key: &str) -> Result<Option<crate::types::structs::Extension>> {
        let input = FindExtensionRequestType {extension_key, };
        let bytes_opt = self.client.invoke_optional("", "ExtensionManager", &self.mo_id, "FindExtension", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Deprecated as of VI 4.0, use trusted certificates and
    /// *SessionManager.LoginExtensionBySubjectName* or
    /// *ExtensionManager.SetExtensionCertificate* and
    /// *SessionManager.LoginExtensionByCertificate*.
    /// 
    /// Returns VirtualCenter Server public key.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Returns:
    ///
    /// Public key of VirtualCenter Server, encoded
    /// in PEM (privacy-enhanced mail) format.
    pub async fn get_public_key(&self) -> Result<String> {
        let bytes = self.client.invoke("", "ExtensionManager", &self.mo_id, "GetPublicKey", None).await?;
        let result: String = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Query statistics about IP allocation usage, either system wide or for
    /// specified extensions.
    /// 
    /// Refer to *IpPoolManager* for details.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### extension_keys
    /// List of extensions whose IP allocation is being queried.
    /// If no extension keys are specified then allocation data
    /// for all registered extensions are returned.
    ///
    /// ## Returns:
    ///
    /// List of IP allocation usage.
    pub async fn query_extension_ip_allocation_usage(&self, extension_keys: Option<&[String]>) -> Result<Option<Vec<crate::types::structs::ExtensionManagerIpAllocationUsage>>> {
        let input = QueryExtensionIpAllocationUsageRequestType {extension_keys, };
        let bytes_opt = self.client.invoke_optional("", "ExtensionManager", &self.mo_id, "QueryExtensionIpAllocationUsage", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Find entities managed by an extension.
    /// 
    /// These can be either virtual machines
    /// or vApps.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### extension_key
    /// Key of the extension to find managed entities for.
    ///
    /// ## Returns:
    ///
    /// List of entities managed by the extension.
    /// 
    /// Refers instances of *ManagedEntity*.
    pub async fn query_managed_by(&self, extension_key: &str) -> Result<Option<Vec<crate::types::structs::ManagedObjectReference>>> {
        let input = QueryManagedByRequestType {extension_key, };
        let bytes_opt = self.client.invoke_optional("", "ExtensionManager", &self.mo_id, "QueryManagedBy", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Registers extension.
    /// 
    /// ***Required privileges:*** Extension.Register
    ///
    /// ## Parameters:
    ///
    /// ### extension
    /// Extension description to register.
    pub async fn register_extension(&self, extension: &crate::types::structs::Extension) -> Result<()> {
        let input = RegisterExtensionRequestType {extension, };
        self.client.invoke_void("", "ExtensionManager", &self.mo_id, "RegisterExtension", Some(&input)).await
    }
    /// Update the stored authentication certificate for a specified extension.
    /// 
    /// Updates the registration of the specified extension with the
    /// thumbprint of the X.509 client certificate provided over SSL handshake,
    /// or by the &quot;certificatePem&quot;argument. The thumbprint
    /// will be used to authenticate the extension during invocations of
    /// *SessionManager.LoginExtensionByCertificate*.
    /// 
    /// NOTE: No verification is performed on the received certificate, such as
    /// expiry or revocation.
    /// 
    /// This method will unset any public key or subject name
    /// associated with the extension.
    /// 
    /// ***Required privileges:*** Extension.Update
    ///
    /// ## Parameters:
    ///
    /// ### extension_key
    /// Key of extension to update.
    ///
    /// ### certificate_pem
    /// PEM encoded certificate. If not specified, the
    /// certificate passed over SSL handshake is used.
    ///
    /// ## Errors:
    ///
    /// ***InvalidArgument***: if the certificate described by
    /// &quot;certificatePem&quot; is not in PEM
    /// format, or could not be decoded to an X.509 certificate.
    /// 
    /// ***NoClientCertificate***: if certificatePem is not specified, and
    /// no certificate was passed over SSL handshake.
    /// 
    /// ***NotFound***: if an extension specified by &quot;extensionKey&quot;
    /// is not registered.
    pub async fn set_extension_certificate(&self, extension_key: &str, certificate_pem: Option<&str>) -> Result<()> {
        let input = SetExtensionCertificateRequestType {extension_key, certificate_pem, };
        self.client.invoke_void("", "ExtensionManager", &self.mo_id, "SetExtensionCertificate", Some(&input)).await
    }
    /// Deprecated as of VI 4.0, use trusted certificates and
    /// *SessionManager.LoginExtensionBySubjectName* or
    /// *ExtensionManager.SetExtensionCertificate* and
    /// *SessionManager.LoginExtensionByCertificate*.
    /// 
    /// Sets extension's public key.
    /// 
    /// This method will unset any subject name or
    /// certificate associated with the extension.
    /// 
    /// ***Required privileges:*** Extension.Update
    ///
    /// ## Parameters:
    ///
    /// ### extension_key
    /// Key of extension to update.
    ///
    /// ### public_key
    /// Public key of extension, encoded
    /// in PEM (privacy-enhanced mail) format.
    pub async fn set_public_key(&self, extension_key: &str, public_key: &str) -> Result<()> {
        let input = SetPublicKeyRequestType {extension_key, public_key, };
        self.client.invoke_void("", "ExtensionManager", &self.mo_id, "SetPublicKey", Some(&input)).await
    }
    /// Update the stored authentication service account for the specified extension.
    /// 
    /// Updates the registration of the specified extension with the
    /// service account passed in the &quot;serviceAccount&quot;parameter.
    /// The service account will be used to authenticate the extension
    /// by invoking vCenter Server Login APIs and the user session can be
    /// used to update an Extension's data.
    /// 
    /// This method will unset the previous service account name
    /// associated with the extension.
    /// 
    /// The account name must be passed in with same case as the created
    /// account name.
    /// The account name must be suffixed with the vCenter machine id.
    /// The account name passed in must be qualified by the SSO domain
    /// for the vCenter server using the same format as userName for
    /// *SessionManager.Login*
    /// 
    /// NOTE: Account lifetime is managed by the extension owning the account.
    /// 
    /// ***Since:*** vSphere API Release 8.0.2.0
    /// 
    /// ***Required privileges:*** Extension.Update
    ///
    /// ## Parameters:
    ///
    /// ### extension_key
    /// Key of extension to update.
    ///
    /// ### service_account
    /// account name qualified with SSO domain.
    ///
    /// ## Errors:
    ///
    /// ***InvalidArgument***: if the account name described by
    /// &quot;serviceAccount&quot; is not present.
    /// 
    /// ***NotFound***: if an extension specified by &quot;extensionKey&quot;
    /// is not registered or the service account is not found.
    pub async fn set_service_account(&self, extension_key: &str, service_account: &str) -> Result<()> {
        let input = SetServiceAccountRequestType {extension_key, service_account, };
        self.client.invoke_void("", "ExtensionManager", &self.mo_id, "SetServiceAccount", Some(&input)).await
    }
    /// Unregisters the specified extension if it exists.
    /// 
    /// ***Required privileges:*** Extension.Unregister
    ///
    /// ## Parameters:
    ///
    /// ### extension_key
    /// Unique name of extension to unregister.
    ///
    /// ## Errors:
    ///
    /// ***NotFound***: if the specified extension
    /// is not registered.
    pub async fn unregister_extension(&self, extension_key: &str) -> Result<()> {
        let input = UnregisterExtensionRequestType {extension_key, };
        self.client.invoke_void("", "ExtensionManager", &self.mo_id, "UnregisterExtension", Some(&input)).await
    }
    /// If the key specified in the extension exists,
    /// the existing record is updated.
    /// 
    /// If the &quot;subjectName&quot; property of the Extension
    /// object has a value, and it is different from the existing
    /// value, this method will unset any public key or
    /// certificate associated with the extension.
    /// 
    /// ***Required privileges:*** Extension.Update
    ///
    /// ## Parameters:
    ///
    /// ### extension
    /// Updated extension description.
    ///
    /// ## Errors:
    ///
    /// ***NotFound***: if the specified extension key is not registered.
    /// 
    /// ***InvalidArgument***: if the Extension description is incomplete or invalid, or
    /// if the extension is an OVF extension and its section types overlap with other
    /// registered OVF extensions.
    pub async fn update_extension(&self, extension: &crate::types::structs::Extension) -> Result<()> {
        let input = UpdateExtensionRequestType {extension, };
        self.client.invoke_void("", "ExtensionManager", &self.mo_id, "UpdateExtension", Some(&input)).await
    }
    /// The list of currently registered extensions.
    /// 
    /// ***Required privileges:*** System.View
    pub async fn extension_list(&self) -> Result<Option<Vec<crate::types::structs::Extension>>> {
        let pv_opt = self.client.fetch_property_raw("", "ExtensionManager", &self.mo_id, "extensionList").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
}
struct FindExtensionRequestType<'a> {
    extension_key: &'a str,
}

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

struct FindExtensionRequestTypeSer<'b, 'a> {
    data: &'b FindExtensionRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for FindExtensionRequestTypeSer<'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"), &"FindExtensionRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct QueryExtensionIpAllocationUsageRequestType<'a> {
    extension_keys: Option<&'a [String]>,
}

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

struct QueryExtensionIpAllocationUsageRequestTypeSer<'b, 'a> {
    data: &'b QueryExtensionIpAllocationUsageRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for QueryExtensionIpAllocationUsageRequestTypeSer<'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"), &"QueryExtensionIpAllocationUsageRequestType")),
                1 => {
                    let Some(ref val) = self.data.extension_keys else { continue; };
                    return Some((std::borrow::Cow::Borrowed("extensionKeys"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct QueryManagedByRequestType<'a> {
    extension_key: &'a str,
}

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

struct QueryManagedByRequestTypeSer<'b, 'a> {
    data: &'b QueryManagedByRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for QueryManagedByRequestTypeSer<'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"), &"QueryManagedByRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct RegisterExtensionRequestType<'a> {
    extension: &'a crate::types::structs::Extension,
}

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

struct RegisterExtensionRequestTypeSer<'b, 'a> {
    data: &'b RegisterExtensionRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for RegisterExtensionRequestTypeSer<'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"), &"RegisterExtensionRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("extension"), &self.data.extension as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct SetExtensionCertificateRequestType<'a> {
    extension_key: &'a str,
    certificate_pem: Option<&'a str>,
}

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

struct SetExtensionCertificateRequestTypeSer<'b, 'a> {
    data: &'b SetExtensionCertificateRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for SetExtensionCertificateRequestTypeSer<'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"), &"SetExtensionCertificateRequestType")),
                1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
                2 => {
                    let Some(ref val) = self.data.certificate_pem else { continue; };
                    return Some((std::borrow::Cow::Borrowed("certificatePem"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct SetPublicKeyRequestType<'a> {
    extension_key: &'a str,
    public_key: &'a str,
}

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

struct SetPublicKeyRequestTypeSer<'b, 'a> {
    data: &'b SetPublicKeyRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for SetPublicKeyRequestTypeSer<'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"), &"SetPublicKeyRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("publicKey"), &self.data.public_key as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct SetServiceAccountRequestType<'a> {
    extension_key: &'a str,
    service_account: &'a str,
}

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

struct SetServiceAccountRequestTypeSer<'b, 'a> {
    data: &'b SetServiceAccountRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for SetServiceAccountRequestTypeSer<'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"), &"SetServiceAccountRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("serviceAccount"), &self.data.service_account as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct UnregisterExtensionRequestType<'a> {
    extension_key: &'a str,
}

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

struct UnregisterExtensionRequestTypeSer<'b, 'a> {
    data: &'b UnregisterExtensionRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for UnregisterExtensionRequestTypeSer<'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"), &"UnregisterExtensionRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct UpdateExtensionRequestType<'a> {
    extension: &'a crate::types::structs::Extension,
}

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

struct UpdateExtensionRequestTypeSer<'b, 'a> {
    data: &'b UpdateExtensionRequestType<'a>,
    seq: usize,
}

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