summaryrefslogtreecommitdiff
path: root/glanceclient/v1/images.py
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-11-25 14:26:02 -0500
committerBrian Waldon <bcwaldon@gmail.com>2012-11-28 09:46:32 -0800
commit4da8b287b40cf0f0de0fd77998e3e66d8bac7999 (patch)
treea3c2f42395e8f7a0442fac69fe7b1e0a36359503 /glanceclient/v1/images.py
parentc0ec97f310bc56c69c22e49928b4aea4cd8458f1 (diff)
downloadpython-glanceclient-4da8b287b40cf0f0de0fd77998e3e66d8bac7999.tar.gz
Add --sort-key and --sort-dir to image-list
The --sort-key and --sort-dir CLI options allow users to control the field and direction by which their images are sorted in an image-list operation. The previous default sort behavior of sorting by ID asc has been preserved. Fixes bug 1082957. Change-Id: I1d3664219c275b0379fe176f8288d6ffae0dffbe
Diffstat (limited to 'glanceclient/v1/images.py')
-rw-r--r--glanceclient/v1/images.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/glanceclient/v1/images.py b/glanceclient/v1/images.py
index 26fe7d6..bb3da3c 100644
--- a/glanceclient/v1/images.py
+++ b/glanceclient/v1/images.py
@@ -34,6 +34,10 @@ CREATE_PARAMS = UPDATE_PARAMS + ('id',)
DEFAULT_PAGE_SIZE = 20
+SORT_DIR_VALUES = ('asc', 'desc')
+SORT_KEY_VALUES = ('name', 'status', 'container_format', 'disk_format',
+ 'size', 'id', 'created_at', 'updated_at')
+
class Image(base.Resource):
def __repr__(self):
@@ -146,6 +150,22 @@ class ImageManager(base.Manager):
if 'marker' in kwargs:
params['marker'] = kwargs['marker']
+ sort_key = kwargs.get('sort_key')
+ if sort_key is not None:
+ if sort_key in SORT_KEY_VALUES:
+ params['sort_key'] = sort_key
+ else:
+ raise ValueError('sort_key must be one of the following: %s.'
+ % ', '.join(SORT_KEY_VALUES))
+
+ sort_dir = kwargs.get('sort_dir')
+ if sort_dir is not None:
+ if sort_dir in SORT_DIR_VALUES:
+ params['sort_dir'] = sort_dir
+ else:
+ raise ValueError('sort_dir must be one of the following: %s.'
+ % ', '.join(SORT_DIR_VALUES))
+
filters = kwargs.get('filters', {})
properties = filters.pop('properties', {})
for key, value in properties.items():