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.

my $files = VirtualMachineFileInfo->new
(
     logDirectory => undef,
     snapshotDirectory => undef,
     suspendDirectory => undef,
     vmPathName => $ds_path
);

The VirtualMachineFileInfo object is then contained within a VirtualMachineConfigSpec object.

my $vm_config_spec = VirtualMachineConfigSpec->new(
     name => $args{vmname},
     memoryMB => $args{memory},
     files => $files,           # <-- here
     numCPUs => $args{num_cpus},
     guestId => $args{guestid},
     deviceChange => \@vm_devices
);

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.

To set the value of a property that is defined as an enumeration, you must pass the new value to the data object as follows.

$<ref> = new <enum_type> ('<val>');

For example, you can change the power state as follows.

$power_state = new VirtualMachinePowerState ('poweredOff');