-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainer-View-Example.py
45 lines (36 loc) · 1.44 KB
/
Container-View-Example.py
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
def _get_content(obj_type, property_list=None):
# Get service instance object
si = _get_si()
# Refer to http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.pg.doc_50%2FPG_Ch5_PropertyCollector.7.6.html for more information.
# Create an object view
obj_view = si.content.viewManager.CreateContainerView(si.content.rootFolder, [obj_type], True)
# Create traversal spec to determine the path for collection
traversal_spec = vmodl.query.PropertyCollector.TraversalSpec(
name='traverseEntities',
path='view',
skip=False,
type=vim.view.ContainerView
)
# Create property spec to determine properties to be retrieved
property_spec = vmodl.query.PropertyCollector.PropertySpec(
type=obj_type,
all=True if not property_list else False,
pathSet=property_list
)
# Create object spec to navigate content
obj_spec = vmodl.query.PropertyCollector.ObjectSpec(
obj=obj_view,
skip=True,
selectSet=[traversal_spec]
)
# Create a filter spec and specify object, property spec in it
filter_spec = vmodl.query.PropertyCollector.FilterSpec(
objectSet=[obj_spec],
propSet=[property_spec],
reportMissingObjectsInResults=False
)
# Retrieve the contents
content = si.content.propertyCollector.RetrieveContents([filter_spec])
# Destroy the object view
obj_view.Destroy()
return content