VM Portability – OVFTool

VM Portability has become of even more importance after the evolution of virtualization in cloud computing.  It doesn’t only include pushing around virtual images but also various configurations of application, data, identity, security, or networking.  Even if all the components were themselves virtualized, simply porting the virtual instances from one location to another is not enough to assure interoperability.  This is because the components must be able to collaborate and this requires connectivity and other configuration information.

One of the solutions to this includes the VMWARE’s OVF/OVA formats. OVF is claimed to enable efficient, flexible, and secure distribution of enterprise software, facilitating the mobility of virtual machines and platform independence (Xen, KVM, Microsoft, and VMware etc).

What follows is an attempt to use it for VMWARE. Generation of OVF/OVA from a virtual machine using vShpere client turned out to be a simple process, which included selecting the VM in vSphere and clicking “Export to OVF” from main menu.

However, this is a manual process, and doesn’t help if we need to do it repeatedly for different builds of software or a large number of VMs.  To automate this process, we need some kind of CLIs to be able to call them in a script. VMWARE’s OVFtool provides us with that capability (and much more, which we will discuss in future posts).  So I tried to automate this through shell and perl scripts.  Both the scripts install a new RPM to a CentOS VM and then export it to OVF format.

SHELL Version:
# Description: To install an RPM to the CentOS VM (ip=$1) & Export it
# to OVF format
if test $# -ne 3
echo “Usage – $0 vmIP rpmPath esxIP”
fileName = $(basename “$2”)
if ssh $1 “scp$2 .;rpm -Uvh $fileName;exit;”
ovftool “vi://root@$3/CentOS” “/home/CentOS.ovf”
echo “Unable to connect to $1”

PERL Version:
#!/usr/bin/perl -w

use Net::OpenSSH;

if ($#ARGV != 2 ) {
print “usage: perl installRPM_ExportVM2OVF.pl vmIP rpmPath esxIPn”;

my $sshCentOSVM = Net::OpenSSH->new($vmIP, user => ‘root’, password => ‘PASSWORD’);

$sshCentOSVM->error and die “Unable to connect to remote host: ” . $sshCentOSVM->error;

my @values = split(‘/’, $rpmPath);
my $fileName = $values[$#values];

$sshCentOSVM->system(“scp$rpmPath .;rpm -Uvh $fileName;”);

system(“ovftool vi://root@” . $esxIP . “/CentOS /home/CentOS.ovf”)

Upcoming posts will include the usage for other hypervisor platforms.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s