def migrate_disk_and_power_off(self, context, instance, dest, flavor, network_info, block_device_info=None):
    LOG.debug('Starting migrate_disk_and_power_off', instance=instance)
    for kind in ('root_gb', 'ephemeral_gb'):
        if (flavor[kind] < instance[kind]):
            reason = _('Unable to resize disk down.')
            raise exception.InstanceFaultRollback(exception.ResizeError(reason=reason))
    disk_info_text = self.get_instance_disk_info(instance['name'], block_device_info=block_device_info)
    disk_info = jsonutils.loads(disk_info_text)
    if ((CONF.libvirt.images_type == 'lvm') and (not self._is_booted_from_volume(instance, disk_info_text))):
        reason = 'Migration is not supported for LVM backed instances'
        raise exception.MigrationPreCheckError(reason)
    inst_base = libvirt_utils.get_instance_path(instance)
    inst_base_resize = (inst_base + '_resize')
    shared_storage = self._is_storage_shared_with(dest, inst_base)
    if (not shared_storage):
        utils.execute('ssh', dest, 'mkdir', '-p', inst_base)
    self.power_off(instance)
    block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
    for vol in block_device_mapping:
        connection_info = vol['connection_info']
        disk_dev = vol['mount_device'].rpartition('/')[2]
        self._disconnect_volume(connection_info, disk_dev)
    try:
        utils.execute('mv', inst_base, inst_base_resize)
        if shared_storage:
            dest = None
            utils.execute('mkdir', '-p', inst_base)
        active_flavor = flavors.extract_flavor(instance)
        for info in disk_info:
            img_path = info['path']
            fname = os.path.basename(img_path)
            from_path = os.path.join(inst_base_resize, fname)
            if ((fname == 'disk.swap') and (active_flavor.get('swap', 0) != flavor.get('swap', 0))):
                continue
            if ((info['type'] == 'qcow2') and info['backing_file']):
                tmp_path = (from_path + '_rbase')
                utils.execute('qemu-img', 'convert', '-f', 'qcow2', '-O', 'qcow2', from_path, tmp_path)
                if shared_storage:
                    utils.execute('mv', tmp_path, img_path)
                else:
                    libvirt_utils.copy_image(tmp_path, img_path, host=dest)
                    utils.execute('rm', '-f', tmp_path)
            else:
                libvirt_utils.copy_image(from_path, img_path, host=dest)
    except Exception:
        with excutils.save_and_reraise_exception():
            self._cleanup_remote_migration(dest, inst_base, inst_base_resize, shared_storage)
    return disk_info_text
def migrate_disk_and_power_off(self, context, instance, dest, flavor, network_info, block_device_info=None):
    LOG.debug('Starting migrate_disk_and_power_off', instance=instance)
    for kind in ('root_gb', 'ephemeral_gb'):
        if (flavor[kind] < instance[kind]):
            reason = _('Unable to resize disk down.')
            raise exception.InstanceFaultRollback(exception.ResizeError(reason=reason))
    disk_info_text = self.get_instance_disk_info(instance['name'], block_device_info=block_device_info)
    disk_info = jsonutils.loads(disk_info_text)
    if ((CONF.libvirt.images_type == 'lvm') and (not self._is_booted_from_volume(instance, disk_info_text))):
        reason = 'Migration is not supported for LVM backed instances'
        raise exception.MigrationPreCheckError(reason)
    inst_base = libvirt_utils.get_instance_path(instance)
    inst_base_resize = (inst_base + '_resize')
    shared_storage = self._is_storage_shared_with(dest, inst_base)
    if (not shared_storage):
        utils.execute('ssh', dest, 'mkdir', '-p', inst_base)
    self.power_off(instance)
    block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
    for vol in block_device_mapping:
        connection_info = vol['connection_info']
        disk_dev = vol['mount_device'].rpartition('/')[2]
        self._disconnect_volume(connection_info, disk_dev)
    try:
        utils.execute('mv', inst_base, inst_base_resize)
        if shared_storage:
            dest = None
            utils.execute('mkdir', '-p', inst_base)
        active_flavor = flavors.extract_flavor(instance)
        for info in disk_info:
            img_path = info['path']
            fname = os.path.basename(img_path)
            from_path = os.path.join(inst_base_resize, fname)
            if ((fname == 'disk.swap') and (active_flavor.get('swap', 0) != flavor.get('swap', 0))):
                continue
            if ((info['type'] == 'qcow2') and info['backing_file']):
                tmp_path = (from_path + '_rbase')
                utils.execute('qemu-img', 'convert', '-f', 'qcow2', '-O', 'qcow2', from_path, tmp_path)
                if shared_storage:
                    utils.execute('mv', tmp_path, img_path)
                else:
                    libvirt_utils.copy_image(tmp_path, img_path, host=dest)
                    utils.execute('rm', '-f', tmp_path)
            else:
                libvirt_utils.copy_image(from_path, img_path, host=dest)
    except Exception:
        with excutils.save_and_reraise_exception():
            self._cleanup_remote_migration(dest, inst_base, inst_base_resize, shared_storage)
    return disk_info_text