使用一个到 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 Developer Guide。
在 Linux 主机上,创建包括以下内容的 v2v.sh 文件。请确认您根据您的具体环境对脚本中的相应内容进行了修改。
例 4.5. 单独主机的 v2v 脚本
Declare all VMs to import
Iterate through each Xen domain, performing the conversion
Iterate through each KVM domain, performing the conversion
Iterate through each VMware VM, performing the conversion
Call the import VM procedure remotely on the RHEV Manager
Get the export storage domains
Get the datacenter
Get the cluster
List contents of export storage domain
For each vm, export
#!/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 Developer Guide。