diff --git a/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py b/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py index 2da1872934..d95c0391a5 100644 --- a/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py +++ b/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py @@ -21,6 +21,7 @@ import json import logging +from django.conf import settings from django.utils.text import normalize_newlines from django.utils.translation import ugettext_lazy as _ from django.views.decorators.debug import sensitive_variables @@ -264,15 +265,23 @@ class SetInstanceDetailsAction(workflows.Action): return choices def populate_flavor_choices(self, request, context): + """By default, returns the available flavors, sorted by RAM + usage (ascending). + Override these behaviours with a CREATE_INSTANCE_FLAVOR_SORT dict + in local_settings.py.""" try: flavors = api.nova.flavor_list(request) + flavor_sort = getattr(settings, 'CREATE_INSTANCE_FLAVOR_SORT', {}) + rev = flavor_sort.get('reverse', False) + key = flavor_sort.get('key', lambda flavor: flavor.ram) + flavor_list = [(flavor.id, "%s" % flavor.name) - for flavor in flavors] + for flavor in sorted(flavors, key=key, reverse=rev)] except: flavor_list = [] exceptions.handle(request, _('Unable to retrieve instance flavors.')) - return sorted(flavor_list) + return flavor_list def populate_availability_zone_choices(self, request, context): try: diff --git a/openstack_dashboard/local/local_settings.py.example b/openstack_dashboard/local/local_settings.py.example index 4494b695e4..089b33f051 100644 --- a/openstack_dashboard/local/local_settings.py.example +++ b/openstack_dashboard/local/local_settings.py.example @@ -184,6 +184,16 @@ API_RESULT_PAGE_SIZE = 20 # of your entire OpenStack installation, and hopefully be in UTC. TIME_ZONE = "UTC" +# When launching an instance, the menu of available flavors is +# sorted by RAM usage, ascending. Provide a callback method here +# (and/or a flag for reverse sort) for the sorted() method if you'd +# like a different behaviour. For more info, see +# http://docs.python.org/2/library/functions.html#sorted +# CREATE_INSTANCE_FLAVOR_SORT = { +# 'key': my_awesome_callback_method, +# 'reverse': False, +# } + LOGGING = { 'version': 1, # When set to True this will disable all logging except