Creating WFA VMWare Perl Commands using VMWare vSphere SDK for Perl

by Extraordinary Contributor on ‎2014-10-01 10:26 AM

Hello Everyone,

WFA Developer's Guide and certified commands for VMware vCenter are totally in Powershell and use VMWare Power CLI. WFA also support Perl as a language for creating commands. So for the Perl users, the following document describes how to create WFA VMware commands in perl using VMWare vSphere SDK for Perl.

  1. Download and Install.  


Download the latest SDK from the vmware website. The following link is for vSphere 5.5

https://developercenter.vmware.com/web/sdk/55/vsphere-perl

You would need a user account and accept EULA.

 

2.  Configure WFA for using VMWare SDK perl libs.

 

  • Define PERL5LIB.

VMWare vSphere SDK has perl version 5.8.8 bundled with it and its supported libs. WFA provides perl version 5.16.3 which will be incompatible to use with the vSphere perl libs. So you need to configure WFA to use the perl 5.8.8 provided with the Vmware SDK.


Add a new system variable called PERL5LIB and its value for all default installation of vSphere SDK and WFA would be:


C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\site\lib;C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\lib;C:\Program Files\NetApp\WFA\Perl64\lib

If you have custom installation path then this value should be the path to VMware\VMware vSphere CLI\Perl\site\lib and VMware\VMware vSphere CLI\Perl\lib and WFA\Perl64\lib

  • Configure WFA to use vSphere's Perl5.8.8 perl.exe


Read the WFA installation and setup Guide for detailed step on how to do this. The next WFA release will simply this process and eliminate manual need to edit configuration files.

 

The default path would be "C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin\perl.exe". Modify it accordingly if you have custom installation path. Restart the WFA services when prompted for.

 

Your WFA is ready!!

 


3. Coding the command.

Most vSphere sample codes with have structure to define Script-Specific Command-Line Options and the connect using Util::Connect(). WFA can't use this because this WFA commands always run in non-interactive mode. So we need Object Oriented connection to server. See below how to do this.

 


4. Sample code:

The below is a working sample code to list all Datacenter in a given vCenter. You need to save vCenter's credentials as required by any WFA command. Command creation is same as creating any other WFA Perl command.

 

#### begin code #####

use strict;
use WFAUtil;
use Getopt::Long;

#VMware Connection libs
use VMware::VIRuntime;
use VMware::VILib;

my $vcname;
GetOptions ("vcname=s" => \$vcname, ) or die 'Illegal command parameters';
my $wfaUtil = WFAUtil->new();

#Get VC credentials
my @vcCredentials = $wfaUtil->getCredentials($vcname);
my $service_url = "https://".$vcname."/sdk/vimService";
my $vim = Vim->new(service_url => $service_url);
$vim->login(user_name => $vcCredentials[0], password => $vcCredentials[1]);

my $host = $vim->find_entity_views(view_type => 'Datacenter');

foreach my $h(@$host)
{
my $message = $h->name;
$wfaUtil->sendLog("info", $message);
}
# Disconnect from the server
Util::disconnect();

#### end code ####


warm regards,
Abhishek Sinha
WFA

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.