libvirt api 虚拟机动态迁移代码示例(非共享存储)

libvirt api 实现动态迁移(非共享存储)

环境centos7

1.添加 源 /etc/yum.repos.d/qemu-kvm-rhev.repo 

[qemu-kvm-rhev]
name=oVirt rebuilds of qemu-kvm-rhev
baseurl=http://resources.ovirt.org/pub/ovirt-3.5/rpm/el7Server/
#mirrorlist=http://resources.ovirt.org/pub/yum-repo/mirrorlist-ovirt-3.5-el7Server
enabled=1
skip_if_unavailable=1
gpgcheck=0

2.安装qemu-kvm-rhev

yum install   qemu-kvm-rhev

3.重启服务

service libvirtd restart

4.hosts中需要添加 ip 和hostname的对应关系

5.在dest节点 创建/pool/test.win7 镜像文件空的

6.在src节点 运行  python mig.py   代码如下:

from __future__ import print_function
import sys
import libvirt

domName = 'test'

conn = libvirt.open('qemu:///system')
if conn == None:
    print('Failed to open connection to qemu:///system', file=sys.stderr)
    exit(1)

dest_conn = libvirt.open('qemu+ssh://192.168.1.252/system')
if conn == None:
    print('Failed to open connection to qemu+ssh://192.168.1.252/system', file=sys.stderr)
    exit(1)

dom = conn.lookupByName(domName)
if dom == None:
    print('Failed to find the domain '+domName, file=sys.stderr)
    exit(1)

xml =  """

  test
  4076b74e-6a48-e121-b493-587aa562e8f0
  None
  1048576
  1048576
  2
  
    /machine
  
  
    hvm
    
    
    
  
  
    
    
    
  
  
    SandyBridge
    
  
  
    
    
    
    
  
  destroy
  restart
  restart
  
    /usr/libexec/qemu-kvm
    
      
      
      
        
        
        
      
      
      
      


你可能感兴趣的:(libvirt)