This procedure shows how to use the PropertyCollector
to retrieve a property from a VirtualMachine
object with the RetrieveProperiesEx
method. The example retrieves a managed object reference to the parent object of a VirtualMachine
object in the inventory hierarchy.
To retrieve a reference to the parent object of a specific virtual machine, you must:
- Prepare a
PropertySpec
to specify theparent
property and theparentVApp
property of theVirtualMachine
class. A virtual machine can have only one parent, but the parent can be either a Folder object or a VirualApp object. This example collects both properties, one of which will be null. - Prepare an
ObjectSpec
to identify the starting object, which is the specifiedVirtualMachine
. There is no need for aTraversalSpec
because the property belongs to the starting object itself. However, theObjectSpec.skip
property is set tofalse
; a value oftrue
would cause the PropertyCollector not to collect properties from the starting object. - Assemble a
PropertyFilterSpec
from the prepared data. - Invoke the
RetrievePropertiesEx
method.
Prerequisites
- A virtual machine managed object reference in a variable named
vmRef
. - An authenticated Web Services session with the vSphere server that manages the virtual machine.
- A
VimPort
binding provider referenced by the variablemethods
, which is attached to the vSphere server connection context. - A
PropertyCollector
instance referenced by the variablepCollector
.
Note: This procedure shows only how to use the
PropertyCollector
. For a description of server connection and getting a reference to the
PropertyCollector
, see
Build a Simple vSphere Client Application for the Web Services SDK.
Procedure
Results
The method returns a key-value pair, name
and val
, indicating the name of the parent property and a managed object reference to the parent object.
What to do next
DynamicProperty parent = getVMParentProperty( vmRef ); if (parent.getName().equals("parentVApp")) { System.out.format("VApp MOref: %s", parent.getVal()); } else { System.out.format("Folder MOref: %s", parent.getVal()); }