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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// Represents a lease on a *VirtualMachine* or
/// a *VirtualApp*, which can be used to import or export
/// disks for the entity.
/// 
/// While the lease is held, operations
/// that alter the state of the virtual machines covered by the lease
/// are blocked. Examples of blocked operations are PowerOn, Destroy,
/// Migrate, etc.
/// 
/// A lease is in one of four states:
/// <dl>
/// <dt>Initializing</dt>
/// <dd>This is the initial state. The lease remains in this state
/// while the corresponding import/export task is preparing the
/// objects. In an import session, this involves creating
/// inventory objects.</dd>
/// <dt>Ready</dt>
/// <dd>The lease changes to this state once the corresponding
/// import/export task is done preparing the lease. The leased
/// objects are now ready, and the client can use the information
/// provided in the *HttpNfcLease.info* property to determine where to
/// up/download disks. The client must call *HttpNfcLease.HttpNfcLeaseProgress*
/// periodically to keep the lease alive and report progress to
/// the corresponding import/export task. Failure to do so causes
/// the lease to time out and enter the error state.</dd>
/// <dt>Done</dt>
/// <dd>When the client is done transferring disks, it calls
/// *HttpNfcLease.HttpNfcLeaseComplete* to signal the end of the import/export session.
/// This causes the corresponding import/export task to complete
/// successfully.</dd>
/// <dt>Error</dt>
/// <dd>If an error occurs during initialization or the lease times out,
/// it will change to this state. The client can also abort the lease
/// manually by calling *HttpNfcLease.HttpNfcLeaseAbort*. In this state, the *HttpNfcLease.error*
/// property can be read to determine the cause.
/// If the lease belongs to an import session, all objects created
/// during the import are removed when the lease enters this state.</dd>
/// </dl>
/// The import/export task corresponding to the lease continues running while
/// the lease is held.
#[derive(Clone)]
pub struct HttpNfcLease {
    client: Arc<dyn VimClient>,
    mo_id: String,
}
impl HttpNfcLease {
    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
        Self {
            client,
            mo_id: mo_id.to_string(),
        }
    }
    /// Aborts the import/export and releases this lease.
    /// 
    /// Operations on the
    /// objects contained in this lease will no longer be blocked. After
    /// calling this method, this lease will no longer be valid.
    /// 
    /// Clients should call this method if an error occurs while accessing
    /// the disks, or if the operation is cancelled. The client can report
    /// the cause of the abort to other clients listening on the task with
    /// the fault parameter.
    ///
    /// ## Parameters:
    ///
    /// ### fault
    /// \[in\] The fault that caused the abort, if any.
    ///
    /// ## Errors:
    ///
    /// ***Timedout***: if the lease has timed out before this call.
    /// 
    /// ***InvalidState***: if the lease has already been aborted.
    pub async fn http_nfc_lease_abort(&self, fault: Option<&crate::types::structs::MethodFault>) -> Result<()> {
        let input = HttpNfcLeaseAbortRequestType {fault, };
        self.client.invoke_void("", "HttpNfcLease", &self.mo_id, "HttpNfcLeaseAbort", Some(&input)).await
    }
    /// Completes the import/export and releases this lease.
    /// 
    /// Operations on
    /// the objects contained in this lease will no longer be blocked. After
    /// calling this method, this lease will no longer be valid.
    /// 
    /// Clients should call this method when they are done accessing the
    /// disks for the *VirtualMachine*s in this lease. The status
    /// of the corresponding task will be set to success.
    ///
    /// ## Errors:
    ///
    /// ***Timedout***: if the lease has timed out before this call.
    /// 
    /// ***InvalidState***: if the lease has already been completed or
    /// aborted.
    pub async fn http_nfc_lease_complete(&self) -> Result<()> {
        self.client.invoke_void("", "HttpNfcLease", &self.mo_id, "HttpNfcLeaseComplete", None).await
    }
    /// Gets the download manifest for this lease.
    ///
    /// ## Errors:
    ///
    /// Failure
    pub async fn http_nfc_lease_get_manifest(&self) -> Result<Option<Vec<crate::types::structs::HttpNfcLeaseManifestEntry>>> {
        let bytes_opt = self.client.invoke_optional("", "HttpNfcLease", &self.mo_id, "HttpNfcLeaseGetManifest", None).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Perform a series of validations on the target host to see if
    /// it can succesfully perform PullFromUrls.
    /// 
    /// ***Since:*** vSphere API Release 7.0.2.0
    ///
    /// ## Parameters:
    ///
    /// ### files
    /// \[in\] List of remote source file descriptors
    /// There should be the same number of *HttpNfcLeaseSourceFile*
    /// as *HttpNfcLeaseDeviceUrl* provided by this lease.
    ///
    /// ### timeout
    /// \[in\] time in seconds for each url validation.
    /// Maximum timeout is 60.
    ///
    /// ## Errors:
    ///
    /// ***InvalidArgument***: if no source files are provided.
    /// 
    /// ***InvalidState***: if the lease has already been aborted.
    pub async fn http_nfc_lease_probe_urls(&self, files: Option<&[crate::types::structs::HttpNfcLeaseSourceFile]>, timeout: Option<i32>) -> Result<Option<Vec<crate::types::structs::HttpNfcLeaseProbeResult>>> {
        let input = HttpNfcLeaseProbeUrlsRequestType {files, timeout, };
        let bytes_opt = self.client.invoke_optional("", "HttpNfcLease", &self.mo_id, "HttpNfcLeaseProbeUrls", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Sets the disk up/download progress, and renews this lease.
    /// 
    /// A lease
    /// will time out automatically after a while. If the client wishes to
    /// continue using it, for example if it is not done accessing the
    /// disks, this method must be called periodically.
    ///
    /// ## Parameters:
    ///
    /// ### percent
    /// \[in\] Completion status represented as an integer
    /// in the 0-100 range.
    ///
    /// ## Errors:
    ///
    /// ***Timedout***: if the lease has timed out or vSphere has not
    /// detected data transfer progress.
    pub async fn http_nfc_lease_progress(&self, percent: i32) -> Result<()> {
        let input = HttpNfcLeaseProgressRequestType {percent, };
        self.client.invoke_void("", "HttpNfcLease", &self.mo_id, "HttpNfcLeaseProgress", Some(&input)).await
    }
    /// Upgrades current lease from push to pull mode.
    ///
    /// ## Parameters:
    ///
    /// ### files
    /// \[in\] List of remote source file descriptors
    /// There should be the same number of *HttpNfcLeaseSourceFile*
    /// as *HttpNfcLeaseDeviceUrl* provided by this lease.
    /// Privilege VApp.PullFromUrls is required.
    ///
    /// ## Returns:
    ///
    /// Refers instance of *Task*.
    ///
    /// ## Errors:
    ///
    /// ***InvalidState***: if the lease has already been aborted.
    pub async fn http_nfc_lease_pull_from_urls_task(&self, files: Option<&[crate::types::structs::HttpNfcLeaseSourceFile]>) -> Result<crate::types::structs::ManagedObjectReference> {
        let input = HttpNfcLeasePullFromUrlsRequestType {files, };
        let bytes = self.client.invoke("", "HttpNfcLease", &self.mo_id, "HttpNfcLeasePullFromUrls_Task", Some(&input)).await?;
        let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Sets desired checksum algorithm per each file that will be returned in
    /// ManifestEntry.
    /// 
    /// Should be set before any transfer starts.
    ///
    /// ## Parameters:
    ///
    /// ### device_urls_to_checksum_types
    /// \[in\] Should contain key value pairs:
    /// where key is *HttpNfcLeaseDeviceUrl.key* returned in this lease info and value
    /// is desired algorithm from *HttpNfcLeaseManifestEntryChecksumType_enum*.
    ///
    /// ## Errors:
    ///
    /// Failure
    pub async fn http_nfc_lease_set_manifest_checksum_type(&self, device_urls_to_checksum_types: Option<&[crate::types::structs::KeyValue]>) -> Result<()> {
        let input = HttpNfcLeaseSetManifestChecksumTypeRequestType {device_urls_to_checksum_types, };
        self.client.invoke_void("", "HttpNfcLease", &self.mo_id, "HttpNfcLeaseSetManifestChecksumType", Some(&input)).await
    }
    /// Current supported capabilities by this lease
    /// See *HttpNfcLeaseCapabilities*
    pub async fn capabilities(&self) -> Result<crate::types::structs::HttpNfcLeaseCapabilities> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "capabilities").await?;
        let pv = pv_opt.ok_or_else(|| crate::core::client::VimError::ParseError("property capabilities was empty".to_string()))?;
        let result: crate::types::structs::HttpNfcLeaseCapabilities = crate::core::client::extract_property(pv)?;
        Ok(result)
    }
    /// If the lease is in the error state, this property contains the
    /// error that caused the lease to be aborted.
    pub async fn error(&self) -> Result<Option<crate::types::structs::MethodFault>> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "error").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
    /// Provides information on the objects contained in this lease.
    /// 
    /// The
    /// info property is only valid when the lease is in the ready state.
    pub async fn info(&self) -> Result<Option<crate::types::structs::HttpNfcLeaseInfo>> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "info").await?;
        match pv_opt {
            Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
            None => Ok(None),
        }
    }
    /// Provides progress information (0-100 percent) for the initializing state
    /// of the lease.
    /// 
    /// Clients can use this to track overall progress.
    pub async fn initialize_progress(&self) -> Result<i32> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "initializeProgress").await?;
        let pv = pv_opt.ok_or_else(|| crate::core::client::VimError::ParseError("property initializeProgress was empty".to_string()))?;
        let result: i32 = crate::core::client::extract_property(pv)?;
        Ok(result)
    }
    /// Current mode of the lease.
    /// 
    /// See *HttpNfcLeaseMode_enum* for possible values.
    pub async fn mode(&self) -> Result<String> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "mode").await?;
        let pv = pv_opt.ok_or_else(|| crate::core::client::VimError::ParseError("property mode was empty".to_string()))?;
        let result: String = crate::core::client::extract_property(pv)?;
        Ok(result)
    }
    /// The current state of the lease.
    pub async fn state(&self) -> Result<crate::types::enums::HttpNfcLeaseStateEnum> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "state").await?;
        let pv = pv_opt.ok_or_else(|| crate::core::client::VimError::ParseError("property state was empty".to_string()))?;
        let result: crate::types::enums::HttpNfcLeaseStateEnum = crate::core::client::extract_property(pv)?;
        Ok(result)
    }
    /// Provides progress information (0-100 percent) for current transfer.
    /// 
    /// Transfer covers download, upload and pull scenario.
    /// Can be externally updated by progress method.
    pub async fn transfer_progress(&self) -> Result<i32> {
        let pv_opt = self.client.fetch_property_raw("", "HttpNfcLease", &self.mo_id, "transferProgress").await?;
        let pv = pv_opt.ok_or_else(|| crate::core::client::VimError::ParseError("property transferProgress was empty".to_string()))?;
        let result: i32 = crate::core::client::extract_property(pv)?;
        Ok(result)
    }
}
struct HttpNfcLeaseAbortRequestType<'a> {
    fault: Option<&'a crate::types::structs::MethodFault>,
}

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

