4.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 4.5, “Scripted bulk v2v process” illustrates the steps performed by the script.
Scripted bulk v2v process

Figure 4.5. Scripted bulk v2v process

The scripted bulk v2v process involves the following steps, as shown in Figure 4.5, “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 export storage domain.
To configure and run the scripted bulk v2v process:

Procedure 4.9. Configuring and running 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 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 4.5. Single host v2v script

    #!/bin/sh
    # Declare all VMs to import
    XENDOMAINS=("rhelxen" "rhel5")
    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
    
    export BASE_URL='https://[rhevm-host]'
    export HTTP_USER='user@internal'
    export HTTP_PASSWORD='password'
    
    curl -o rhevm.cer http://[rhevm-host]/ca.crt
    
    # Get the export storage domains
    
    curl -X GET -H "Accept: application/xml" -u "${HTTP_USER}:${HTTP_PASSWORD}" --cacert rhevm.cer ${BASE_URL}/api/storagedomains?search=nfs_export -o exportdomain
    EXPORT_DOMAIN=`xpath exportdomain '/storage_domains/storage_domain/@id' | sed -e 's/ id=//' | sed -e 's/"//g'`
    
    # Get the datacenter
    
    curl -X GET -H "Accept: application/xml" -u "${HTTP_USER}:${HTTP_PASSWORD}" --cacert rhevm.cer ${BASE_URL}/api/datacenters?search=NFS -o dc
    DC=`xpath dc '/data_centers/data_center/@id' | sed -e 's/ id=//' | sed -e 's/"//g'`
    
    # Get the cluster
    
    curl -X GET -H "Accept: application/xml" -u "${HTTP_USER}:${HTTP_PASSWORD}" --cacert rhevm.cer ${BASE_URL}/api/clusters?search=NFS -o cluster
    CLUSTER_ELEMENT=`xpath cluster '/clusters/cluster/@id' | sed -e 's/ id=//' | sed -e 's/"//g'`
    
    # List contents of export storage domain
    
    curl -X GET -H "Accept: application/xml" -u "${HTTP_USER}:${HTTP_PASSWORD}" --cacert rhevm.cer ${BASE_URL}/api/storagedomains/${EXPORT_DOMAIN}/vms -o vms
    
    # For each vm, export
    VMS=`xpath vms '/vms/vm/actions/link[@rel="import"]/@href' | sed -e 's/ href="//g' | sed -e 's/"/ /g'`
    
    for vms in $VMS
    do
            curl -v -u "${HTTP_USER}:${HTTP_PASSWORD}" -H "Content-type: application/xml" -d '<action><cluster><name>cluster_name</name></cluster><storage_domain><name>data_domain</name></storage_domain><overwrite>true</overwrite><discard_snapshots>true</discard_snapshots></action>' --cacert rhevm.cer ${BASE_URL}$vms
    done
    
    

    Note

    Use the POST method to export virtual machines with the REST API. For more information about using the REST API, see the Red Hat Enterprise Virtualization REST API Guide.
  3. Run the v2v.sh script. It can take several hours to convert and import a large number of virtual machines.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.