Summary
ElectricCommander is tightly integrated with VMware Lab Manager, which allows ElectricCommander to easily provision and destroy virtual machines during the build process. The current integration with VMware requires you to use Lab Manager. If you are not using Lab Manager, this article describes a similar solution that works directly with ESX (VI3) servers, including the tools you need and the techniques to directly manipulate the ESX server. The solution for provisioning ESX servers is similar to Lab Manager, but slightly less functional.
What you can do
Using the VMware Infrastructure Perl Toolkit allows you manipulate the ESX server, storage, resource pools, and VMs. You can do just about anything you want to do to the ESX server. To download this toolkit, a link is provided at the end of this article.
What Lab Manager does better
Lab Manager provides functionality on top of ESX, so naturally, you will not have these functions if you communicate directly with the ESX server. In particular, Lab Manager allows:
-
Libraries of configurations
-
Very efficient storage of VMs
-
Network fencing around the VMS (allows mulitple copies of the same VM to run at the same time without network naming collisions [IP address, MAC, etc…] )
Solution
VMware provides a Perl toolkit to communicate with ESX servers. This Perl toolkit also contains some pre-built utilities to simplify interaction with the ESX server…. essentially providing a command-line interface.
-
Download the toolkit for the intended platform from VMware.
-
Install the toolkit on the ElectricCommander agent that will run the commands (this could be the ElectricCommander server).
-
Create ElectricCommander steps that call the utilities.
Example
Here is an example script that runs in an ElectricCommander step. It logs on, queries the ESX server, starts a VM, and then shuts down the VM.
REM *** setup paths and environment variables set APIHOME=c:\Program Files\VMware\VMware VI Perl Toolkit set PERLB=%APIHOME%\Perl\bin\perl.exe set APIHOST=vsupport2 set PATH=%APIHOME%\perl\apps;%PATH%;%APIHOME%\perl\bin;%APIHOME%\perl\site\bin REM *** change to the VMWare Perl Toolkit directory c: cd "%APIHOME%\perl\apps" REM *** HACK to fix vmware chcp call errors...avoids call to c:\windows\system32\chcp echo @echo off > chcp.cmd echo echo Active code page: 437 >> chcp.cmd REM *** logon to ESX server and save credentials in session file del c:\session_file.txt session\save_session.pl --username apidemo --password apidemo --server vsupport2 --savesessionfile c:\session_file.txt REM *** show VM;s on this ESX server (just for fun) general\vidiscovery.pl --server vsupport2 --sessionfile c:\session_file.txt --managedentity host --entityname vsupport2.electric-cloud.com REM *** start a VM vm\vmcontrol.pl --server vsupport2 --sessionfile c:\session_file.txt --operation poweron --vmname api REM *** sleep 5 minutes sleep 60 REM *** stop the VM vm\vmcontrol.pl --server vsupport2 --sessionfile c:\session_file.txt --operation poweroff --vmname api
Notes
We found the VMWare utilities produced a strange error when running in ElectricCommander on Windows. It calls the Windows utility "chcp" to find the code page, but apparently returns empty results. Running the utility outside ElectricCommander works fine. For now, suppress the error by making a fake copy of "chcp" that gives back a value. This may have been a configuration problem on our test machine, but we included the workaround in case you have the same problem.