Create Clones of the Virtual
MachineLast Updated December 16, 2024
Create two clones of the virtual machine and build a PropertyFilterSpec that uses a
ListView managed object to track the Tasks to completion.
For this task you need:
- A virtual machine managed object reference in a variable namedvmRef.
- 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.
- The ViewManager object is referenced by the variableviewMgr.
- A PropertyCollector instance referenced by the variablepCollector.
Given the MOref of a virtual machine and
the MOref of its parent folder, this function initiates two clone operations,
resulting in two
Task
managed objects that you can use to monitor
progress of the clone operations. The function uses the Task
objects to build a PropertyFilterSpec
that you can use to report
status updates for the two Task
objects.- Declare a method that accepts a virtual machine MOref to clone it and monitor theTaskobjects.
- Use thegetVMParentmethod to get a MOref for the parent folder of the virtual machine.If the parent object is aFolder, theCloneVMTaskmethod will create the clones in the same folder that contains the specified virtual machine. If the parent object is aVirtualApp, theVirtualMachinecannot be cloned.
- Create a clone specification. Use default values whenever possible.
- Create two clone virtual machines.TheCloneVMTaskmethod returns aTaskobject from each invocation. You can use PropertyCollector to track task completion.
- Create a list view to reference the clone tasks.
- Create an object spec to describe the property collection.Add the list ofTaskobjects to the object spec. Set theskipproperty totrueso the PropertyCollector will ignore the properties of theListViewobject itself.
- Create a traversal spec to tell the PropertyCollector how to move from theListViewobject to theTaskobjects.Set theskipproperty tofalseso the PropertyCollector will try to collect properties from the managed objects at the end of this traversal step.
- Add the traversal spec to the object spec.
- Create a property spec to collect theTask.info.stateandTask.info.resultproperties.
- Create a filter spec from the object spec and the property spec, and use the filter spec to create aPropertyFilterobject to guide the property collection.The filter managed object needs to persist on the server until the PropertyCollector finishes reporting task status.
Two cloning operations are underway, with status of the operations reflected in
Task
objects. A PropertyFitler
managed object
is created and configured to monitor the task status.Use the
PropertyCollector.WaitForUpdatesEx
method to monitor the
status of the Task
objects.