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
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// The *InventoryView* managed object provides a means of browsing the inventory and tracking
/// changes to open folders.
///
/// This managed object is particularly useful for UI clients that
/// display a tree-based navigation panel of the inventory.
///
/// *InventoryView* maintains the *ManagedObjectView.view* list
/// of managed object references to inventory objects. When you create an inventory view
/// (*ViewManager.CreateInventoryView*), the server initializes the view's object
/// list with a single folder - the root folder.
///
/// *InventoryView* provides methods to open and close folders in the inventory. Use these
/// methods to add and subtract objects from the *ManagedObjectView.view* list.
/// Use the *InventoryView* together with the *PropertyCollector*
/// to manage the data resulting from *InventoryView.OpenInventoryViewFolder*
/// and *InventoryView.CloseInventoryViewFolder* methods. By using the *PropertyCollector*,
/// you have access to the modifications to the view, rather than processing the entire view list.
///
/// For example, you might use the following sequence of operations with
/// an *InventoryView* and the *PropertyCollector*:
/// 1. Create an *InventoryView*.
/// 2. Create a filter specification for the *PropertyCollector*.
/// - Use the *InventoryView* as the starting object in the
/// *ObjectSpec* for the filter.
/// - Use a set of *TraversalSpec*
/// data objects to identify paths in possible inventory configurations.
/// - Use the *PropertySpec*
/// to identify object properties for retrieval.
/// 3. Use either the *PropertyCollector.CheckForUpdates* or
/// *PropertyCollector.WaitForUpdates* method to obtain
/// *InventoryView* modifications. Both methods return
/// an *UpdateSet* object that describes
/// the changes returned by the *PropertyCollector*.
/// 4. Call the *InventoryView.OpenInventoryViewFolder* or *method*.
#[derive(Clone)]
pub struct InventoryView {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl InventoryView {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Notify the server that folder(s) have been closed, and changes for all
/// its contained objects should no longer be sent.
///
/// The associated child
/// objects are removed from the view. The containers themselves
/// will still be retained as open objects until their parent is closed.
///
/// May partially succeed if some entities could not be resolved. The operation
/// will still succeed for all entities that could be resolved, and the
/// list of those that failed is returned as the result.
///
/// ## Parameters:
///
/// ### entity
/// An array of managed object references. Each array entry is a
/// reference to an entity to collapse.
///
/// ***Required privileges:*** System.View
///
/// Refers instances of *ManagedEntity*.
///
/// ## Returns:
///
/// A list containing any entities in the argument could not be resolved.
///
/// Refers instances of *ManagedEntity*.
pub async fn close_inventory_view_folder(&self, entity: &[crate::types::structs::ManagedObjectReference]) -> Result<Option<Vec<crate::types::structs::ManagedObjectReference>>> {
let input = CloseInventoryViewFolderRequestType {entity, };
let bytes_opt = self.client.invoke_optional("", "InventoryView", &self.mo_id, "CloseInventoryViewFolder", Some(&input)).await?;
match bytes_opt {
Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
None => Ok(None),
}
}
/// Destroy this view.
///
/// ***Required privileges:*** System.View
pub async fn destroy_view(&self) -> Result<()> {
self.client.invoke_void("", "InventoryView", &self.mo_id, "DestroyView", None).await
}
/// Adds the child objects of a given managed entity to the view.
///
/// If a *Datacenter* is returned as a child, the implicit virtual machine folder and
/// host folder objects are also returned. If a *ComputeResource* is returned,
/// the implicit root *ResourcePool* and *HostSystem* objects are also returned.
///
/// May partially succeed if some entities could not be resolved. The operation
/// will still succeed for all entities which could be resolved, and the
/// list of those which failed is returned as the result.
///
/// ## Parameters:
///
/// ### entity
/// An array of managed object references. Each array entry is a reference
/// to an entity to expand. Expands each entity in the
/// order given. If an entity is not in the current view,
/// expands the view as needed.
///
/// ***Required privileges:*** System.View
///
/// Refers instances of *ManagedEntity*.
///
/// ## Returns:
///
/// A list containing any entities in the argument could not be resolved.
///
/// Refers instances of *ManagedEntity*.
pub async fn open_inventory_view_folder(&self, entity: &[crate::types::structs::ManagedObjectReference]) -> Result<Option<Vec<crate::types::structs::ManagedObjectReference>>> {
let input = OpenInventoryViewFolderRequestType {entity, };
let bytes_opt = self.client.invoke_optional("", "InventoryView", &self.mo_id, "OpenInventoryViewFolder", Some(&input)).await?;
match bytes_opt {
Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
None => Ok(None),
}
}
/// The list of references to objects mapped by this view.
pub async fn view(&self) -> Result<Option<Vec<crate::types::structs::ManagedObjectReference>>> {
let pv_opt = self.client.fetch_property_raw("", "InventoryView", &self.mo_id, "view").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
}
struct CloseInventoryViewFolderRequestType<'a> {
entity: &'a [crate::types::structs::ManagedObjectReference],
}
impl<'a> miniserde::Serialize for CloseInventoryViewFolderRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(CloseInventoryViewFolderRequestTypeSer { data: self, seq: 0 }))
}
}
struct CloseInventoryViewFolderRequestTypeSer<'b, 'a> {
data: &'b CloseInventoryViewFolderRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for CloseInventoryViewFolderRequestTypeSer<'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"), &"CloseInventoryViewFolderRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("entity"), &self.data.entity as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct OpenInventoryViewFolderRequestType<'a> {
entity: &'a [crate::types::structs::ManagedObjectReference],
}
impl<'a> miniserde::Serialize for OpenInventoryViewFolderRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(OpenInventoryViewFolderRequestTypeSer { data: self, seq: 0 }))
}
}
struct OpenInventoryViewFolderRequestTypeSer<'b, 'a> {
data: &'b OpenInventoryViewFolderRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for OpenInventoryViewFolderRequestTypeSer<'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"), &"OpenInventoryViewFolderRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("entity"), &self.data.entity as &dyn miniserde::Serialize)),
_ => return None,
}
}
}