6.0
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. 39
Chapter 3 Refining vSphere SDK for Perl Scripts
'localeVersion' => 'INTL',
'name' => 'VMware ESX Server',
'osType' => 'vmnix-x86',
'productLineId' => 'esx',
'vendor' => 'VMware, Inc.',
'version' => '3.0.1'
}, 'AboutInfo' );
Theoutputaboveshowsthecontentofthesummary.config.productpropertyofaHostSystemmanaged
object.Thetype(ormoreproperlyclass)ofsummary.config.productpropertyisAboutInfo.Perl’ s
Data::Dumpermodulewritestheobjectinaformthatcanbeusedwithevaltogetbackacopyoftheoriginal
structure.
TheblesskeywordindicatesthedataisaPerlobject,andthelastargumenttoblessistheclassof
theobject,AboutInfo.
Line19(inExample 3‐4)retriev estheHostSystemviewobjectandline21printsthenameassociatedwiththe
correspondinghost.
Theconfigpropertyhasmorevaluesthan
thoseprintedbyline23.Line25printstheentireconfigobject.
Insidetheconfigobjectprintedbyline25(inExample 3‐4),theproductpropertyisanobject.Thebless
functionreturnsareferencetotheproductobject,whichisitselfnestedinsidetheconfigobject.
$VAR1 = bless( {
'name' => 'test-system.eng.vmware.com',
'port' => 'nnn',
'product' => bless( {
'apiType' => 'HostAgent',
'apiVersion' => '4.0.0',
'build' => '31178',
'fullName' => 'VMware ESX Server 3.0.1 build-31178',
'localeBuild' => '000',
'localeVersion' => 'INTL',
'name' => 'VMware ESX Server',
'osType' => 'vmnix-x86',
'productLineId' => 'esx',
'vendor' => 'VMware, Inc.',
'version' => '3.0.1'
}, 'AboutInfo' ),
'vmotionEnabled' => 'false'
}, 'HostConfigSummary' );
Theoutputfromline27ofExample 3‐4printsthestructureoftheentiresummaryobjectofthehostview.The
outputshowsanumberofnestedobjects,includingtwoobjectsthatarenestedtwolevelsdeep.Theproduct
objectisnestedinsidetheconfigobject,andtheconnectionStateobjectis
nestedinsidetheruntimeobject.
Specifying Untyped Arguments in Scheduled Tasks and Callbacks
BecauseofthewayvSphereSDKforPerlmapsthevSphereAPIintoPerl,youhavetospecifyargumentsto
callbackmethodsdifferentlyfromthewayyouspecifyargumentstoothermethods.YoucanusePrimTypeto
specifyuntypedargumentsinscheduledtasksandcallbacks.
Youmustspecifytheargumentspositionally,intheorderdefinedinthebindingsforotherlanguageslike
Java.
YoumustindicatethetypeofeachargumentusingthePrimTypeconstructor.
Forexample,considerascheduledtaskthatperiodicallycreatesasnapshot.TheCreateSnapshot()method
takesfourarguments,name,description,memory,andquiesce.
YoumustdefinetheargumentsbeforeyouusethembycreatingfourMethodActionArgumentobjectswith
PrimTypevalues,asfollows:
my $name = MethodActionArgument->new(
value => PrimType->new('Sample snapshot task', 'string')
);
my $description = MethodActionArgument->new(
value => PrimType->new('Created from a sample script', 'string')
);