#NEWLINE# @ oslo_db_api . wrap_db_retry ( max_retries = db_api . MAX_RETRIES , retry_interval = 0.1 , inc_retry_interval = True , retry_on_request = True , exception_checker = db_api . is_deadlock ) #NEWLINE# def make_reservation( self , context , tenant_id , resources , deltas , plugin ) : #NEWLINE# #INDENT# requested_resources = deltas . keys ( ) #NEWLINE# with db_api . autonested_transaction ( context . session ) : #NEWLINE# #INDENT# current_limits = self . get_tenant_quotas ( context , resources , tenant_id ) #NEWLINE# unlimited_resources = set ( [ resource for ( resource , limit ) in current_limits . items ( ) if ( limit < 0 ) ] ) #NEWLINE# LOG . debug ( 'Resources %s have unlimited quota limit. It is not required to calculated headroom ' , ',' . join ( unlimited_resources ) ) #NEWLINE# requested_resources = ( set ( requested_resources ) - unlimited_resources ) #NEWLINE# current_usages = dict ( ( ( resource , resources [ resource ] . count ( context , plugin , tenant_id , resync_usage = False ) ) for resource in requested_resources ) ) #NEWLINE# expired_deltas = quota_api . get_reservations_for_resources ( context , tenant_id , requested_resources , expired = True ) #NEWLINE# resources_over_limit = [ ] #NEWLINE# for resource in requested_resources : #NEWLINE# #INDENT# expired_reservations = expired_deltas . get ( resource , 0 ) #NEWLINE# total_usage = ( current_usages [ resource ] - expired_reservations ) #NEWLINE# res_headroom = ( self [ resource ] - total_usage ) #NEWLINE# LOG . debug ( 'Attempting to reserve %(delta)d items for resource %(resource)s. Total usage: %(total)d; quota limit: %(limit)d; headroom:%(headroom)d' , { #NEWLINE# #INDENT# 'resource' : resource , #NEWLINE# 'delta' : deltas [ resource ] , #NEWLINE# 'total' : total_usage , #NEWLINE# 'limit' : current_limits [ resource ] , #NEWLINE# 'headroom' : res_headroom , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( res_headroom < deltas [ resource ] ) : #NEWLINE# #INDENT# resources_over_limit . append ( resource ) #NEWLINE# #UNINDENT# if expired_reservations : #NEWLINE# #INDENT# self . _handle_expired_reservations ( context , tenant_id ) #NEWLINE# #UNINDENT# #UNINDENT# if resources_over_limit : #NEWLINE# #INDENT# raise exceptions . OverQuota ( overs = sorted ( resources_over_limit ) ) #NEWLINE# #UNINDENT# return quota_api . create_reservation ( context , tenant_id , deltas )