6.0

Table Of Contents
vSphere SDK for Perl Programming Guide
30 VMware, Inc.
);
Creating Data Objects with Properties
Youcreatedataobjectswithconstructorsthathavenamescorrespondingtotheclassesofthedataobjectsin
thevSphereAPI.TheconstructorsyntaxfollowscommonPerlconventions.Theargumentssuppliedtothe
constructorarekeyvaluepairs,whereeachkeyisthenameofanobjectproperty,andthecorresponding
value
isthevaluewithwhichthepropertyisinitialized.
Forexample,creatingavirtualmachinerequiresthecreationofadatastructurethatincludesanumberof
nesteddataobjects.OneofthoseobjectsisaVirtualMachineFieldInfodataobject,whichcanbe
constructedasfollows:
my $files = VirtualMachineFileInfo->new
(
logDirectory => undef,
snapshotDirectory => undef,
suspendDirectory => undef,
vmPathName => $ds_path
);
TheVirtualMachineFileInfoobjectisthencontainedwithinaVirtualMachineConfigSpecobject:
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
);
Thiscodeistakenfromtheapps/vm/vmcreate.plutilityapplication.Seethescriptsintheappsandsamples
directoriesforexamplesofsimpleandcomplexusesofdataobjects.
Tosetthevalueofapropertythatisdefinedasanenumeration,youmustpassthenewvaluetothedataobject
asfollows:
$<ref> = new <enum_type> ('<val>');
Forexample,youcanchangethepowerstateasfollows:
$power_state = new VirtualMachinePowerState ('poweredOff');
Understanding Operations and Methods
ThevSphereSDKforPerlruntimemapsserversideoperationstoclientsidePerlviewobjectmethods.For
eachoperationdefinedonaservermanagedobject,thevSphereSDKforPerlcreatesacorrespondingview
methodwhenitcreatestheviewobject.
Non-Blocking and Blocking Methods
AllserversideoperationsavailableinthevSphereAPIarenonblockingoperationslistedinthevSphereAPI
ReferenceGuide.ThevSphereSDKforPerlprovidesanonblockingmethodcorrespondingtotheserverside
operation,andalsoprovidesablocking(synchronous)method(<opname>()method).
NonblockingmethodsAsynchronousmethodsthatreturncontroltotheclientimmediatelyafter
invocationandreturnataskobjecttothecallingprogram.Nonblockingmethodsallowyoutomonitor
progress(ofthe*_Taskobject)outsidethemainprocessinglogicofthescript.Thismonitoringcanbe
usefulduringlong
runningoperations.Thesemethodsalsoallowyoutointerleavelocal(clientside)
processingandserversideprocessing.
BlockingmethodsSynchronousmethodsthatfullyprocesstheoperationbeforereturningcontroltothe
clientscript.Doesnotreturnareferencetoataskobject.Ifyouuseablockingmethod,youdonothaveto
handleataskobjectwithadditionalcode.