david-caro / python-foreman

Small low level python wrapper around Foreman API
GNU General Public License v2.0
57 stars 37 forks source link

No support for pagination #38

Closed fpytloun closed 9 years ago

fpytloun commented 9 years ago

Unfortunately client has no support for pagination. Eg. if I call following against Foreman with more than 50 hosts:

hosts = provider.foreman.index_hosts()

The result looks like:

(Pdb) hosts.keys()
[u'sort', u'search', u'results', u'per_page', u'total', u'subtotal', u'page']
(Pdb) hosts['results'] = {}
(Pdb) print simplejson.dumps(hosts, indent=4, separators=(',', ': '))
{
    "sort": {
        "by": null,
        "order": null
    },
    "search": null,
    "results": {},
    "per_page": 50,
    "total": 583,
    "subtotal": 583,
    "page": 1
}

I believe this is a bug because it makes listing all hosts/users/whatever impossible and user has to handle pages on his own.

fpytloun commented 9 years ago

Ok, found per_page argument. Should be documented somewhere :-)

index(self, search=None, order=None, page=None, per_page=None) method of foreman.client.Hosts instance
    List all hosts

    :param search: filter results; Must be String (OPTIONAL)
    :param order: sort results; Must be String (OPTIONAL)
    :param page: paginate results; Must be String (OPTIONAL)
    :param per_page: number of entries per request; Must be String (OPTIONAL)

So solution can be eg.:

f.index_hosts(per_page=999999)