Product SiteDocumentation Site

3.3.5. Scripted Bulk v2v Process

For bulk import scenarios, it is advantageous to be able to perform the scripted v2v process from a single host. Remote procedure calls to the Red Hat Enterprise Virtualization Manager can be made using the REST API. This enables a single script running on a single Linux host to perform both steps of the v2v process. Figure 3.7, “Scripted bulk v2v process” illustrates the steps performed by the script.
Scripted bulk v2v process
Figure 3.7. Scripted bulk v2v process

The scripted bulk v2v process involves the following steps, as shown in Figure 3.7, “Scripted bulk v2v process”:
  1. The virtual machine image is retrieved from the source hypervisor.
  2. The virtual machine image is packaged and copied to the export storage domain.
  3. A remote procedure call is made to the Red Hat Enterprise Virtualization Manager, telling it to import the virtual machine.
  4. The Manager imports the virtual machine from the import storage domain.
To configure and run the scripted bulk v2v process:
  1. Ensure the REST API is enabled on the Red Hat Enterprise Virtualization Manager, and it is accessible from the Linux host running the v2v process. For more information about the REST API, see the Red Hat Enterprise Virtualization REST API Guide.
  2. On the Linux host, create the file v2v.sh with the following contents. Ensure you edit the script to contain appropriate values for your environment.
    Example 3.5. Single host v2v script
    #!/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
    

  3. Run the v2v.sh script. It can take several hours to convert and import a large number of virtual machines.