def _quota_reserve(context, project_id, user_id):
 def get_sync(resource, usage):
  def sync(elevated, project_id, user_id):
   return {resource: usage}
  return sync
 quotas = {}
 user_quotas = {}
 resources = {}
 deltas = {}
 for i in range(3):
  resource = ('resource%d' % i)
  if (i == 2):
   resource = 'fixed_ips'
   quotas[resource] = db.quota_create(context, project_id, resource, (i + 2)).hard_limit
   user_quotas[resource] = quotas[resource]
  else:
   quotas[resource] = db.quota_create(context, project_id, resource, (i + 1)).hard_limit
   user_quotas[resource] = db.quota_create(context, project_id, resource, (i + 1), user_id=user_id).hard_limit
  sync_name = ('_sync_%s' % resource)
  resources[resource] = quota.ReservableResource(resource, sync_name, ('quota_res_%d' % i))
  deltas[resource] = i
  setattr(sqlalchemy_api, sync_name, get_sync(resource, i))
  sqlalchemy_api.QUOTA_SYNC_FUNCTIONS[sync_name] = getattr(sqlalchemy_api, sync_name)
 return db.quota_reserve(context, resources, quotas, user_quotas, deltas, timeutils.utcnow(), CONF.quota.until_refresh, datetime.timedelta(days=1), project_id, user_id)

def _quota_reserve ( context , project_id , user_id ) : def get_sync ( resource , usage ) : def sync ( elevated , project_id , user_id ) : return { resource : usage } return sync quotas = { } user_quotas = { } resources = { } deltas = { } for i in range ( 3 ) : resource = ( 'resource%d' % i ) if ( i == 2 ) : resource = 'fixed_ips' quotas [ resource ] = db . quota_create ( context , project_id , resource , ( i + 2 ) ) . hard_limit user_quotas [ resource ] = quotas [ resource ] else : quotas [ resource ] = db . quota_create ( context , project_id , resource , ( i + 1 ) ) . hard_limit user_quotas [ resource ] = db . quota_create ( context , project_id , resource , ( i + 1 ) , user_id = user_id ) . hard_limit sync_name = ( '_sync_%s' % resource ) resources [ resource ] = quota . ReservableResource ( resource , sync_name , ( 'quota_res_%d' % i ) ) deltas [ resource ] = i setattr ( sqlalchemy_api , sync_name , get_sync ( resource , i ) ) sqlalchemy_api . QUOTA_SYNC_FUNCTIONS [ sync_name ] = getattr ( sqlalchemy_api , sync_name ) return db . quota_reserve ( context , resources , quotas , user_quotas , deltas , timeutils . utcnow ( ) , CONF . quota . until_refresh , datetime . timedelta ( days = 1 ) , project_id , user_id )
create sample quota .