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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// The DatastoreBrowser managed object type provides access to the contents of one or
/// more datastores.
///
/// The items in a datastore are files that contain configuration,
/// virtual disk, and the other data associated with a virtual machine.
///
/// Although datastores may often be implemented using a traditional file system, a full
/// interface to a file system is not provided here. Instead, specialized access for
/// virtual machine files is provided. A datastore implementation may completely hide the
/// file directory structure.
///
/// The intent is to provide functionality analogous to a file chooser in a user
/// interface.
///
/// Files on datastores do not have independent permissions through this API. Instead,
/// the permissions for all the files on a datastore derive from the datastore object
/// itself. It is not possible to change individual file permissions as the user browsing
/// the datastore may not necessarily be a recognized user from the point of view of the
/// host changing the permission. This occurs if the user browsing the datastore is doing
/// so through the VirtualCenter management server.
///
/// The DatastoreBrowser provides many ways to customize a search for files. A search can
/// be customized by specifying the types of files to be searched, search criteria
/// specific to a file type, and the amount of detail about each file. The most basic
/// queries only use file details and are efficient with limited side effects. For these
/// queries, file metadata details can be optionally retrieved, but the files themselves
/// are opened and their contents examined. As a result, these files are not necessarily
/// validated.
///
/// More complicated queries can be formed by specifying the specific types of files to
/// be searched, the parameters to filter for each type, and the desired level of detail
/// about each file. This method of searching for files is convenient because it allows
/// additional data about the virtual machine component to be retrieved. In addition,
/// certain validation checks can be performed on matched files as an inherent part of
/// the details collection process. However, gathering extra details or the use of type
/// specific filters can sometimes only be implemented by examining the contents of a
/// file. As a result, the use of these conveniences comes with the cost of additional
/// latency in the request and possible side effects on the system as a whole.
///
/// The DatastoreBrowser is referenced from various objects, including from
/// *Datastore*, *ComputeResource*, *HostSystem* and
/// *VirtualMachine*. Depending on which object is used, there are different
/// requirements for the accessibility of the browsed datastore from the host (or hosts)
/// associated with the object:
/// - When referenced from the target *Datastore*, it needs to be
/// accessible from at least one host on which the datastore is mounted.
/// See *DatastoreSummary.accessible*.
/// - When referenced from a *ComputeResource*, the target datastore
/// needs to be accessible from at least one host in the ComputeResource.
/// See *HostMountInfo.accessible*.
/// - When referenced from a *HostSystem*, the target datastore needs
/// to be accessible from that host. See *HostMountInfo.accessible*.
/// - When referenced from a *VirtualMachine*, the target datastore
/// needs to be accessible from the host on which the virtual machine is
/// registered. See *HostMountInfo.accessible*.
///
/// See also *FileInfo*.
#[derive(Clone)]
pub struct HostDatastoreBrowser {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl HostDatastoreBrowser {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Deprecated as of VI API 2.5, use *FileManager.DeleteDatastoreFile_Task*.
///
/// Deletes the specified files from the datastore.
///
/// If a valid virtual disk file is
/// specified, then all the components of the virtual disk are deleted.
///
/// ***Required privileges:*** Datastore.DeleteFile
///
/// ## Parameters:
///
/// ### datastore_path
/// -
///
/// ## Errors:
///
/// ***InvalidDatastore***: if the operation cannot be performed on the target
/// datastores. Typically, a specific subclass of this exception is thrown.
///
/// ***FileNotFound***: if the file or folder specified by datastorePath is not
/// found.
///
/// ***CannotDeleteFile***: if the delete operation on the file fails.
///
/// ***InvalidArgument***: if fileInfo is not a valid FileInfo type.
pub async fn delete_file(&self, datastore_path: &str) -> Result<()> {
let input = DeleteFileRequestType {datastore_path, };
self.client.invoke_void("", "HostDatastoreBrowser", &self.mo_id, "DeleteFile", Some(&input)).await
}
/// Returns the information for the files that match the given search criteria as a
/// SearchResults object.
///
/// Searches only the folder specified by the datastore path.
/// The Datastore.Browse privilege must be held on the datastore identified
/// by the datastore path.
///
/// ## Parameters:
///
/// ### datastore_path
/// -
///
/// ### search_spec
/// -
///
/// ## Returns:
///
/// This method returns a *Task* object with which to monitor the
/// operation. The *info.result* property in the
/// *Task* contains the
/// *HostDatastoreBrowserSearchResults* upon success.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***InvalidDatastore***: if the operation cannot be performed on the target
/// datastores. The server can throw InvalidDatastorePath to indicate a malformed
/// datastorePath, or InaccessibleDatastore to indicate inaccessibility of the
/// datastore.
///
/// ***InvalidArgument***: if the SearchSpec contains duplicate file types.
///
/// ***FileNotFound***: if the file or folder specified by datastorePath is not
/// found.
pub async fn search_datastore_task(&self, datastore_path: &str, search_spec: Option<&crate::types::structs::HostDatastoreBrowserSearchSpec>) -> Result<crate::types::structs::ManagedObjectReference> {
let input = SearchDatastoreRequestType {datastore_path, search_spec, };
let bytes = self.client.invoke("", "HostDatastoreBrowser", &self.mo_id, "SearchDatastore_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Returns the information for the files that match the given search criteria as a
/// SearchResults\[\] object.
///
/// Searches the folder specified by the datastore path and
/// all subfolders. The Datastore.Browse privilege must be held on the
/// datastore identified by the datastore path.
///
/// ## Parameters:
///
/// ### datastore_path
/// -
///
/// ### search_spec
/// -
///
/// ## Returns:
///
/// This method returns a *Task* object with which to monitor the
/// operation. The *info.result* property in the
/// *Task* contains the
/// *HostDatastoreBrowserSearchResults* upon success.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***InvalidDatastore***: if the operation cannot be performed on the target
/// datastores. Typically, a specific subclass of this exception is thrown.
///
/// ***InvalidArgument***: if the SearchSpec contains duplicate file types.
///
/// ***FileNotFound***: if the file or folder specified by datastorePath is not
/// found.
pub async fn search_datastore_sub_folders_task(&self, datastore_path: &str, search_spec: Option<&crate::types::structs::HostDatastoreBrowserSearchSpec>) -> Result<crate::types::structs::ManagedObjectReference> {
let input = SearchDatastoreSubFoldersRequestType {datastore_path, search_spec, };
let bytes = self.client.invoke("", "HostDatastoreBrowser", &self.mo_id, "SearchDatastoreSubFolders_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Set of datastores that can be searched on this DatastoreBrowser.
///
/// The list of datastores available to browse on this DatastoreBrowser is contextual
/// information that depends on the object being browsed. If the host is being
/// browsed, the host's datastores are used. If the Datacenter is being browsed, the
/// Datacenter's list of datastores is used.
///
/// ***Required privileges:*** System.View
///
/// ## Returns:
///
/// Refers instances of *Datastore*.
pub async fn datastore(&self) -> Result<Option<Vec<crate::types::structs::ManagedObjectReference>>> {
let pv_opt = self.client.fetch_property_raw("", "HostDatastoreBrowser", &self.mo_id, "datastore").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
/// The list of supported file types.
///
/// The supported file types are represented as
/// items in this list. For each supported file type, there is an object in the list
/// whose dynamic type is one of the types derived from the
/// *FileQuery* data object
/// type. In general, the properties in this query type are not set.
///
/// Use the Query of the desired file type in the SearchSpec.query to indicate the
/// desired file types.
///
/// This property is used by clients to determine what kinds of file types are
/// supported. Clients should consult this list to avoid querying for types of virtual
/// machine components that are not supported.
pub async fn supported_type(&self) -> Result<Option<Vec<Box<dyn crate::types::traits::FileQueryTrait>>>> {
let pv_opt = self.client.fetch_property_raw("", "HostDatastoreBrowser", &self.mo_id, "supportedType").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
}
struct DeleteFileRequestType<'a> {
datastore_path: &'a str,
}
impl<'a> miniserde::Serialize for DeleteFileRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(DeleteFileRequestTypeSer { data: self, seq: 0 }))
}
}
struct DeleteFileRequestTypeSer<'b, 'a> {
data: &'b DeleteFileRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for DeleteFileRequestTypeSer<'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"), &"DeleteFileRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("datastorePath"), &self.data.datastore_path as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct SearchDatastoreRequestType<'a> {
datastore_path: &'a str,
search_spec: Option<&'a crate::types::structs::HostDatastoreBrowserSearchSpec>,
}
impl<'a> miniserde::Serialize for SearchDatastoreRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(SearchDatastoreRequestTypeSer { data: self, seq: 0 }))
}
}
struct SearchDatastoreRequestTypeSer<'b, 'a> {
data: &'b SearchDatastoreRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for SearchDatastoreRequestTypeSer<'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"), &"SearchDatastoreRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("datastorePath"), &self.data.datastore_path as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.search_spec else { continue; };
return Some((std::borrow::Cow::Borrowed("searchSpec"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct SearchDatastoreSubFoldersRequestType<'a> {
datastore_path: &'a str,
search_spec: Option<&'a crate::types::structs::HostDatastoreBrowserSearchSpec>,
}
impl<'a> miniserde::Serialize for SearchDatastoreSubFoldersRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(SearchDatastoreSubFoldersRequestTypeSer { data: self, seq: 0 }))
}
}
struct SearchDatastoreSubFoldersRequestTypeSer<'b, 'a> {
data: &'b SearchDatastoreSubFoldersRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for SearchDatastoreSubFoldersRequestTypeSer<'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"), &"SearchDatastoreSubFoldersRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("datastorePath"), &self.data.datastore_path as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.search_spec else { continue; };
return Some((std::borrow::Cow::Borrowed("searchSpec"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}