'Attach the volume.'

def _attach_volume(self, context, volume, properties, remote=False):

    if remote:
        rpcapi = volume_rpcapi.VolumeAPI()
        try:
            conn = rpcapi.initialize_connection(context, volume, properties)
        except Exception:
            with excutils.save_and_reraise_exception():
                try:
                    rpcapi.terminate_connection(context, volume, properties, force=True)
                except Exception:
                    LOG.warning('Failed    terminating    the    connection    of    volume    %(volume_id)s,    but    it    is    acceptable.', {'volume_id': volume['id']})
    else:
        model_update = None
        try:
            LOG.debug('Volume    %s:    creating    export', volume['id'])
            model_update = self.create_export(context, volume, properties)
            if model_update:
                volume.update(model_update)
                volume.save()
        except exception.CinderException as ex:
            if model_update:
                LOG.exception('Failed    updating    model    of    volume    %(volume_id)s    with    driver    provided    model    %(model)s', {'volume_id': volume['id'], 'model': model_update})
                raise exception.ExportFailure(reason=ex)
        try:
            conn = self.initialize_connection(volume, properties)
        except Exception as err:
            try:
                err_msg = (_('Unable    to    fetch    connection    information    from    backend:    %(err)s') % {'err': six.text_type(err)})
                LOG.error(err_msg)
                LOG.debug('Cleaning    up    failed    connect    initialization.')
                self.remove_export(context, volume)
            except Exception as ex:
                ex_msg = (_('Error    encountered    during    cleanup    of    a    failed    attach:    %(ex)s') % {'ex': six.text_type(ex)})
                LOG.error(err_msg)
                raise exception.VolumeBackendAPIException(data=ex_msg)
            raise exception.VolumeBackendAPIException(data=err_msg)
    try:
        attach_info = self._connect_device(conn)
    except Exception as exc:
        attach_info = getattr(exc, 'kwargs', {}).get('attach_info', None)
        try:
            LOG.debug('Device    for    volume    %s    is    unavailable    but    did    attach,    detaching    it.', volume['id'])
            self._detach_volume(context, attach_info, volume, properties, force=True, remote=remote)
        except Exception:
            LOG.exception('Error    detaching    volume    %s', volume['id'])
        raise
    return (attach_info, volume)
