Get_Parent_Property
Given the managed object reference for a virtual machine object, use the PropertyCollector to get the managed object reference for its parent object.
Given the MOref of a virtual machine, this function uses the PropertyCollector to retrieve the MOref of the parent of the virtual machine object. The MOref of the parent folder can be used to clone the virtual machine.
A VirtualMachine
can be
a child of either a Folder
object or a VirtualApp
object. If it is a child of a Folder
object, the
parent
property contains the MOref of the
Folder
object and the parentVApp
property is
null. If the VirtualMachine
is a child of a
VirtualApp
object, the parent
property is
null and the parentVApp
property contains the MOref of the
VirtualApp
object. The method in this example returns a
key-value pair from which the caller can determine which kind of parent the
VirtualMachine
has.
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 variable
methods
, which is attached to the vSphere server connection context. - A PropertyCollector instance
referenced by the variable
pCollector
.
Procedure
What to do next
Now that you have the reference information for the virtual machine that you specified on the command line (vmRef) and a reference for the parent (in the dp property), you are ready to extract the type and MOref of the parent.