Commit d0c0eacf authored by Antoine Millet's avatar Antoine Millet

Implemented disk selection in VM migrations

parent b9a6a071
......@@ -557,19 +557,39 @@ class VirtualMachine(object):
def migrate(self, dest_uri, live=False):
volumes = list(self.iter_disks()) # Store volumes for future cleanup
migration_params = {}
# Get the list of shared, non shared disks and shared pools:
shared = set()
shared_pools = set()
nonshared = set()
for volume in volumes:
if volume.storage.is_shared:
shared.add(volume.device)
shared_pools.add(volume.storage.name)
else:
nonshared.add(volume.device)
flags = (libvirt.VIR_MIGRATE_PEER2PEER
| libvirt.VIR_MIGRATE_PERSIST_DEST
| libvirt.VIR_MIGRATE_UNDEFINE_SOURCE)
if live:
flags |= (libvirt.VIR_MIGRATE_LIVE
| libvirt.VIR_MIGRATE_NON_SHARED_DISK
| libvirt.VIR_MIGRATE_AUTO_CONVERGE)
flags |= (libvirt.VIR_MIGRATE_LIVE | libvirt.VIR_MIGRATE_NON_SHARED_DISK)
migration_params[libvirt.VIR_MIGRATE_PARAM_MIGRATE_DISKS] = list(nonshared)
else:
flags |= libvirt.VIR_MIGRATE_OFFLINE
error = self.lv_dom.migrateToURI3(dest_uri, {}, flags)
dconn = libvirt.open(dest_uri)
# Refresh shared pools on the destination to avoid unknown volumes:
for pool_name in shared_pools:
pool = dconn.storagePoolLookupByName(pool_name)
pool.refresh()
# Note that we don't reuse the existing connection to target
# because the migrate3 API doesn't support P2P migrations.
error = self.lv_dom.migrateToURI3(dest_uri, migration_params, flags)
if error:
raise RuntimeError('Unable to migrate VM')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment