6.0

Table Of Contents
vSphere SDK for Perl Programming Guide
22 VMware, Inc.
TheVim::find_entity_views()subroutineusesthevaluetheuserpassesinlaterinthescript.Thevalue
mustbeoneofthemanagedentitytypeslistedasview_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 13,“OptionsAvailableforAllSDKforPerlCommands,”onpage 16.
AcalltoUtil::connect()connectstotheserver.
WhenascriptreachesthecalltoUtil::connect(),thevSphereSDKforPerlruntimecheckstheenvironment
variables,configurationfilecontents,
andcommandlineentries(inthisorder)forconnectionoptions.Ifthe
optionsarenotdefined,theruntimeusesthedefaults(localhostandnousernameandpassword)tosetup
theconnection.
Step 4: Obtain View Objects of Server-Side Managed Objects
WhenyoucallthesubroutinesintheVimpackagetoretrieveentitiesfromthehost,thevSphereSDKforPerl
runtimecreatesthecorrespondingPerlobjects(viewobjects)locally.
Example 21usestheOpts::get_option()subroutinetoassignto$entity_typethestringvalueofthe
parameterthattheuserpassesinwhen
executingthescript.Example 21thenuses$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
serversidemanagedobjectofthespecifiedentitytype.
Step 5: Process Views and Report Results
Thelastpartofthescriptprocessestheviews.Forthisstep,youmustknowtheviewobjects’propertiesand
methods,soyoumustunderstandtheserversideobjects.See“UnderstandingServerSideObjects”onpage 24
foranintroduction.Forindepthinformationaboutserversideobjects,seethevSphereAPI
ReferenceGuide
whichisincludedonthevSphereSDKforPerldocumentationpage.
BecauseviewsarePerlobjects,youusePerlobjectorientedsyntaxtoprocesstheviews.Example 21loops
throughthearrayofentitiesreturned(@$entity_views)andaccessesthenamepropertyofeachentityby
calling$entity_view->name.
Theexamplethenprintsthenameofeachentitytotheconsole.
N
OTEYourscriptmustcallOpts::parse()andOpts::validate()toprocesstheoptionsavailableforall
scripts,evenifyoudonotdefinescriptspecificcommandlineoptions.
IMPORTANTThisobjectisstaticandmustbeexplicitlyupdatedwhenthecorrespondingserversideobject
changes.