6.0

Table Of Contents
vSphere SDK for Perl Programming Guide
36 VMware, Inc.
Forexample,tosearchforthevirtualmachineSan Jose,runthiscommand:
perl vminfo.pl --username Administrator --password 'secret' --server myserver --vmname 'San Jose'
TosearchforthevirtualmachineSan-Jose/5,runthiscommand:
perl vminfo.pl --username Administrator --password 'secret' --server myserver --vmname
'San-Jose%2f5'
Retrieving the ServiceInstance Object on a vSphere Host
YoucanretrievetheServiceInstanceobjecttoaccesstheServiceContentortoretrievethecurrenttimeon
anESX/ESXiorvCenterServersystem.
Ifyouwanttoretrievethecurrenttime,youmustretrieveaServiceInstanceobjectandcallits
CurrentTime()method.YoucanusetheVim::get_service_instance()subroutinetoretrievethe
object.
To retrieve the current VMware host time
1 ConnecttotheVMwarehost:
Util::connect();
2 RetrievetheServiceInstanceobject:
my $service_instance = Vim::get_service_instance();
3 Retrievethecurrenthosttime:
$service_instance->CurrentTime();
Saving and Using Sessions
ThevSphereSDKforPerllibraryincludesseveralsubroutinesthatsaveandreusesessions,soyoucan
maintainsessionsacrossscripts.Usingsessionscanenhancesecurity:Insteadofstoringpasswordsinscripts,
youcanruntheVim::login()subroutineinyourscriptusingthenameofthesessionfile.Thesessionfile
doesnotexposepasswordinformation.
Saving Sessions
Youcansaveasessionusingthesubroutinecallsyntaxasfollows:
Vim::save_session():
...
# usual login procedure with connect()
Util::connect();
...
# save the global session in file .mysession
Vim::save_session(session_file => '.mysession');
Alternatively,youcanusesave_session()withtheobjectorientedsyntax(see“UsingMultipleSessions”on
page 37):
...
# object-oriented login
my $service_url = "https://$server/sdk/vimService";
my $vim = Vim->new(service_url => $service_url);
$vim->login(user_name => $username, password => $password); ...
# save session $vim in file .mysession
$vim->save_session(session_file => '.mysession');
Thesessionremainsactiveuntiltheprogramrunsalogoutordisconnectoperation,oruntiltheprogramtimes
out.Timeoutis30minutesafterthelastoperationwasperformed.
Loading Sessions
Youcanuseload_session()toloadasavedsessionintotheglobalsessionasfollows: