#NEWLINE# def sort_flavor_list( request , flavors ) : #NEWLINE# #INDENT# 'Utility method to sort a list of flavors.\n        By default, returns the available flavors, sorted by RAM\n        usage (ascending). Override these behaviours with a\n        CREATE_INSTANCE_FLAVOR_SORT dict\n        in local_settings.py.\n    ' #NEWLINE# def get_key( flavor , sort_key ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return getattr ( flavor , sort_key ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# LOG . warning ( 'Could not find sort key "%s". Using the default "ram" instead.' , sort_key ) #NEWLINE# return getattr ( flavor , 'ram' ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# flavor_sort = getattr ( settings , 'CREATE_INSTANCE_FLAVOR_SORT' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# sort_key = flavor_sort . get ( 'key' , 'ram' ) #NEWLINE# rev = flavor_sort . get ( 'reverse' , False ) #NEWLINE# if ( not callable ( sort_key ) ) : #NEWLINE# #INDENT# key = ( lambda flavor : get_key ( flavor , sort_key ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key = sort_key #NEWLINE# #UNINDENT# flavor_list = [ ( flavor . id , ( '%s' % flavor . name ) ) for flavor in sorted ( flavors , key = key , reverse = rev ) ] #NEWLINE# return flavor_list #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# exceptions . handle ( request , _ ( 'Unable to sort instance flavors.' ) ) #NEWLINE# return [ ]