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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// Singleton Managed Object used to manage IP Pools.
/// 
/// IP Pools are used to allocate IPv4 and IPv6 addresses to vApps.
#[derive(Clone)]
pub struct IpPoolManager {
    client: Arc<dyn VimClient>,
    mo_id: String,
}
impl IpPoolManager {
    pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
        Self {
            client,
            mo_id: mo_id.to_string(),
        }
    }
    /// Allocates an IPv4 address from an IP pool.
    /// 
    /// Allocated IP addresses are reserved in the IP pool until released by
    /// calling *IpPoolManager.ReleaseIpAllocation*, or until the IP pool is configured to
    /// have an IP range that does not contain the IP address, or until the IP
    /// pool is destroyed.
    /// 
    /// The caller must be a vCenter extension. Refer to *ExtensionManager*
    /// for details on vCenter extensions.
    /// 
    /// The caller specifies a per extension unique allocation ID. Calling this
    /// function twice with the same allocation ID for the same pool yields the
    /// same IP address. This makes it possible to do idempotent allocations.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to find the pool
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### pool_id
    /// The unique ID of the pool
    ///
    /// ### allocation_id
    /// The unique ID for this allocation
    ///
    /// ## Returns:
    ///
    /// An IPv4 address if the pool has an available IPv4 address in its
    /// address ranges, otherwise the empty string.
    pub async fn allocate_ipv_4_address(&self, dc: &crate::types::structs::ManagedObjectReference, pool_id: i32, allocation_id: &str) -> Result<String> {
        let input = AllocateIpv4AddressRequestType {dc, pool_id, allocation_id, };
        let bytes = self.client.invoke("", "IpPoolManager", &self.mo_id, "AllocateIpv4Address", Some(&input)).await?;
        let result: String = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Allocates an IPv6 address from an IP pool.
    /// 
    /// Allocated IP addresses are reserved in the IP pool until released by
    /// calling *IpPoolManager.ReleaseIpAllocation*, or until the IP pool is configured to
    /// have an IP range that does not contain the IP address, or until the IP
    /// pool is destroyed.
    /// 
    /// The caller must be a vCenter extension. Refer to *ExtensionManager*
    /// for details on vCenter extensions.
    /// 
    /// The caller specifies a per extension unique allocation ID. Calling this
    /// function twice with the same allocation ID for the same pool yields the
    /// same IP address. This makes it possible to do idempotent allocations.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to find the pool
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### pool_id
    /// The unique ID of the pool
    ///
    /// ### allocation_id
    /// The unique ID for this allocation
    ///
    /// ## Returns:
    ///
    /// An IPv6 address if the pool has an available IPv6 address in its
    /// address ranges, otherwise the empty string.
    pub async fn allocate_ipv_6_address(&self, dc: &crate::types::structs::ManagedObjectReference, pool_id: i32, allocation_id: &str) -> Result<String> {
        let input = AllocateIpv6AddressRequestType {dc, pool_id, allocation_id, };
        let bytes = self.client.invoke("", "IpPoolManager", &self.mo_id, "AllocateIpv6Address", Some(&input)).await?;
        let result: String = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Create a new IP pool.
    /// 
    /// The name field must be defined, all other fields are optional. If unset,
    /// they will be given default values.
    /// 
    /// The ID for the pool is generated by the server and should not be defined on the
    /// pool object passed to this method.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to create the pool.
    /// 
    /// ***Required privileges:*** Datacenter.IpPoolConfig
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### pool
    /// The IP pool to create on the server
    ///
    /// ## Returns:
    ///
    /// The generated ID for the pool
    pub async fn create_ip_pool(&self, dc: &crate::types::structs::ManagedObjectReference, pool: &crate::types::structs::IpPool) -> Result<i32> {
        let input = CreateIpPoolRequestType {dc, pool, };
        let bytes = self.client.invoke("", "IpPoolManager", &self.mo_id, "CreateIpPool", Some(&input)).await?;
        let result: i32 = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Destroys an IP pool on the given datacenter.
    /// 
    /// Looks up the pool on the datacenter by ID and deletes it. If the pool is in use,
    /// the method throws InvalidState unless the force flag is true.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to find the pool
    /// 
    /// ***Required privileges:*** Datacenter.IpPoolConfig
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### id
    /// The unique ID of the pool
    ///
    /// ### force
    /// If true, the pool will be destroyed even if it is in use
    ///
    /// ## Errors:
    ///
    /// ***InvalidState***: if the pool is in use and the force flag is false
    pub async fn destroy_ip_pool(&self, dc: &crate::types::structs::ManagedObjectReference, id: i32, force: bool) -> Result<()> {
        let input = DestroyIpPoolRequestType {dc, id, force, };
        self.client.invoke_void("", "IpPoolManager", &self.mo_id, "DestroyIpPool", Some(&input)).await
    }
    /// Query IP allocations by IP pool and extension key.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to find the pool
    /// 
    /// ***Required privileges:*** Datacenter.IpPoolQueryAllocations
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### pool_id
    /// The unique ID of the pool
    ///
    /// ### extension_key
    /// The key of the extension
    ///
    /// ## Returns:
    ///
    /// The resulting list of *IpPoolManagerIpAllocation*.
    pub async fn query_ip_allocations(&self, dc: &crate::types::structs::ManagedObjectReference, pool_id: i32, extension_key: &str) -> Result<Vec<crate::types::structs::IpPoolManagerIpAllocation>> {
        let input = QueryIpAllocationsRequestType {dc, pool_id, extension_key, };
        let bytes = self.client.invoke("", "IpPoolManager", &self.mo_id, "QueryIPAllocations", Some(&input)).await?;
        let result: Vec<crate::types::structs::IpPoolManagerIpAllocation> = crate::core::client::unmarshal_array(self.client.transport(), &bytes)?;
        Ok(result)
    }
    /// Return the list of IP pools for a datacenter.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter for which to look up the IP pools.
    /// 
    /// ***Required privileges:*** System.Read
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ## Returns:
    ///
    /// The resulting list of pools.
    pub async fn query_ip_pools(&self, dc: &crate::types::structs::ManagedObjectReference) -> Result<Option<Vec<crate::types::structs::IpPool>>> {
        let input = QueryIpPoolsRequestType {dc, };
        let bytes_opt = self.client.invoke_optional("", "IpPoolManager", &self.mo_id, "QueryIpPools", Some(&input)).await?;
        match bytes_opt {
            Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
            None => Ok(None),
        }
    }
    /// Releases an IP allocation back to it's IP pool.
    /// 
    /// Attempting to release an IP allocation that is not allocated from the
    /// specified IP pool with the specified allocation ID silently fails. This
    /// makes it possible to release IP allocations idempotently.
    /// 
    /// All IP addresses allocated by an extension are automatically released
    /// if the extension is unregistered from vCenter.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to find the pool
    /// 
    /// ***Required privileges:*** Datacenter.IpPoolReleaseIp
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### pool_id
    /// The unique ID of the pool
    ///
    /// ### allocation_id
    /// The unique ID for this allocation
    pub async fn release_ip_allocation(&self, dc: &crate::types::structs::ManagedObjectReference, pool_id: i32, allocation_id: &str) -> Result<()> {
        let input = ReleaseIpAllocationRequestType {dc, pool_id, allocation_id, };
        self.client.invoke_void("", "IpPoolManager", &self.mo_id, "ReleaseIpAllocation", Some(&input)).await
    }
    /// Update an IP pool on a datacenter.
    /// 
    /// The pool to update is looked up from the value of the id field.
    /// 
    /// All fields in the pool except the id are optional. Only defined values are stored
    /// on the server.
    ///
    /// ## Parameters:
    ///
    /// ### dc
    /// The datacenter on which to look up the pool.
    /// 
    /// ***Required privileges:*** Datacenter.IpPoolConfig
    /// 
    /// Refers instance of *Datacenter*.
    ///
    /// ### pool
    /// The IP pool to update on the server
    pub async fn update_ip_pool(&self, dc: &crate::types::structs::ManagedObjectReference, pool: &crate::types::structs::IpPool) -> Result<()> {
        let input = UpdateIpPoolRequestType {dc, pool, };
        self.client.invoke_void("", "IpPoolManager", &self.mo_id, "UpdateIpPool", Some(&input)).await
    }
}
struct AllocateIpv4AddressRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    pool_id: i32,
    allocation_id: &'a str,
}

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

struct AllocateIpv4AddressRequestTypeSer<'b, 'a> {
    data: &'b AllocateIpv4AddressRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for AllocateIpv4AddressRequestTypeSer<'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"), &"AllocateIpv4AddressRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("poolId"), &self.data.pool_id as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("allocationId"), &self.data.allocation_id as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct AllocateIpv6AddressRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    pool_id: i32,
    allocation_id: &'a str,
}

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

struct AllocateIpv6AddressRequestTypeSer<'b, 'a> {
    data: &'b AllocateIpv6AddressRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for AllocateIpv6AddressRequestTypeSer<'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"), &"AllocateIpv6AddressRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("poolId"), &self.data.pool_id as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("allocationId"), &self.data.allocation_id as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct CreateIpPoolRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    pool: &'a crate::types::structs::IpPool,
}

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

struct CreateIpPoolRequestTypeSer<'b, 'a> {
    data: &'b CreateIpPoolRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for CreateIpPoolRequestTypeSer<'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"), &"CreateIpPoolRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("pool"), &self.data.pool as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct DestroyIpPoolRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    id: i32,
    force: bool,
}

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

struct DestroyIpPoolRequestTypeSer<'b, 'a> {
    data: &'b DestroyIpPoolRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for DestroyIpPoolRequestTypeSer<'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"), &"DestroyIpPoolRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("id"), &self.data.id as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("force"), &self.data.force as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct QueryIpAllocationsRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    pool_id: i32,
    extension_key: &'a str,
}

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

struct QueryIpAllocationsRequestTypeSer<'b, 'a> {
    data: &'b QueryIpAllocationsRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for QueryIpAllocationsRequestTypeSer<'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"), &"QueryIPAllocationsRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("poolId"), &self.data.pool_id as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct QueryIpPoolsRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
}

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

struct QueryIpPoolsRequestTypeSer<'b, 'a> {
    data: &'b QueryIpPoolsRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for QueryIpPoolsRequestTypeSer<'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"), &"QueryIpPoolsRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct ReleaseIpAllocationRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    pool_id: i32,
    allocation_id: &'a str,
}

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

struct ReleaseIpAllocationRequestTypeSer<'b, 'a> {
    data: &'b ReleaseIpAllocationRequestType<'a>,
    seq: usize,
}

impl<'b, 'a> miniserde::ser::Map for ReleaseIpAllocationRequestTypeSer<'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"), &"ReleaseIpAllocationRequestType")),
            1 => return Some((std::borrow::Cow::Borrowed("dc"), &self.data.dc as &dyn miniserde::Serialize)),
            2 => return Some((std::borrow::Cow::Borrowed("poolId"), &self.data.pool_id as &dyn miniserde::Serialize)),
            3 => return Some((std::borrow::Cow::Borrowed("allocationId"), &self.data.allocation_id as &dyn miniserde::Serialize)),
            _ => return None,
        }
    }
}
struct UpdateIpPoolRequestType<'a> {
    dc: &'a crate::types::structs::ManagedObjectReference,
    pool: &'a crate::types::structs::IpPool,
}

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

struct UpdateIpPoolRequestTypeSer<'b, 'a> {
    data: &'b UpdateIpPoolRequestType<'a>,
    seq: usize,
}

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