use std::sync::Arc;
use crate::core::client::{VimClient, Result};
#[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(),
}
}
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)
}
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)
}
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)
}
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
}
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)
}
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),
}
}
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
}
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,
}
}
}