To retrieve the value of a property defined as an enumeration, you must dereference its value from within the containing object by qualifying the property with
->val. For example, the power state of a virtual machine (
powerState) is a member of the
runtime data object.
To retrieve the value of powerState, you must dereference the two containing objects (the
view object and the
runtime data object) and the value itself (
val), as follows:
Because powerState is an enumeration, you use
runtime->powerState->val to retrieve its string value.
$data_object is a blessed reference to a Perl object or class name, and
property is a method call on the object.
You create data objects with constructors that have names corresponding to the classes of the data objects in the vSphere API. The constructor syntax follows common Perl conventions. The arguments supplied to the constructor are key-value pairs, where each key is the name of an object property, and the corresponding value is the value with which the property is initialized.
For example, creating a virtual machine requires the creation of a data structure that includes a number of nested data objects. One of those objects is a
VirtualMachineFieldInfo data object, which can be constructed as follows:
The VirtualMachineFileInfo object is then contained within a
VirtualMachineConfigSpec object:
This code is taken from the apps/vm/vmcreate.pl utility application. See the scripts in the
apps and
samples directories for examples of simple and complex uses of data objects.