From d0c0eacf589713346c194d38f244393e632f29eb Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Fri, 11 Sep 2015 18:02:15 +0200 Subject: [PATCH] Implemented disk selection in VM migrations --- .../node/hypervisor/domains/__init__.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/cloudcontrol/node/hypervisor/domains/__init__.py b/cloudcontrol/node/hypervisor/domains/__init__.py index f93bd9f..71598cb 100644 --- a/cloudcontrol/node/hypervisor/domains/__init__.py +++ b/cloudcontrol/node/hypervisor/domains/__init__.py @@ -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') -- GitLab