Use Python-libvirt API for Migration

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.