6.5

Table Of Contents
vSphere SDK for Perl Programming Guide
14 VMware, Inc.
2Runsave_session.pl.Youmustsupplyconnectionparametersandthenameofasessionfileinwhich
thescriptcansaveanauthenticationcookie.
perl save_session.pl --savesessionfile <location> --server <esxi_host>
Forexample:
perl save_session.pl --savesessionfile C:\Temp\my_session --server my_server
Ifyouspecifyaserverbutnousernameorpassword,thescriptpromptsyou.
3Youcannowrunscriptsinthe\appsor\samplesdirectoryoryourownscriptsandpassinthesession
fileusingthe--sessionfileparameterasfollows:
<command> --sessionfile <sessionfile_location> <command_options>
Forexample:
perl hostinfo.pl --sessionfile C:\Temp\my_session
Youcanusethecodeinthe\apps\session\save_session.plutilityapplicationinsideyourownvSphere
SDKforPerlapplication.Ifacalltotheserverthrowsanexception,yourapplicationshouldterminatethe
sessiontoavoidsessionleaks.Youcoulddothiswithanerrorhandlerthatrunsdisconnect()orlogout(),
forexample:
eval {
# ... insert program here ...
};
if ($@) {
print "Fatal error: $@";
Util::disconnect();
exit(1);
}
Youcanalsousethe_END_pseudosignalhandlertoperformadisconnect,asfollows:
$SIG{__END__} = sub { Util::disconnect(); }
Passing Parameters at the Command Line
Passparametersatthecommandlineusingoptionnameandoptionvaluepairs(someoptionshavenovalue).
--<optionname> <optionvalue>
Thefollowingexampleconnectstotheserverasusersnow-whitewithpassworddwarf$.Thefirstexample
(Linux)usesanescapecharacterbeforeeachspecialcharacter,theotherexamplesusesinglequotes(Linux)
anddoublequotes(Windows).
Linux
vminfo.pl --server <server> --username snow\-white --password dwarf\$ --vmname <name>
vminfo.pl --server <server> --username ‘snow-white’ --password ‘dwarf$’ --vmname <name>
Windows
vminfo.pl --server <server> --username “snow-white” --password “dwarf$” --vmname <name>
Setting Environment Variables
YoucansetenvironmentvariablesinaLinuxprofile,intheEnvironmentpropertiesdialogboxofthe
MicrosoftWindowsSystemcontrolpanel,or,forthecurrentsession,atthecommandline.Environment
variablesarelistedwhenyourunacommandwith--help.
Thefollowingexampleshowsthecontentsofa
/root/.visdkrc filethatusesenvironmentvariables:
VI_SERVER = <server>
VI_USERNAME = <usr>
VI_PASSWORD = <root_password>
NOTEIfyouuseasessionfile,anyotherconnectionparametersareignored.