6.5
Table Of Contents
- vSphere SDK for Perl Programming Guide
- Contents
- Getting Started with vSphere SDK for Perl
- Writing vSphere SDK for Perl Scripts
- Refining vSphere SDK for Perl Scripts
- Creating and Using Filters
- Filtering Views Selectively Using Properties
- Retrieving the ServiceInstance Object on a vSphere Host
- Saving and Using Sessions
- Using Multiple Sessions
- Learning About Object Structure Using Data::Dumper
- Specifying Untyped Arguments in Scheduled Tasks and Callbacks
- Using Advanced Subroutines
- vSphere SDK for Perl Subroutine Reference
- Web Services for Management Perl Library
- Credential Store Perl Library
VMware, Inc. 31
Chapter 2 Writing vSphere SDK for Perl Scripts
Examples of Operations
ThefollowingtablelistssomeoftheoperationsavailableforaVirtualMachinemanagedobject.
SeethevSphereAPIReferenceGuideforlistsofalloperationsforeachmanagedobject.
Calling Methods
Afteryouhaveretrievedtheviewobjectthatcorrespondstoamanagedobject,youcanrunmethodsonthat
viewtomakeuseofthemanagedobject’sservices.Yourunamethodbyspecifyingthemethod’sname
parameter,forexample:
$vm->MigrateVM (name => 'productionVM');
ThetypeofparameterrequiredbythemethoddependsontheoperationdefinedinthevSphereAPI.Itmight
beasimpletype,dataobject,ormanagedobjectreference.Forinformationaboutspecificparametersanddata
types,seethevSphereAPIReferenceGuide.
Blockingoperationsarerunasmethodson
aviewobject.Forexample,tosuspendavirtualmachine,call:
$vm_view->SuspendVM();
Youcanexecuteanyoperationthatisdefinedforamanagedobjectasamethodonacorrespondingview
object.BecausethevSphereSDKforPerlcreatesanaccessorandamutatormethod(getterandsettermethod)
foreachpropertydefinedinthemanagedobject,youcanreferencethenameof
anypropertyasamethodcall
oftheview,forexample:
my $network_name = $network_view->name
ThevSphereSDKforPerlallowsyoutopassaviewobjecttoamethodthatrequiresa
ManagedObjectReference.Forexample,ifyouhavetheviewthatrepresentsahost($host),youcanpassthe
viewtothepowerOn()methodasfollows:
my $host = Vim::find_entity_view (view_type => 'HostSystem', name => 'my host');
my $vm = Vim::find_entity_view (view_type => 'VirtualMachine', name => 'my virtual machine');
$vm->powerOn (host => $host)
Omitting Optional Arguments in Method Calls
WhenyoucallavSphereAPImethodusingvSphereSDKforPerl,andwanttoomitanoptionalargument,
youcandooneoftwothings:
Youcanomittheargument:
$vm->PowerOnVM(host => $host); # with the optional host argument
$vm->PowerOnVM(); # without the optional host argument
Youcansupplyundefasthevalueoftheoptionalargument:
$vm->PowerOnVM(host => undef);
Supplyingundefasthevalueoftheoptionalargumentisusefulwhenthevalueofanargument,whichmight
ormightnotbeundef,iscontainedinavariable,asinthefollowingexample:
my $host = Vim::find_entity_view(
Table 2-4. Examples for Asynchronous and Synchronous Methods
vSphere API
Non-blocking (asynchronous)
vSphere SDK for Perl
Non-blocking (asynchronous)
vSphere SDK for Perl Only
Blocking (synchronous)
PowerOnVM_Task() PowerOnVM_Task() PowerOnVM()
CloneVM_Task() CloneVM_Task() CloneVM()
SuspendVM_Task() SuspendVM_Task() SuspendVM()
NOTE“SpecifyingUntypedArgumentsinScheduledTasksandCallbacks”onpage 39discussesusingthe
vSphereSDKforPerlPrimTypestructureinsomecalls.