Hello Pablo Iranzo Gómez,
I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/21247
to review the following change.
Change subject: Remove limit of 1000 hosts, and make it use pagination
......................................................................
Remove limit of 1000 hosts, and make it use pagination
Change-Id: I28bdc52e838dc1e28a5965b3954556755d28fb82
Signed-off-by: Pablo <[email protected]>
---
M src/helper/hypervisors.py
1 file changed, 19 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector
refs/changes/47/21247/1
diff --git a/src/helper/hypervisors.py b/src/helper/hypervisors.py
index 352dde2..1ab230f 100644
--- a/src/helper/hypervisors.py
+++ b/src/helper/hypervisors.py
@@ -145,6 +145,22 @@
return api
+def paginate(entity, oquery=""):
+ """Generator for listing all elements of object avoiding api query limit
+ @param entity: object to paginate using list and query
+ @param oquery: optional query to limit results
+ """
+ page = 0
+ length = 100
+ while length > 0:
+ page += 1
+ query = "%s page %s" % (oquery, page)
+ tanda = entity.list(query=query)
+ length = len(tanda)
+ for elem in tanda:
+ yield elem
+
+
def get_all(hostname, username, password, ca, insecure=False):
tree = ENGINETree()
@@ -152,11 +168,11 @@
try:
api = _initialize_api(hostname, username, password, ca, insecure)
if api is not None:
- for dc in api.datacenters.list(max=1000):
+ for dc in paginate(api.datacenters):
tree.add_datacenter(dc)
- for cluster in api.clusters.list(max=1000):
+ for cluster in paginate(api.clusters):
tree.add_cluster(cluster)
- for host in api.hosts.list(max=1000):
+ for host in paginate(api.hosts):
tree.add_host(host)
result = set(tree.get_sortable())
except RequestError as re:
--
To view, visit http://gerrit.ovirt.org/21247
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I28bdc52e838dc1e28a5965b3954556755d28fb82
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: ovirt-log-collector-3.3
Gerrit-Owner: Sandro Bonazzola <[email protected]>
Gerrit-Reviewer: Pablo Iranzo Gómez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches