vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> <strong>Programming</strong> <strong>Guide</strong><br />
To create an enumeration data object, use a string value as the argument to the enumeration type’s constructor.<br />
my $power_state = VirtualMachinePowerState->new('poweredOff');<br />
Typically, enumerations are used as arguments to methods:<br />
$vm->MigrateVM(<br />
host => $target_host,<br />
priority => VirtualMachineMovePriority->new('defaultPriority'),<br />
state => VirtualMachinePowerState->new('poweredOff'),<br />
);<br />
Creating Data Objects with Properties<br />
You create data objects with constructors that have names corresponding to the classes of the data objects in<br />
the <strong>vSphere</strong> API. The constructor syntax follows common <strong>Perl</strong> conventions. The arguments supplied to the<br />
constructor are key‐value pairs, where each key is the name of an object property, and the corresponding value<br />
is the value with which the property is initialized.<br />
For example, creating a virtual machine requires the creation of a data structure that includes a number of<br />
nested data objects. One of those objects is a VirtualMachineFieldInfo data object, which can be<br />
constructed as follows:<br />
my $files = VirtualMachineFileInfo->new<br />
(<br />
logDirectory => undef,<br />
snapshotDirectory => undef,<br />
suspendDirectory => undef,<br />
vmPathName => $ds_path<br />
);<br />
The VirtualMachineFileInfo object is then contained within a VirtualMachineConfigSpec object:<br />
my $vm_config_spec = VirtualMachineConfigSpec->new(<br />
name => $args{vmname},<br />
memoryMB => $args{memory},<br />
files => $files, # $args{num_cpus},<br />
guestId => $args{guestid},<br />
deviceChange => \@vm_devices<br />
);<br />
This code is taken from the apps/vm/vmcreate.pl utility application. See the scripts in the apps and samples<br />
directories <strong>for</strong> examples of simple and complex uses of data objects.<br />
To set the value of a property that is defined as an enumeration, you must pass the new value to the data object<br />
as follows:<br />
$ = new ('');<br />
For example, you can change the power state as follows:<br />
$power_state = new VirtualMachinePowerState ('poweredOff');<br />
Understanding Operations and Methods<br />
The <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> runtime maps server‐side operations to client‐side <strong>Perl</strong> view object methods. For<br />
each operation defined on a server managed object, the <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> creates a corresponding view<br />
method when it creates the view object.<br />
30 <strong>VMware</strong>, Inc.