vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> <strong>Programming</strong> <strong>Guide</strong><br />
You can use the code in the \apps\session\save_session.pl utility application inside your own <strong>vSphere</strong><br />
<strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> application. If a call to the server throws an exception, your application should terminate the<br />
session to avoid session leaks. You could do this with an error handler that runs disconnect() or logout(),<br />
<strong>for</strong> example:<br />
eval {<br />
# ... insert program here ...<br />
};<br />
if (@$) {<br />
print "Fatal error: $@";<br />
Util::disconnect();<br />
exit(1);<br />
}<br />
You can also use the _END_ pseudo‐signal handler to per<strong>for</strong>m a disconnect, as follows:<br />
$SIG{__END__} = sub { Util::disconnect(); }<br />
Passing Parameters at the Command Line<br />
Pass parameters at the command line using option name and option value pairs (some options have no value).<br />
-- <br />
The following example connects to the server as user snow-white with password dwarf$. The first example<br />
(Linux) uses an escape character be<strong>for</strong>e each special character, the other examples use single quotes (Linux)<br />
and double quotes (Windows).<br />
Linux<br />
vminfo.pl --server --username snow\-white --password dwarf\$ --vmname <br />
vminfo.pl --server --username ‘snow-white’ --password ‘dwarf$’ --vmname <br />
Windows<br />
vminfo.pl --server --username “snow-white” --password “dwarf$” --vmname <br />
Setting Environment Variables<br />
You can set environment variables in a Linux profile, in the Environment properties dialog box of the<br />
Microsoft Windows System control panel, or, <strong>for</strong> the current session, at the command line. Environment<br />
variables are listed when you run a command with --help.<br />
The following example shows the contents of a /root/.visdkrc file that uses environment variables:<br />
VI_SERVER = <br />
VI_USERNAME = <br />
VI_PASSWORD = <br />
VI_PROTOCOL = https<br />
VI_PORTNUMBER = 443<br />
Do not escape special characters in the file that specifies environment variables.<br />
If you have set up your system to run this file, you can run scripts on the specified server afterwards.<br />
Using a Configuration File<br />
A configuration file is a text file that contains variable names and settings. Variables corresponding to the<br />
connection options are shown in Table 1‐3. Use --config if the configuration in<strong>for</strong>mation is saved in a<br />
different file than ./visdkrc. If you specify --config, the system ignores the ./visdkrc settings.<br />
CAUTION Limit read access to a configuration file, especially if it contains user credentials.<br />
You can use the --config option to run a script with the configuration file, <strong>for</strong> example:<br />
connect.pl --config --list<br />
14 <strong>VMware</strong>, Inc.