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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// This managed object type provides interfaces to perform resource check
/// and query for various operations, e.g.
///
/// host enter maintenance mode,
/// disk upgrade.
/// It can be accessed through MOID of 'vsan-cluster-resource-check-system',
/// via vSAN service on vCenter at cluster level, or accessed through MOID
/// of 'vsan-resource-check-system' on ESXi host.
#[derive(Clone)]
pub struct VsanResourceCheckSystem {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl VsanResourceCheckSystem {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// ***Required privileges:*** System.Read
pub async fn vsan_host_cancel_resource_check(&self) -> Result<bool> {
let bytes = self.client.invoke("vsan", "VsanResourceCheckSystem", &self.mo_id, "VsanHostCancelResourceCheck", None).await?;
let result: bool = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Retrieve the status of the latest resource check.
///
/// If a resource check task is running, its status will be returned.
/// Otherwise the status of the last resource check will be returned.
///
/// ## Parameters:
///
/// ### resource_check_spec
/// The specification of the resource check to be queried.
/// If it is not specified, *VsanResourceCheckStatus*
/// will still be returned with *VsanResourceCheckStatus.task*
/// and/or *VsanResourceCheckStatus.parentTask* information
/// if such task is running in the specified cluster. However,
/// *VsanResourceCheckStatus.result* will not be populated in this case.
///
/// ### cluster
/// The cluster to fetch the resource check status.
///
/// ***Required privileges:*** System.Read
///
/// Refers instance of *ClusterComputeResource*.
///
/// ## Returns:
///
/// The status of the specified resource check. The resource check may
/// have not started yet, or be currently running, or have completed
/// already.
/// If a resource check has completed successfully, detailed resource
/// check result will also be included.
///
/// ## Errors:
///
/// ***NotSupported***: if run directly on an ESX Server host.
///
/// ***InvalidArgument***: Exception when the given operation is not
/// supported, some parameter is missing or incorrect
/// in the spec. For example, for host enter
/// maintenance mode operation, host vSAN UUID or
/// maintenanceSpec is not provided, or data evacuation
/// mode is not supported.
///
/// ***VsanFault***: If any error happens when retrieving
/// the resource check status.
pub async fn vsan_get_resource_check_status(&self, resource_check_spec: Option<&crate::types::structs::VsanResourceCheckSpec>, cluster: Option<&crate::types::structs::ManagedObjectReference>) -> Result<crate::types::structs::VsanResourceCheckStatus> {
let input = VsanGetResourceCheckStatusRequestType {resource_check_spec, cluster, };
let bytes = self.client.invoke("vsan", "VsanResourceCheckSystem", &self.mo_id, "VsanGetResourceCheckStatus", Some(&input)).await?;
let result: crate::types::structs::VsanResourceCheckStatus = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Perform a resource check for given spec.
///
/// Given the operation type and parameter(s) for the operation, the resource
/// check will run a point-in-time simulation based on the cluster state at
/// the time of the resource check request. It will check whether current vSAN
/// cluster has enough resource or any issue to perform the operation.
/// For example, given the host enter maintenance mode operation, the host
/// vSAN UUID and data evacuation mode, it will check whether there is enough
/// fault domains, disk capacity, etc. or any inaccessible object which can
/// prevent the host from entering maintenance mode.
/// Only one resource check should be run in a vSAN cluster at a time.
///
/// ## Parameters:
///
/// ### resource_check_spec
/// The specification of the resource check.
///
/// ### cluster
/// The cluster to run the resource check.
///
/// ***Required privileges:*** System.Read
///
/// Refers instance of *ClusterComputeResource*.
///
/// ## Returns:
///
/// A task to monitor resource check progress. Results can be obtained
/// with the API *VsanResourceCheckSystem.VsanGetResourceCheckStatus*
/// after the resource check finishes.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***NotSupported***: if run directly on an ESX Server host.
///
/// ***InvalidArgument***: Exception when the given operation is not
/// supported, some parameter is missing or incorrect
/// in the spec. For example, for host enter
/// maintenance mode operation, host vSAN UUID or
/// maintenanceSpec is not provided, or data evacuation
/// mode is not supported.
///
/// ***InvalidState***: Exception when it is not qualified to run the resource
/// check. For example, for host enter maintenance mode
/// operation, if the given host is already in maintenance
/// mode.
///
/// ***VsanFault***: If any error happens during the resource check.
///
/// ***NotFound***: Exception when the given entity in the spec cannot be
/// found.
///
/// ***NotSupported***: Exception if the resource check is not supported
/// on the given entity. For example, it's not supported
/// to run disk data evacuation resource check on an
/// unmounted disk/disk-group.
pub async fn vsan_perform_resource_check(&self, resource_check_spec: &crate::types::structs::VsanResourceCheckSpec, cluster: Option<&crate::types::structs::ManagedObjectReference>) -> Result<crate::types::structs::ManagedObjectReference> {
let input = VsanPerformResourceCheckRequestType {resource_check_spec, cluster, };
let bytes = self.client.invoke("vsan", "VsanResourceCheckSystem", &self.mo_id, "VsanPerformResourceCheck", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// ***Required privileges:*** System.Read
///
/// ## Parameters:
///
/// ### resource_check_spec
/// -
///
/// ## Returns:
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// Failure
pub async fn vsan_host_perform_resource_check(&self, resource_check_spec: &crate::types::structs::VsanResourceCheckSpec) -> Result<crate::types::structs::ManagedObjectReference> {
let input = VsanHostPerformResourceCheckRequestType {resource_check_spec, };
let bytes = self.client.invoke("vsan", "VsanResourceCheckSystem", &self.mo_id, "VsanHostPerformResourceCheck", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
}
struct VsanGetResourceCheckStatusRequestType<'a> {
resource_check_spec: Option<&'a crate::types::structs::VsanResourceCheckSpec>,
cluster: Option<&'a crate::types::structs::ManagedObjectReference>,
}
impl<'a> miniserde::Serialize for VsanGetResourceCheckStatusRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(VsanGetResourceCheckStatusRequestTypeSer { data: self, seq: 0 }))
}
}
struct VsanGetResourceCheckStatusRequestTypeSer<'b, 'a> {
data: &'b VsanGetResourceCheckStatusRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for VsanGetResourceCheckStatusRequestTypeSer<'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"), &"VsanGetResourceCheckStatusRequestType")),
1 => {
let Some(ref val) = self.data.resource_check_spec else { continue; };
return Some((std::borrow::Cow::Borrowed("resourceCheckSpec"), val as &dyn miniserde::Serialize));
}
2 => {
let Some(ref val) = self.data.cluster else { continue; };
return Some((std::borrow::Cow::Borrowed("cluster"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct VsanPerformResourceCheckRequestType<'a> {
resource_check_spec: &'a crate::types::structs::VsanResourceCheckSpec,
cluster: Option<&'a crate::types::structs::ManagedObjectReference>,
}
impl<'a> miniserde::Serialize for VsanPerformResourceCheckRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(VsanPerformResourceCheckRequestTypeSer { data: self, seq: 0 }))
}
}
struct VsanPerformResourceCheckRequestTypeSer<'b, 'a> {
data: &'b VsanPerformResourceCheckRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for VsanPerformResourceCheckRequestTypeSer<'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"), &"VsanPerformResourceCheckRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("resourceCheckSpec"), &self.data.resource_check_spec as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.cluster else { continue; };
return Some((std::borrow::Cow::Borrowed("cluster"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct VsanHostPerformResourceCheckRequestType<'a> {
resource_check_spec: &'a crate::types::structs::VsanResourceCheckSpec,
}
impl<'a> miniserde::Serialize for VsanHostPerformResourceCheckRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(VsanHostPerformResourceCheckRequestTypeSer { data: self, seq: 0 }))
}
}
struct VsanHostPerformResourceCheckRequestTypeSer<'b, 'a> {
data: &'b VsanHostPerformResourceCheckRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for VsanHostPerformResourceCheckRequestTypeSer<'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"), &"VsanHostPerformResourceCheckRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("resourceCheckSpec"), &self.data.resource_check_spec as &dyn miniserde::Serialize)),
_ => return None,
}
}
}