

def before(self, state):
    resource = state.request.context.get('resource')
    items = state.request.context.get('resources')
    if ((state.request.method != 'POST') or (not resource) or (not items)):
        return
    plugin = manager.NeutronManager.get_plugin_for_resource(resource)
    deltas = collections.Counter(map((lambda x: x['tenant_id']), items))
    reservations = []
    neutron_context = state.request.context.get('neutron_context')
    for (tenant_id, delta) in deltas.items():
        try:
            reservation = quota.QUOTAS.make_reservation(neutron_context, tenant_id, {
                resource: delta,
            }, plugin)
            LOG.debug('Made reservation on behalf of %(tenant_id)s for: %(delta)s', {
                'tenant_id': tenant_id,
                'delta': {
                    resource: delta,
                },
            })
            reservations.append(reservation)
        except exceptions.QuotaResourceUnknown as e:
            LOG.debug(e)
    state.request.context['reservations'] = reservations

dataset/ETHPy150Open openstack/neutron/neutron/pecan_wsgi/hooks/quota_enforcement.py QuotaEnforcementHook.before/original