Red Hat Enterprise Virtualization Manager に対してリモートプロシージャコールを実行し、仮想マシンをインポートするように指示します。
Manager がエクスポートストレージドメインから仮想マシンをインポートします。
スクリプト化された v2v の一括処理の設定/実行は、以下の手順で行います。
手順4.9 スクリプト化された v2v 一括処理の設定と実行
Red Hat Enterprise Virtualization Manager で REST API が有効化されている状態で、かつ v2v プロセスを実行する Linux ホストからアクセス可能であることを確認します。REST API についての詳しい情報は 『Red Hat Enterprise Virtualization テクニカルガイド』を参照してください。
Linux ホストで、以下の内容を記述した v2v.sh ファイルを作成します。スクリプトを編集して、ご使用の環境に適した値を設定してください。
例4.5 単一ホストの v2v スクリプト
#!/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
#!/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
Copy to ClipboardCopied!Toggle word wrapToggle overflow
注記
POST メソッドを使用し、REST API で仮想マシンをエクスポートします。REST API の使用方法に関する詳しい説明は、『Red Hat Enterprise Virtualization テクニカルガイド』を参照してください。