Vmware ESX(i) is an incredible dynamic IT infrastructure, you can do wonderful things with this product, the only problem is: the license. Why the license? Well, let’s put it simple, the expensive the license, the more things you can do, so the free license barely allows you to do almost nothing.

For automation purposes, the free license does not provides API access, so you don’t have the best way to perform tasks like:

  1. Shutdown
  2. Power on
  3. Revert
  4. Reset and so on.

Now, is there a way to overcome this limitation? Yes, there is a way, but you need know something… this is kinda insecure, but if you are a good engineer then you shouldn’t have any problems.

Requirements

  1. You need a Jenkins server (properly configured with user authentication and disallow anonymous usage)
  2. An ESX(i) server, make sure you have root access to it via ssh (you probably need to enable it)
  3. An Ubuntu machine, this one will be a jenkins slave, make sure it’s connected properly with jenkins

1 . Create some virtual machines

On your ESX(i) server, create a virtual machine, with a nice name. Install whatever OS you need and the software that you need to start testing. Finally create two snapshots, one after the one, I will explain this later.

2. Install a SSH Key from your Jenkins Slave into the ESX(i) server

This could be kinda tricky, but this is how we can overcome the absence of the API, we are going to manually use vim-cmd in order to achieve our objective.

Once we have the key installed, we can ssh into the ESX(i) server without using the password. NOTE: You will make the ESX(i) server vulnerable because of the root user, so PROTECT the jenkins slave at all costs, make sure no one can access the slave freely.

3. Create bash script

Before we need to valuable information, the ID of the virtual machine and the ID of the snapshot, we can get this via vim-cmd on your ESX(i) via ssh as follows:

You will get a response like this:

Our VM ID is 96, now we need the ID of the snapshot in order to revert it:

You will get the following information:

Notice that we have two snapshots, a parent and a child snapshot and here is the magic trick: Use the ID of the child snapshot, the reason? Because ESX(i) will keep the VM powered on no matter what, if you use the parent ID it will be automatically turned off after reverting the virtual machine.

With this information let’s create the script and place it on your jenkins slave workspace:

 Configure your Jenkins Job

Add a new “Execute Shell” build step and run your bash script from there, then add additional steps to finish the job according to your scenario, in my case I do perform a revert on 3 different virtual machines and execute an automated test suite with java over a customer’s product that I install using the same bash script.

Example of where to run the bash script

As you can see, we can overcome the “free license” limitation of ESX(i) by placing a SSH key on it and run vim-cmd commands directly, but beware, if the ESX(i) is restarted by some reason, the key will be deleted and you have to place it again.

 

Follow me

Carlos Alberto Umanzor Arguedas

Web Developer at carlosumanzor.com
Web Developer, QA Engineer and Gamer Enthusiast, Developer of Linkcrawler and Father of a future computer ninja.
Follow me

Pin It on Pinterest

Shares
Share This
Optimization WordPress Plugins & Solutions by W3 EDGE