6.5

Table Of Contents
VMware, Inc. 33
3
ThischapterdiscussessomeprogrammingtechniquesforyourvSphereSDKforPerlscripts.
Thechapterincludesthesetopics:
“CreatingandUsingFilters”onpage 33
“FilteringViewsSelectivelyUsingProperties”onpage 34
“RetrievingtheServiceInstanceObjectonavSphereHost”onpage 36
“SavingandUsingSessions”onpage 36
“UsingMultipleSessions”onpage 37
“LearningAboutObjectStructureUsingData::Dumperonpage 38
“SpecifyingUntypedArgumentsinScheduledTasksandCallbacks”onpage 39
“UsingAdvancedSubroutines”onpage 40
Creating and Using Filters
YoucanusethevSphereSDKforPerltodefineandusefiltersthatselectobjectsbasedonpropertyvalues.
Filterscanreducealargeresultsettoonlythoseobjectswithcharacteristicsofinteresttoyou.
Using Filters with Vim::find_entity_view() or Vim::find_entity_views()
YoucancallVim::find_entity_view()orVim::find_entity_views()toretrieveobjectsfromthe
ESX/ESXihost.Vim::find_entity_view()returnsthefirstobjectitfindsthatmatchesthesearchcriteria.
Vim::find_entity_views()returnsallobjects.
WhenyoucallVim::find_entity_view()thefirstobjectfoundmightnotbetheoneyouarelookingfor.For
example,youmightwant
toretrieveonlythosevirtualmachineobjectswhosenamesbeginwithacertain
prefix.WhenyoucallVim::find_entity_views(),thecommandmightreturnmoreobjectsthanyouwant
toworkwith,forexampleallvirtualmachinesinadatacenter.Youcanapplyoneormorefiltersto
Vim::find_entity_view()andVim::find_entity_views()to
selectasubsetofobjectsbasedonproperty
values.
ToapplyafiltertotheresultsofVim::find_entity_view()orVim::find_entity_views(),yousupplyan
optionalfilterparameter.Thevalueoftheparameterisananonymoushashreferencecontainingoneor
morepairsoffiltercriteria.Eachofthecriteriaisa
propertypathandamatchvalue.Thematchvaluecanbe
eitherastringoraregularexpressionobject.Ifthematchvalueisastring,thevalueofthepropertymustmatch
thestringexactly(includingcase).TomatchBooleanvalues,usethestringstrueandfalse.
Thefollowing
filterparametermatchesavirtualmachinepowerstateofpoweredOff:
filter => { 'runtime.powerState' => 'poweredOff' }
Refining vSphere SDK for Perl Scripts
3