Add the ability to specify the sort dir for each key

Extend rest images api v2 with multiple sort directions support.
Example:
/v2/images/detail?sort_key=name&sort_dir=asc&sort_key=size&sort_dir=desc
Changed database api which now can take sort_dir param as a list.

python-glanceclient support will be added in separate commit.

Implements-blueprint: glance-sorting-enhancements
DocImpact
APIImpact
Change-Id: Ib43b53abfba7cb5789d916a014376cf38fc5245b
This commit is contained in:
Mike Fedosin
2015-01-19 21:00:57 +03:00
parent f428567ec0
commit fac0cb2f07
13 changed files with 366 additions and 83 deletions

View File

@@ -196,7 +196,7 @@ class Controller(object):
'filters': self._get_filters(req),
'limit': self._get_limit(req),
'sort_key': [self._get_sort_key(req)],
'sort_dir': self._get_sort_dir(req),
'sort_dir': [self._get_sort_dir(req)],
'marker': self._get_marker(req),
}
@@ -292,7 +292,7 @@ class Controller(object):
def _get_sort_dir(self, req):
"""Parse a sort direction query param from the request object."""
sort_dir = req.params.get('sort_dir', None)
sort_dir = req.params.get('sort_dir', 'desc')
if sort_dir is not None and sort_dir not in SUPPORTED_SORT_DIRS:
_keys = ', '.join(SUPPORTED_SORT_DIRS)
msg = _("Unsupported sort_dir. Acceptable values: %s") % (_keys,)