struct HttpNfcLeaseAbortRequestTypeSer<'b, 'a> {
    data: &'b HttpNfcLeaseAbortRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for HttpNfcLeaseAbortRequestTypeSer<'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"), &"HttpNfcLeaseAbortRequestType")),
                1 => {
                    let Some(ref val) = self.data.fault else { continue; };
                    return Some((std::borrow::Cow::Borrowed("fault"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct HttpNfcLeaseProbeUrlsRequestType<'a> {
    files: Option<&'a [crate::types::structs::HttpNfcLeaseSourceFile]>,
    timeout: Option<i32>,
}

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

struct HttpNfcLeaseProbeUrlsRequestTypeSer<'b, 'a> {
    data: &'b HttpNfcLeaseProbeUrlsRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for HttpNfcLeaseProbeUrlsRequestTypeSer<'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"), &"HttpNfcLeaseProbeUrlsRequestType")),
                1 => {
                    let Some(ref val) = self.data.files else { continue; };
                    return Some((std::borrow::Cow::Borrowed("files"), val as &dyn miniserde::Serialize));
                }
                2 => {
                    let Some(ref val) = self.data.timeout else { continue; };
                    return Some((std::borrow::Cow::Borrowed("timeout"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct HttpNfcLeaseProgressRequestType {
    percent: i32,
}

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

struct HttpNfcLeaseProgressRequestTypeSer<'b> {
    data: &'b HttpNfcLeaseProgressRequestType,
    seq: usize,
}

impl<'b> miniserde::ser::Map for HttpNfcLeaseProgressRequestTypeSer<'b> {
    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"), &"HttpNfcLeaseProgressRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("percent"), &self.data.percent as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct HttpNfcLeasePullFromUrlsRequestType<'a> {
    files: Option<&'a [crate::types::structs::HttpNfcLeaseSourceFile]>,
}

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

struct HttpNfcLeasePullFromUrlsRequestTypeSer<'b, 'a> {
    data: &'b HttpNfcLeasePullFromUrlsRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for HttpNfcLeasePullFromUrlsRequestTypeSer<'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"), &"HttpNfcLeasePullFromUrlsRequestType")),
                1 => {
                    let Some(ref val) = self.data.files else { continue; };
                    return Some((std::borrow::Cow::Borrowed("files"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}
struct HttpNfcLeaseSetManifestChecksumTypeRequestType<'a> {
    device_urls_to_checksum_types: Option<&'a [crate::types::structs::KeyValue]>,
}

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

struct HttpNfcLeaseSetManifestChecksumTypeRequestTypeSer<'b, 'a> {
    data: &'b HttpNfcLeaseSetManifestChecksumTypeRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for HttpNfcLeaseSetManifestChecksumTypeRequestTypeSer<'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"), &"HttpNfcLeaseSetManifestChecksumTypeRequestType")),
                1 => {
                    let Some(ref val) = self.data.device_urls_to_checksum_types else { continue; };
                    return Some((std::borrow::Cow::Borrowed("deviceUrlsToChecksumTypes"), val as &dyn miniserde::Serialize));
                }
                _ => return None,
            }
        }
    }
}