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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// Service interface to parse and generate OVF descriptors.
/// 
/// The purpose of this interface is to make it easier for callers to import VMs and
/// vApps from OVF packages and to export VI packages to OVF. In the following
/// description, the term "client" is used to mean any caller of the interface.
/// 
/// This interface only converts between OVF and VI types. To actually import and export
/// entities, use *ResourcePool.importVApp*,
/// *VirtualMachine.exportVm* and
/// *VirtualApp.exportVApp*.
/// 
/// **Import**
/// 
/// For the import scenario, the typical sequence of events is as follows:
/// 
/// The client calls parseDescriptor to obtain information about the OVF descriptor. This
/// typically includes information (such as a list of networks) that must be mapped to VI
/// infrastructure entities.
/// 
/// The OVF descriptor is validated against the OVF Specification, and any errors or
/// warnings are returned as part of the ParseResult. For example, the parser might
/// encounter a section marked required that it does not understand, or the XML descriptor
/// might be malformed.
/// 
/// The client decides on network mappings, datastore, properties etc. It then calls
/// createImportSpec to obtain the parameters needed to call
/// *ResourcePool.importVApp*.
/// 
/// If any warnings are present, the client will review these and decide whether to
/// proceed or not. If errors are present, the ImportSpec will be missing, so
/// the client is forced to give up or fix the problems and then try again.
/// 
/// The client now calls *ResourcePool.importVApp*, passing the ImportSpec as a parameter. This will create
/// the virtual machines and *VirtualApp* objects in VI and return locations
/// to which the files of the entity can be uploaded. It also returns a lease that
/// controls the duration of the lock taken on the newly created inventory objects. When
/// all files have been uploaded, the client must release this lease.
/// 
/// **Export**
/// 
/// Creating the OVF descriptor is the last part of exporting an entity to OVF. At this
/// point, the client has already downloaded all files for the entity, optionally
/// compressing and/or chunking them (however, the client may do a "dry run" of creating
/// the descriptor before downloading the files. See *OvfManager.createDescriptor*).
/// 
/// In addition to the entity reference itself, information about the choices made on
/// these files is passed to createDescriptor as a list of OvfFile instances.
/// 
/// The client must inspect and act upon warnings and errors as previously described.
/// 
/// No matter if the export succeeds or fails, the client is responsible for releasing the
/// shared state lock taken on the entity (by *VirtualMaching.exportVm* or *VirtualApp.exportVApp*) during the export.
/// 
/// **Error handling**
/// 
/// All result types contain warning and error lists. Warnings do not cause processing to
/// fail, but the caller (typically, the user of a GUI client) may choose to reject the
/// result based on the warnings issued.
/// 
/// Errors cause processing to abort by definition.
#[derive(Clone)]
pub struct OvfManager {
    client: Arc<dyn VimClient>,
    mo_id: String,
}
impl OvfManager {
    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
        Self {
            client,
            mo_id: mo_id.to_string(),
        }
    }
    /// Create an OVF descriptor for the specified ManagedEntity, which may be a
    /// *VirtualMachine* or a *VirtualApp*.
    /// 
    /// To create the complete OVF descriptor, the client must already have downloaded the
    /// files that are part of the entity, because information about these files
    /// (compression, chunking, filename etc.) is part of the descriptor.
    /// 
    /// However, these downloads can be quite time-consuming, so if the descriptor for some
    /// reason cannot be generated, the client will want to know this before downloading
    /// the files.
    /// 
    /// For this reason, the client may do an initial "dry run" with the ovfFiles
    /// parameter unset. Default filenames will then be used in the descriptor, and the
    /// client can examine any warnings and/or errors before downloading the files.
    /// 
    /// After the final call to this method, client must release the lock on the entity
    /// given to it by *VirtualMachine.exportVm* or *VirtualApp.exportVApp*.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### obj
    /// The entity to export. Supported types are *VirtualMachine*
    /// and *VirtualApp*.
    /// 
    /// ***Required privileges:*** VApp.Export
    /// 
    /// Refers instance of *ManagedEntity*.
    ///
    /// ### cdp
    /// Parameters to the method, bundled in an instance of
    /// CreateDescriptorParams.
    ///
    /// ## Returns:
    ///
    /// An instance of CreateDescriptorResult
    ///
    /// ## Errors:
    ///
    /// ***TaskInProgress***: if a required managed entity is busy.
    /// 
    /// ***VmConfigFault***: if a configuration issue prevents the operation from
    /// succeeding. Typically, a more specific subclass is thrown.
    /// 
    /// ***ConcurrentAccess***: if a concurrency issue prevents the operation from
    /// succeeding.
    /// 
    /// ***FileFault***: if there is a generic file error
    /// 
    /// ***InvalidState***: if the operation failed due to the current state of the system.
    pub async fn create_descriptor(&self, obj: &crate::types::structs::ManagedObjectReference, cdp: &crate::types::structs::OvfCreateDescriptorParams) -> Result<crate::types::structs::OvfCreateDescriptorResult> {
        let input = CreateDescriptorRequestType {obj, cdp, };
        let bytes = self.client.invoke("", "OvfManager", &self.mo_id, "CreateDescriptor", Some(&input)).await?;
        let result: crate::types::structs::OvfCreateDescriptorResult = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Validate the OVF descriptor against the hardware supported by the
    /// host system.
    /// 
    /// If the validation succeeds, return a result containing:
    /// - An *ImportSpec* to use when importing the entity.
    /// - A list of items to upload (for example disk backing files, ISO images etc.)
    ///   
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### ovf_descriptor
    /// The OVF descriptor of the entity.
    ///
    /// ### resource_pool
    /// The resource pool to import the entity to. May be a
    /// vApp.
    /// 
    /// ***Required privileges:*** VApp.Import
    /// 
    /// Refers instance of *ResourcePool*.
    ///
    /// ### datastore
    /// The datastore on which to create the inventory objects
    /// of the entity, for example "storage1". The privilege
    /// Datastore.AllocateSpace is required on the datastore.
    /// 
    /// ***Required privileges:*** Datastore.AllocateSpace
    /// 
    /// Refers instance of *Datastore*.
    ///
    /// ### cisp
    /// Additional parameters to the method, bundled in an instance of
    /// CreateImportSpecParams.
    ///
    /// ## Errors:
    ///
    /// ***TaskInProgress***: if a required managed entity is busy.
    /// 
    /// ***VmConfigFault***: if a configuration issue prevents the operation from
    /// succeeding. Typically, a more specific subclass is thrown.
    /// 
    /// ***ConcurrentAccess***: if a concurrency issue prevents the operation from
    /// succeeding.
    /// 
    /// ***FileFault***: if there is a generic file error
    /// 
    /// ***InvalidState***: if the operation failed due to the current state of the system.
    pub async fn create_import_spec(&self, ovf_descriptor: &str, resource_pool: &crate::types::structs::ManagedObjectReference, datastore: &crate::types::structs::ManagedObjectReference, cisp: &dyn crate::types::traits::OvfCreateImportSpecParamsTrait) -> Result<crate::types::structs::OvfCreateImportSpecResult> {
        let input = CreateImportSpecRequestType {ovf_descriptor, resource_pool, datastore, cisp, };
        let bytes = self.client.invoke("", "OvfManager", &self.mo_id, "CreateImportSpec", Some(&input)).await?;
        let result: crate::types::structs::OvfCreateImportSpecResult = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Parse the OVF descriptor and return as much information about it as possible
    /// without knowing the host on which it will be imported.
    /// 
    /// Typically, this method is called once without a deploymentOption parameter to
    /// obtain the values for the default deployment option. Part of the result is the list
    /// of possible deployment options. To obtain the values for a particular deployment
    /// option, call this method again, specifying that option.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### ovf_descriptor
    /// The OVF descriptor to examine.
    ///
    /// ### pdp
    /// Additional parameters for parseDescriptor, wrapped in an instance of
    /// ParseDescriptorParams.
    ///
    /// ## Returns:
    ///
    /// The information about the descriptor
    ///
    /// ## Errors:
    ///
    /// ***TaskInProgress***: if a required managed entity is busy.
    /// 
    /// ***VmConfigFault***: if a configuration issue prevents the operation from
    /// succeeding. Typically, a more specific subclass is thrown.
    /// 
    /// ***ConcurrentAccess***: if a concurrency issue prevents the operation from
    /// succeeding.
    /// 
    /// ***FileFault***: if there is a generic file error
    /// 
    /// ***InvalidState***: if the operation failed due to the current state of the system.
    pub async fn parse_descriptor(&self, ovf_descriptor: &str, pdp: &crate::types::structs::OvfParseDescriptorParams) -> Result<crate::types::structs::OvfParseDescriptorResult> {
        let input = ParseDescriptorRequestType {ovf_descriptor, pdp, };
        let bytes = self.client.invoke("", "OvfManager", &self.mo_id, "ParseDescriptor", Some(&input)).await?;
        let result: crate::types::structs::OvfParseDescriptorResult = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Validate that the given OVF can be imported on the host.
    /// 
    /// More specifically, this means whether or not the host supports the virtual hardware
    /// required by the OVF descriptor.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Parameters:
    ///
    /// ### ovf_descriptor
    /// The OVF descriptor to examine.
    ///
    /// ### host
    /// The host to validate against.
    /// 
    /// Refers instance of *HostSystem*.
    ///
    /// ### vhp
    /// Additional parameters for validateHost, wrapped in a ValidateHostParams
    /// instance.
    ///
    /// ## Returns:
    ///
    /// A ValidateResult instance containing any warnings and/or errors from the
    /// validation.
    ///
    /// ## Errors:
    ///
    /// ***TaskInProgress***: if a required managed entity is busy.
    /// 
    /// ***ConcurrentAccess***: if a concurrency issue prevents the operation from
    /// succeeding.
    /// 
    /// ***FileFault***: if there is a generic file error
    /// 
    /// ***InvalidState***: if the operation failed due to the current state of the system.
    pub async fn validate_host(&self, ovf_descriptor: &str, host: &crate::types::structs::ManagedObjectReference, vhp: &crate::types::structs::OvfValidateHostParams) -> Result<crate::types::structs::OvfValidateHostResult> {
        let input = ValidateHostRequestType {ovf_descriptor, host, vhp, };
        let bytes = self.client.invoke("", "OvfManager", &self.mo_id, "ValidateHost", Some(&input)).await?;
        let result: crate::types::structs::OvfValidateHostResult = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Returns an array of *OvfOptionInfo* object that specifies what options the server
    /// support for exporting an OVF descriptor.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Returns:
    ///
    /// An instance of *OvfOptionInfo*
    pub async fn ovf_export_option(&self) -> Result<Option<Vec<crate::types::structs::OvfOptionInfo>>> {
        let pv_opt = self.client.fetch_property_raw("", "OvfManager", &self.mo_id, "ovfExportOption").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
    /// Returns an array of *OvfOptionInfo* object that specifies what options the server
    /// support for modifing/relaxing the OVF import process.
    /// 
    /// ***Required privileges:*** System.View
    ///
    /// ## Returns:
    ///
    /// An instance of *OvfOptionInfo*
    pub async fn ovf_import_option(&self) -> Result<Option<Vec<crate::types::structs::OvfOptionInfo>>> {
        let pv_opt = self.client.fetch_property_raw("", "OvfManager", &self.mo_id, "ovfImportOption").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
}
struct CreateDescriptorRequestType<'a> {
    obj: &'a crate::types::structs::ManagedObjectReference,
    cdp: &'a crate::types::structs::OvfCreateDescriptorParams,
}

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

struct CreateDescriptorRequestTypeSer<'b, 'a> {
    data: &'b CreateDescriptorRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for CreateDescriptorRequestTypeSer<'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"), &"CreateDescriptorRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("obj"), &self.data.obj as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("cdp"), &self.data.cdp as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct CreateImportSpecRequestType<'a> {
    ovf_descriptor: &'a str,
    resource_pool: &'a crate::types::structs::ManagedObjectReference,
    datastore: &'a crate::types::structs::ManagedObjectReference,
    cisp: &'a dyn crate::types::traits::OvfCreateImportSpecParamsTrait,
}

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

struct CreateImportSpecRequestTypeSer<'b, 'a> {
    data: &'b CreateImportSpecRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for CreateImportSpecRequestTypeSer<'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"), &"CreateImportSpecRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("ovfDescriptor"), &self.data.ovf_descriptor as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("resourcePool"), &self.data.resource_pool as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("datastore"), &self.data.datastore as &dyn miniserde::Serialize)),
            4 => return Some((std::borrow::Cow::Borrowed("cisp"), &self.data.cisp as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct ParseDescriptorRequestType<'a> {
    ovf_descriptor: &'a str,
    pdp: &'a crate::types::structs::OvfParseDescriptorParams,
}

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

struct ParseDescriptorRequestTypeSer<'b, 'a> {
    data: &'b ParseDescriptorRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for ParseDescriptorRequestTypeSer<'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"), &"ParseDescriptorRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("ovfDescriptor"), &self.data.ovf_descriptor as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("pdp"), &self.data.pdp as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct ValidateHostRequestType<'a> {
    ovf_descriptor: &'a str,
    host: &'a crate::types::structs::ManagedObjectReference,
    vhp: &'a crate::types::structs::OvfValidateHostParams,
}

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

struct ValidateHostRequestTypeSer<'b, 'a> {
    data: &'b ValidateHostRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for ValidateHostRequestTypeSer<'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"), &"ValidateHostRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("ovfDescriptor"), &self.data.ovf_descriptor as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("host"), &self.data.host as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("vhp"), &self.data.vhp as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}