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:
#!/bin/sh
#
# Description: To install an RPM to the CentOS VM (ip=$1) & Export it
# to OVF format
#
if test $# -ne 3
then
echo “Usage – $0 vmIP rpmPath esxIP”
else
fileName = $(basename “$2”)
if ssh $1 “scp 192.168.112.132:$2 .;rpm -Uvh $fileName;exit;”
then
ovftool “vi://root@$3/CentOS” “/home/CentOS.ovf”
else
echo “Unable to connect to $1”
fi
fi
PERL Version:
#!/usr/bin/perl -w
use Net::OpenSSH;
if ($#ARGV != 2 ) {
print “usage: perl installRPM_ExportVM2OVF.pl vmIP rpmPath esxIPn”;
exit;
}
$vmIP=$ARGV[0];
$rpmPath=$ARGV[1];
$esxIP=$ARGV[2];
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 192.168.112.132:$rpmPath .;rpm -Uvh $fileName;”);
system(“ovftool vi://root@” . $esxIP . “/CentOS /home/CentOS.ovf”)
Upcoming posts will include the usage for other hypervisor platforms.