vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> <strong>Programming</strong> <strong>Guide</strong><br />
Using Filters on the Utility Application Command Line<br />
When you run a utility application that takes arguments specifying names <strong>for</strong> virtual machines, host systems,<br />
and so on, you must supply the exact name on the command line. Regular expressions are not accepted.<br />
When you run a utility application, there are some restrictions on special characters:<br />
In virtual machine names, you must represent the character <strong>for</strong>ward slash (/) as %2f, backward slash (\)<br />
as %5c, and percent (%) as %25 when they appear in virtual machine names.<br />
On UNIX‐like command lines, surround names that contain special characters with single‐quotes, and use<br />
percent (%) as the escape character.<br />
For example, to search <strong>for</strong> the virtual machine San Jose, run this command:<br />
perl vminfo.pl --username Administrator --password 'secret' --server myserver --vmname 'San Jose'<br />
To search <strong>for</strong> the virtual machine San-Jose/5, run this command:<br />
perl vminfo.pl --username Administrator --password 'secret' --server myserver --vmname<br />
'San-Jose%2f5'<br />
Retrieving the ServiceInstance Object on a <strong>vSphere</strong> Host<br />
You can retrieve the ServiceInstance object to access the ServiceContent or to retrieve the current time on<br />
an ESX/ESXi or vCenter Server system.<br />
If you want to retrieve the current time, you must retrieve a ServiceInstance object and call its<br />
CurrentTime() method. You can use the Vim::get_service_instance() subroutine to retrieve the object.<br />
To retrieve the current <strong>VMware</strong> host time<br />
1 Connect to the <strong>VMware</strong> host:<br />
Util::connect();<br />
2 Retrieve the ServiceInstance object:<br />
my $service_instance = Vim::get_service_instance();<br />
3 Retrieve the current host time:<br />
$service_instance->CurrentTime();<br />
Saving and Using Sessions<br />
The <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> library includes several subroutines that save and reuse sessions, so you can<br />
maintain sessions across scripts. Using sessions can enhance security: Instead of storing passwords in scripts,<br />
you can run the Vim::login() subroutine in your script using the name of the session file. The session file<br />
does not expose password in<strong>for</strong>mation.<br />
Saving Sessions<br />
You can save a session using the subroutine call syntax as follows:<br />
Vim::save_session():<br />
...<br />
# usual login procedure with connect()<br />
Util::connect();<br />
...<br />
# save the global session in file .mysession<br />
Vim::save_session(session_file => '.mysession');<br />
36 <strong>VMware</strong>, Inc.