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
vSphere SDK for Perl Programming Guide
22 VMware, Inc.
TheVim::find_entity_views()subroutineusesthevaluetheuserpassesinlaterinthescript.Thevalue
mustbeoneofthemanaged‐entitytypeslistedasview_typeparametersupportedby
Vim::find_entity_views().
Whenyouattempttorunascriptanddonotsupplyallnecessaryoptions,thevSphereSDKforPerldisplays
usagehelpforthescript,asinthefollowingexample:
perl simpleclient.pl
Required command option 'entity' not specified
Common VI options:
. . .
Command-specific options:
--entity (required)
ManagedEntity type: ClusterComputeResource, ComputeResource, Datacenter,
Folder, HostSystem, ResourcePool, VirtualMachine...
Step 3: Connect to the Server
ThevSphereAPIishostedasasecureWebserviceonavCenterServerandESX/ESXisystem.Bydefault,the
WebserviceisavailableoverHTTPS.Clientsmustprovidevalidcredentialstoconnecttotheservice.
Dependingonthespecificsofyourserver,youmighthavetoenteronlyauser
nameandpassword.Youmight
needotherinformation.SeeTable 1‐3,“OptionsAvailableforAllSDKforPerlCommands,”onpage 16.
AcalltoUtil::connect()connectstotheserver.
WhenascriptreachesthecalltoUtil::connect(),thevSphereSDKforPerlruntimecheckstheenvironment
variables,configurationfilecontents,
andcommand‐lineentries(inthisorder)forconnectionoptions.Ifthe
optionsarenotdefined,theruntimeusesthedefaults(localhostandnousernameandpassword)tosetup
theconnection.
Step 4: Obtain View Objects of Server-Side Managed Objects
WhenyoucallthesubroutinesintheVimpackagetoretrieveentitiesfromthehost,thevSphereSDKforPerl
runtimecreatesthecorrespondingPerlobjects(viewobjects)locally.
Example 2‐1usestheOpts::get_option()subroutinetoassignto$entity_typethestringvalueofthe
parameterthattheuserpassesinwhen
executingthescript.Example 2‐1thenuses$entity_typeasthe
view_typeparameterinthesubsequentcalltoVim::find_entity_views().
# get all inventory objects of the specified type
my $entity_type = Opts::get_option('entity');
my $entity_views = Vim::find_entity_views(view_type => $entity_type);
TheVim::find_entity_views()subroutinecreatesalocalPerlobject(anarrayofreferences)fromthe
server‐sidemanagedobjectofthespecifiedentitytype.
Step 5: Process Views and Report Results
Thelastpartofthescriptprocessestheviews.Forthisstep,youmustknowtheviewobjects’propertiesand
methods,soyoumustunderstandtheserver‐sideobjects.See“UnderstandingServer‐SideObjects”onpage 24
foranintroduction.Forin‐depthinformationaboutserver‐sideobjects,seethevSphereAPI
ReferenceGuide
whichisincludedonthevSphereSDKforPerldocumentationpage.
BecauseviewsarePerlobjects,youusePerlobject‐orientedsyntaxtoprocesstheviews.Example 2‐1loops
throughthearrayofentitiesreturned(@$entity_views)andaccessesthenamepropertyofeachentityby
calling$entity_view->name.
Theexamplethenprintsthenameofeachentitytotheconsole.
N
OTEYourscriptmustcallOpts::parse()andOpts::validate()toprocesstheoptionsavailableforall
scripts,evenifyoudonotdefinescript‐specificcommand‐lineoptions.
IMPORTANTThisobjectisstaticandmustbeexplicitlyupdatedwhenthecorrespondingserver‐sideobject
changes.