#!/bin/sh
# Declare all VMs to import
XENDOMAINS=("rhelxen" "rhel2")
KVMDOMAINS=("rhelkvm")
VMWAREVMS=("rhel54vmware")
# Iterate through each Xen domain, performing the conversion
for domain in ${XENDOMAINS[@]}
do
virt-v2v -ic xen:///localhost -o rhev -os storage.example.com:/exportdomain --network rhevm $domain
done
# Iterate through each KVM domain, performing the conversion
for domain in ${KVMDOMAINS[@]}
do
virt-v2v -o rhev -os storage.example.com:/exportdomain --network rhevm $domain
done
# Iterate through each VMware VM, performing the conversion
for vm in ${VMWAREVMS[@]}
do
virt-v2v -ic esx://esx.example.com/?no_verify=1 -o rhev -os storage.example.com:/exportdomain --network rhevm $vm
done
# Call the import VM procedure remotely on the RHEV Manager
# Set API variables
export BASE_URL='http://rhevm.example.com'
export HTTP_USER='rhevadmin@domain.example.com'
export HTTP_PASSWORD='password123'
# Get the storage domains
wget --auth-no-challenge --http-user=${HTTP_USER} --http-password=${HTTP_PASSWORD} --header="Accept: application/xml" ${BASE_URL}/rhevm-api/storagedomains?search=name%3Dexport2 -O exportdomain
EXPORT_DOMAIN=`xpath exportdomain '/storage_domains/storage_domain/@id' | sed -e 's/ id=//' | sed -e 's/"//g'`
# Get the datacenter
wget --auth-no-challenge --http-user=${HTTP_USER} --http-password=${HTTP_PASSWORD} --header="Accept: application/xml" ${BASE_URL}/rhevm-api/datacenters?search=name%3D23compat -O dc
DC=`xpath dc '/data_centers/data_center/@id' | sed -e 's/ id=//' | sed -e 's/"//g'`
# Get the cluster
wget --auth-no-challenge --http-user=${HTTP_USER} --http-password=${HTTP_PASSWORD} --header="Accept: application/xml" ${BASE_URL}/rhevm-api/clusters?search=name%3DDefault -O cluster
CLUSTER_ELEMENT=`grep "cluster id" cluster`
echo ${CLUSTER_ELEMENT}
# List contents of export storage domain
wget --auth-no-challenge --http-user=${HTTP_USER} --http-password=${HTTP_PASSWORD} --header="Accept: application/xml" ${BASE_URL}/rhevm-api/datacenters/${DC}/storagedomains/${EXPORT_DOMAIN}/vms -O vms
# For each vm, export
VMS=`xpath vms '/vms/vm/actions/link[@rel="import"]/@href' | sed -e 's/ href="//' | sed -e 's/"//'`
echo '<action><cluster><name>23compat</name></cluster><storage_domain><name>data2</name></storage_domain></action>' > importaction
wget --auth-no-challenge --http-user=${HTTP_USER} --http-password=${HTTP_PASSWORD} --header="Accept: application/xml" --header="Content-Type: application/xml" --post-file=importaction ${BASE_URL}$VMS