Add parameter support to pagination-list

Before categories.list did not support passing any parameters to API
call. This commit allows passing parameters, that would be urlencoded
and appended to the url.
This would allow to paginate the query.

Co-Authored-By: Kirill Zaitsev <kzaitsev@mirantis.com>
Change-Id: I9b90624ee5698baa598b18b16400e193fc9c5a1f
Related-bug: #1474932
This commit is contained in:
Ekaterina Chernova 2015-07-31 11:40:10 +03:00
parent bf042ae99a
commit f3c143a3a8
1 changed files with 21 additions and 3 deletions

View File

@ -12,6 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from six.moves import urllib
from muranoclient.common import base
@ -26,9 +29,24 @@ class Category(base.Resource):
class CategoryManager(base.Manager):
resource_class = Category
def list(self):
return self._list('/v1/catalog/categories',
response_key='categories')
def list(self, **kwargs):
"""Get category list with pagination support.
:param sort_keys: an array of fields used to sort the list (string)
:param sort_dir: 'asc' or 'desc' for ascending or descending sort
:param limit: maximum number of categories to return
:param marker: begin returning categories that appear later in the
category list than that represented by this marker id
"""
params = {}
for key, value in six.iteritems(kwargs):
if value:
params[key] = value
url = '/v1/catalog/categories?{0}'.format(
urllib.parse.urlencode(params, True))
return self._list(url, response_key='categories')
def get(self, id):
return self._get('/v1/catalog/categories/{0}'.format(id))