'Preparation live migration.'

def pre_live_migration(self, context, instance, block_device_info, network_info, disk_info, migrate_data):

    if (disk_info is not None):
        disk_info = jsonutils.loads(disk_info)
    LOG.debug('migrate_data    in    pre_live_migration:    %s', migrate_data, instance=instance)
    is_shared_block_storage = migrate_data.is_shared_block_storage
    is_shared_instance_path = migrate_data.is_shared_instance_path
    is_block_migration = migrate_data.block_migration
    if (not is_shared_instance_path):
        instance_dir = libvirt_utils.get_instance_path_at_destination(instance, migrate_data)
        if os.path.exists(instance_dir):
            raise exception.DestinationDiskExists(path=instance_dir)
        LOG.debug('Creating    instance    directory:    %s', instance_dir, instance=instance)
        os.mkdir(instance_dir)
        if disk_info:
            image_disk_info = {}
            for info in disk_info:
                image_file = os.path.basename(info['path'])
                image_path = os.path.join(instance_dir, image_file)
                image_disk_info[image_path] = info['type']
            LOG.debug('Creating    disk.info    with    the    contents:    %s', image_disk_info, instance=instance)
            image_disk_info_path = os.path.join(instance_dir, 'disk.info')
            libvirt_utils.write_to_file(image_disk_info_path, jsonutils.dumps(image_disk_info))
        if (not is_shared_block_storage):
            LOG.debug('Checking    to    make    sure    images    and    backing    files    are    present    before    live    migration.', instance=instance)
            self._create_images_and_backing(context, instance, instance_dir, disk_info, fallback_from_host=instance.host)
            if (configdrive.required_by(instance) and (CONF.config_drive_format == 'iso9660')):
                src = ('%s:%s/disk.config' % (instance.host, instance_dir))
                self._remotefs.copy_file(src, instance_dir)
        if (not is_block_migration):
            self._ensure_console_log_for_instance(instance)
            self._fetch_instance_kernel_ramdisk(context, instance)
    block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
    if len(block_device_mapping):
        LOG.debug('Connecting    volumes    before    live    migration.', instance=instance)
    for bdm in block_device_mapping:
        connection_info = bdm['connection_info']
        disk_info = blockinfo.get_info_from_bdm(instance, CONF.libvirt.virt_type, instance.image_meta, bdm)
        self._connect_volume(connection_info, disk_info, instance)
    LOG.debug('Plugging    VIFs    before    live    migration.', instance=instance)
    max_retry = CONF.live_migration_retry_count
    for cnt in range(max_retry):
        try:
            self.plug_vifs(instance, network_info)
            break
        except processutils.ProcessExecutionError:
            if (cnt == (max_retry - 1)):
                raise
            else:
                LOG.warning('plug_vifs()    failed    %(cnt)d.    Retry    up    to    %(max_retry)d.', {'cnt': cnt, 'max_retry': max_retry}, instance=instance)
                greenthread.sleep(1)
    if (not migrate_data):
        migrate_data = objects.LibvirtLiveMigrateData(bdms=[])
    else:
        migrate_data.bdms = []
    migrate_data.target_connect_addr = CONF.libvirt.live_migration_inbound_addr
    migrate_data.supported_perf_events = self._supported_perf_events
    migrate_data.serial_listen_ports = []
    if CONF.serial_console.enabled:
        num_ports = hardware.get_number_of_serial_ports(instance.flavor, instance.image_meta)
        for port in six.moves.range(num_ports):
            migrate_data.serial_listen_ports.append(serial_console.acquire_port(migrate_data.serial_listen_addr))
    for vol in block_device_mapping:
        connection_info = vol['connection_info']
        if connection_info.get('serial'):
            disk_info = blockinfo.get_info_from_bdm(instance, CONF.libvirt.virt_type, instance.image_meta, vol)
            bdmi = objects.LibvirtLiveMigrateBDMInfo()
            bdmi.serial = connection_info['serial']
            bdmi.connection_info = connection_info
            bdmi.bus = disk_info['bus']
            bdmi.dev = disk_info['dev']
            bdmi.type = disk_info['type']
            bdmi.format = disk_info.get('format')
            bdmi.boot_index = disk_info.get('boot_index')
            migrate_data.bdms.append(bdmi)
    return migrate_data
