Currently, we are studying how to use the pythob-libvirt API to operate VMS. After several twists and turns, the migration function is completed:
The Code is as follows:
Import libvirt # virsh migrate -- live KK qemu + TCP: // 192.168.4.87/system TCP: // 192.168.4.87 # conn = libvirt. open ('qemu: // system') # dest_conn = libvirt. open ('qemu + TCP: // 192.168.4.87/system') vm_domain = Conn. lookupbyname ('kk ') print vm_domain.migrate (dest_conn, 1, 'k2k', none, 0) # parameter description: the first is the conn of the target, and the migration method is live ), the name of the target VM. The destination URI can be empty, and the bandwidth can be set to 0.
In this case, the code is certainly not successful. libvirt. libvirterror: unable to resolve address 'xx 'service' 49170 ': No address associated with hostname
To configure the/etc/hosts file of the source host, add "192.168.4.87 xx" to map the IP address and host name of the target host.
During the migration process, the libmongod process running on the target host should create a URI Based on the address and port. The URI is the libmongod process used by the target host to receive data and send back data to the source host. The above helps the libmongod method to resolve the host name to the IP address.
The principle of using the virsh command for migration is the same, but to save the trouble of configuring the/etc/hosts file, you can use:
migrate --live kk qemu+tcp://192.168.4.87/system tcp://192.168.4.87
If the URI is set:
dest_conn=libvirt.open('qemu+tcp://192.168.4.87/system tcp://192.168.4.87‘)
If an error occurs, you do not need to configure the/etc/hosts file to avoid configuring the/etc/hosts file.
If the/etc/hosts file is always changed, the data synchronization is poor and it is troublesome. How can I not configure the hosts file ??
The method of configuring the/etc/hosts file is successfully tested. The Code is as follows:
print vm_domain.migrate(dest_conn,1,'k2k','tcp://192.168.4.87',0)
Parameters compare the corresponding functions of the first code.