From 36d8a134d679d9c0e6c9b09c3c1c584a32797cfb Mon Sep 17 00:00:00 2001 From: Chad Roberts Date: Mon, 17 Nov 2014 16:12:29 -0500 Subject: Adding support for query filtering to list() calls Each of the list() methods now supports an extra parameter, search_opts, which is a dict that will contain search fields and values to limit the result sets. The changes here will also rely upon changes to the Sahara service to support query-style parameters. Change-Id: I26986cbc153c3f8ad74b52d91086afbdfbd93926 Implements: bp enable-result-filtering --- saharaclient/api/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'saharaclient/api/base.py') diff --git a/saharaclient/api/base.py b/saharaclient/api/base.py index c2c9c36..ee85c2d 100644 --- a/saharaclient/api/base.py +++ b/saharaclient/api/base.py @@ -17,6 +17,7 @@ import json import logging import six +from six.moves.urllib import parse from saharaclient.openstack.common.gettextutils import _ @@ -161,3 +162,12 @@ class APIException(Exception): self.error_code = error_code self.error_name = error_name self.error_message = error_message + + +def get_query_string(search_opts): + if search_opts: + qparams = sorted(search_opts.items(), key=lambda x: x[0]) + query_string = "?%s" % parse.urlencode(qparams) + else: + query_string = "" + return query_string \ No newline at end of file -- cgit v1.2.1