You can specify a smaller and more efficient data set using one of the ViewManager views with the Property Collector. Each view represents objects you have selected on the server. Views are more efficient because you only need a single instance of a
PropertyCollector object, instead of multiple instances with multiple filter specifications.
Use one of the ViewManager methods to obtain information about
Task objects and references while the session is running. The ViewManager’s
ListView method allows you to customize your view with an input object list, the
ContainerView method lets you view all objects in a folder, datacenter, resource pool, or other data container, and the
InventoryView method lets you monitor the entire inventory. The smallest view you can create will be the most efficient way to retrieve task data.
The ViewManager has the following property:
viewList – An array of view references. Each array entry is a managed object reference to a view created by this View Manager.
See PropertyCollector Example (RetrievePropertiesEx) for an example that uses the
ContainerView method to access Inventory data.
Use the ViewManager’s ListView method to specify the set of tasks that you want to monitor.
The following example uses the ViewManager service interface with a
ListView method to access and manipulate
Task objects. This example uses the property collector to monitor tasks that are created in the process of virtual machine cloning. This program creates two clones of the specified virtual machine and then monitors the tasks and prints out status and reference values when the tasks have completed.
Now that we have the reference information for the virtual machine that you specified on the command line (vmRef) and a reference for the parent directory (
folderRef), we are ready to create the clone virtual machines.
In the next section, we use the waitForUpdatesEx method to look for a change in
cloneTask.info.state and
cloneTask.info.result. When the state is “success”,
cloneTask.info.result is the managed object reference of the clone. Note that the order of property retrieval is not guaranteed, and it may take more than one call to
waitForUpdatesEx to retrieve both properties for a task.
This code does not set a time-out (WaitOptions.maxWaitSeconds is unset), so after it has retrieved all of the property values,
waitForUpdatesEx will block the thread, waiting for the TCP connection with the vSphere Server to time-out.
TaskManager is a service interface that you can also use for accessing and manipulating
Task objects. This approach uses a
PropertyCollector that includes the
recentTask property of the
TaskManager managed object that corresponds to the Recent Tasks pane at the bottom of the vSphere client User Interface.
You can use the following TaskManager properties in your client application.
In addition to these properties, TaskManager has the following methods:
TaskManager and Task Managed Objects shows a UML class diagram for
TaskManager and associated objects.
To obtain the list of recent tasks, use a PropertyCollector to obtain references to the
TaskManager and to all
Task objects from the
recentTask property of the
TaskManager.
Example: PropertyFilterSpec Definition to Obtain recentTask Property Values shows an excerpt from the
TaskList.java sample that creates the
ObjectSpec,
PropertySpec, and a
TraversalSpec to obtain references to all
Task objects on the server from the
TaskList. See also
Property Collector.