Using vSphere SDK for Perl
This section explains how to get started with vSphere SDK for Perl by looking at two typical usage scenarios. It also lists common vSphere SDK for Perl tasks and discusses programming conventions.
Getting Started
If you want to use the SDK to retrieve performance information for a host, you might perform the following tasks:
1
Check the vSphere SDK for Perl Utility Applications Reference or the apps directory for a script that retrieves performance information.
Check /usr/lib/vmware-vcli/apps on Linux and Program Files\VMware vSphere CLI\Perl\apps on Windows. All utility applications are fully supported.
The viperformance.pl script retrieves performance counters from the host.
Note If you cannot find a utility application, examine the sample scripts. You can use sample scripts as starting points for your application. On Linux, /usr/share/doc/vmware-vcli/samples, on Windows, Program Files\VMware\VMware vSphere CLI\Perl\samples. Sample scripts are not supported.
2
Run the script with the --help option or without any options to see its online documentation. More detailed information is in the Utility Applications Reference included in the vSphere SDK for Perl documentation set and available from the VMware Web site.
3
Run the viperformance.pl script against an ESXi host.
viperformance.pl --url https://<host>:<port>/sdk/vimService --username nemo --password fi\$h --host Aquarium --countertype net --interval 30 --samples 3
Escape characters must precede special characters in passwords. See Options Available for All SDK for Perl Commands for a complete list of connection parameters.
If you want to use the SDK for a task that none of the utility applications can perform, you might perform the following tasks:
1
Check the /samples folder for a sample script that performs a similar task. The scripts in the samples folder are available for customization.
2
The following materials are available for modifying or writing scripts:
3
Vim::<subroutine>(<parameter_name>=><value>, <parameter_name>=><value> );
Util::<subroutine>(<parameter_name>=><value>, <parameter_name>=><value> );
Opts::<subroutine>(<parameter_name>=><value>, <parameter_name>=><value> );
Common vSphere SDK for Perl Tasks
The vSphere SDK for Perl includes utility applications and sample scripts for common administration tasks.
viperformance.pl (retrieves performance counters from host)
vmsnapshot.pl, snapshotmanager.pl
Some tasks require additional scripting. See Writing vSphere SDK for Perl Scripts.
vSphere SDK for Perl Programming Conventions
Several programming conventions are different than you might expect because the SDK interacts with a server using SOAP/WSDL.
To match Boolean values in a filter, use the strings true and false. See Creating and Using Filters.
Date/Time – The server returns a SOAP dateTime value. You can use the Date::Parse Perl module to process these objects.
The vSphere SDK for Perl accepts only native SOAP dateTime values using standard date time format with or without fractional seconds, and with or without GMT (Z) time zone:
YYYY-MM-DDThh:mm:ssTZD, for example, 1997-07-16T19:20:30+01:00
YYYY-MM-DDThh:mm:ss.sTZD
, for example, 1997-07-16T19:20:30.45+01:00
The SDK always returns dateTime values in the standard date time format.