'Accept a volume that has been offered for transfer.'

def accept(self, context, transfer_id, auth_key):

    volume_api.check_policy(context, 'accept_transfer')
    transfer = self.db.transfer_get(context.elevated(), transfer_id)
    crypt_hash = self._get_crypt_hash(transfer['salt'], auth_key)
    if (crypt_hash != transfer['crypt_hash']):
        msg = (_('Attempt    to    transfer    %s    with    invalid    auth    key.') % transfer_id)
        LOG.error(msg)
        raise exception.InvalidAuthKey(reason=msg)
    volume_id = transfer['volume_id']
    vol_ref = objects.Volume.get_by_id(context.elevated(), volume_id)
    if vol_ref['consistencygroup_id']:
        msg = (_('Volume    %s    must    not    be    part    of    a    consistency    group.') % vol_ref['id'])
        LOG.error(msg)
        raise exception.InvalidVolume(reason=msg)
    try:
        values = {'per_volume_gigabytes': vol_ref.size}
        QUOTAS.limit_check(context, project_id=context.project_id, **values)
    except exception.OverQuota as e:
        quotas = e.kwargs['quotas']
        raise exception.VolumeSizeExceedsLimit(size=vol_ref.size, limit=quotas['per_volume_gigabytes'])
    try:
        reserve_opts = {'volumes': 1, 'gigabytes': vol_ref.size}
        QUOTAS.add_volume_type_opts(context, reserve_opts, vol_ref.volume_type_id)
        reservations = QUOTAS.reserve(context, **reserve_opts)
    except exception.OverQuota as e:
        quota_utils.process_reserve_over_quota(context, e, resource='volumes', size=vol_ref.size)
    try:
        donor_id = vol_ref['project_id']
        reserve_opts = {'volumes': (-1), 'gigabytes': (- vol_ref.size)}
        QUOTAS.add_volume_type_opts(context, reserve_opts, vol_ref.volume_type_id)
        donor_reservations = QUOTAS.reserve(context.elevated(), project_id=donor_id, **reserve_opts)
    except Exception:
        donor_reservations = None
        LOG.exception('Failed    to    update    quota    donating    volume    transfer    id    %s', transfer_id)
    volume_utils.notify_about_volume_usage(context, vol_ref, 'transfer.accept.start')
    try:
        self.volume_api.accept_transfer(context, vol_ref, context.user_id, context.project_id)
        self.db.transfer_accept(context.elevated(), transfer_id, context.user_id, context.project_id)
        QUOTAS.commit(context, reservations)
        if donor_reservations:
            QUOTAS.commit(context, donor_reservations, project_id=donor_id)
        LOG.info('Volume    %s    has    been    transferred.', volume_id)
    except Exception:
        with excutils.save_and_reraise_exception():
            QUOTAS.rollback(context, reservations)
            if donor_reservations:
                QUOTAS.rollback(context, donor_reservations, project_id=donor_id)
    vol_ref = self.db.volume_get(context, volume_id)
    volume_utils.notify_about_volume_usage(context, vol_ref, 'transfer.accept.end')
    return {'id': transfer_id, 'display_name': transfer['display_name'], 'volume_id': vol_ref['id']}
