Pages

Monday, November 5, 2012

Installing the vSphere SDK for Perl on OS X

Since the first Intel based Macbook Pro was introduced, Apple OS X has been my preferred platform for work and play.  While VMware Fusion makes it particularly easy to run VMware toolkits and utilities, I still prefer native versions.  I started working with the VMware vSphere SDK for Perl years ago, developing against and natively running the SDK tools on my various Mac systems ever since.

Installing the VMware vSphere SDK for Perl is actually a straightforward process.  The installation steps outlined here were tested using the vSphere SDK for Perl 5.1 and OS X Mountain Lion, but the process should work just as well on older versions of both the SDK and OS X.

Warning:  Installing the vSphere SDK for Perl on OS X is unsupported by VMware.  I have not encountered any issues particular to running the Perl SDK on OS X over the years, but there may be unexpected conflicts.

Note:  Installation of the vSphere SDK for Perl will require CPAN.  If you haven't configured CPAN on your system, be sure to review my earlier blog post.

First, download the vSphere SDK for Perl 5.1 64-bit Linux installer.  At the time of this post, the current installer package was VMware-vSphere-Perl-SDK-5.1.0-780721.x86_64.tar.gz.

cd ~/Downloads
tar zxvf VMware-vSphere-Perl-SDK-5.1.0-780721.x86_64.tar.gz
cd vmware-vsphere-cli-distrib/

Then install the required vSphere SDK Perl modules through CPAN selecting default answers at any CPAN prompts.

sudo perl -MCPAN -e shell
cpan[1]> install Class::MethodMaker Crypt::SSLeay SOAP::Lite UUID Data::Dump
cpan[2]> exit

The vSphere Perl SDK requires UUID-0.03.  However, version 0.03 is marked as an unauthorized release.  I've run UUID-0.02 without issues, so as a fix we'll modify the vSphere Perl SDK Makefile.PL to use the current version of UUID hosted on CPAN.

sudo sed -i '.bak' -e "s/'UUID' => '0.03'/'UUID' => '0.02'/" Makefile.PL

On a supported operating system, the vmware-install.pl installer script would do all the work.  On OS X, however, the vmware-install.pl script will check and fail since it was called on an incompatible operating system.  We'll need to execute some of the installation steps manually to complete the vSphere SDK for Perl installation.

sudo perl Makefile.PL
sudo make install
# Copy esxcfg- and vicfg- commands to /usr/local/bin
sudo cp -rv ./bin/ /usr/local/bin/

The Perl Makefile.PL install placed the vSphere Perl SDK core modules into the standard Perl library path /Library/Perl/5.12/VMware.  The utility applications were installed under /usr/lib/vmware-viperl/apps.  The vSphere Perl SDK and WS-Management sample scripts were installed under /usr/share/doc/vmware-viperl/doc/samples.

Before testing the vSphere SDK for Perl utilities or running any custom scripts, you'll need to instruct LWP to ignore hostname validation of self-signed certificates.  Otherwise, you may get the cryptic message: Server version unavailable at 'https://172.16.254.50:443/sdk/vimService.wsdl' at /Library/Perl/5.12/VMware/VICommon.pm line 545, <STDIN> line 1.

In newer versions of the Crypt::SSLeay module, stricter validation of SSL certificates is performed.  The issue has been discussed on the VMTN communities forums.

Note:  You should understand the full impact of globally disabling hostname verification in a production environment.  Blindly disabling SSL verification can increase the possibility of a man-in-the-middle attack.

The ESX CLI commands were copied into the default PATH location /usr/local/bin and can be invoked without a path prefix:
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
vicfg-vmknic --server=172.16.254.50 --username=administrator@vlab --vihost=192.168.100.11 --list
Verify ESX CLI Commands

The vSphere Perl SDK utility applications were installed into the /usr/lib/vmware-viperl/apps directory:
cd /usr/lib/vmware-viperl/apps/
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
general/viversion.pl --username=administrator@vlab --server=172.16.254.50
host/hostinfo.pl --username=administrator@vlab --server=172.16.254.50 --hostname=192.168.100.11
Validate vSphere Perl SDK Utilities

Finally, if you're interested in running the Web Services for Management (WS-Management) sample scripts or developing your own, the samples were installed into the /usr/share/doc/vmware-viperl/doc/samples directory:
cd /usr/share/doc/vmware-viperl/doc/samples
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
WSMan/firmwarerevisions.pl --server=192.168.100.11 --username=root
Validate vSphere Perl SDK WSMan

Note:  If you get the error Incorrect parameter at /Library/Perl/5.12/SOAP/Lite.pm line 1993, <STDIN> line 1 when running the WS-Management sample scripts, it's most likely related to a known issue with the SOAP::Lite module.  As a quick workaround, you can modify line 1993 using the following sed command:
sudo sed -i '.bak' -e '1993s/\^\\d\$/\^\\d+\$/' /Library/Perl/5.12/SOAP/Lite.pm

The original version of the Lite.pm module will be copied to /Library/Perl/5.12/SOAP/Lite.pm.bak if you ever need to restore it.

The SOAP::Lite and Crypt::SSLeay issues aren't specific to OS X and will most likely be seen on supported Linux and Windows operating systems with those specific CPAN Perl module versions installed.

That's it!  You now have a working, unsupported vSphere SDK for Perl installation on your OS X system.

7 comments:

  1. This post is very helpful for me when I try to install WebService::Validator::CSS::W3C.
    Thank you for your great help!

    ReplyDelete
  2. Wow! Thanks so much for the detailed and _accurate_ guide. You must have saved me at least 8 hours of frustration.

    ReplyDelete
  3. Also requires XML::LibXML.

    ReplyDelete
  4. Replies
    1. I never had any issues, usually XML::LibXML is already installed. What version of OSX are you using? Is it the default Perl install or a custom one?

      Thanks!

      Delete
  5. Thanks very much. I really need it.

    ReplyDelete
  6. Trying to use it on iMac running Yosemite. I get the following SOAP request error for any command I attempt. Any thoughts or ideas will be most appreciated.

    SOAP request error - possibly a protocol issue:


    ha-hostnameesxi3.mydomain.comruntime.bootTime2016-06-07T00:22:09.633594Zruntime.connectionStateconnectedruntime.inMaintenanceModefalsesummary.config.vmotionEnabled</

    ReplyDelete