#NEWLINE# def _get_tenant_compute_usages( request , usages , disabled_quotas , tenant_id ) : #NEWLINE# #INDENT# if tenant_id : #NEWLINE# #INDENT# ( instances , has_more ) = nova . server_list ( request , search_opts = { #NEWLINE# #INDENT# 'tenant_id' : tenant_id , #NEWLINE# #UNINDENT# } , all_tenants = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( instances , has_more ) = nova . server_list ( request ) #NEWLINE# #UNINDENT# flavors = dict ( [ ( f . id , f ) for f in nova . flavor_list ( request ) ] ) #NEWLINE# missing_flavors = [ instance . flavor [ 'id' ] for instance in instances if ( instance . flavor [ 'id' ] not in flavors ) ] #NEWLINE# for missing in missing_flavors : #NEWLINE# #INDENT# if ( flavor not in flavors ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# flavors [ missing ] = nova . flavor_get ( request , missing ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# flavors [ missing ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# exceptions . handle ( request , ignore = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# usages . tally ( 'instances' , len ( instances ) ) #NEWLINE# for flavor in [ flavors [ instance . flavor [ 'id' ] ] for instance in instances ] : #NEWLINE# #INDENT# usages . tally ( 'cores' , getattr ( flavor , 'vcpus' , None ) ) #NEWLINE# usages . tally ( 'ram' , getattr ( flavor , 'ram' , None ) ) #NEWLINE# #UNINDENT# if ( len ( instances ) == 0 ) : #NEWLINE# #INDENT# usages . tally ( 'cores' , 0 ) #NEWLINE# usages . tally ( 'ram' , 0 )