Fix polling by pagination of the Glance API
Change-Id: I227bba6be05b69809514234be9769736c46cab28
diff --git a/collectd/files/plugin/collectd_openstack.py b/collectd/files/plugin/collectd_openstack.py
index f0ecbfc..84b0092 100644
--- a/collectd/files/plugin/collectd_openstack.py
+++ b/collectd/files/plugin/collectd_openstack.py
@@ -368,20 +368,20 @@
_objects.extend(bulk_objs)
- links = resp.get('{}_links'.format(object_name))
- if links is None or self.pagination_limit is None:
- # Either the pagination is not supported or there is
- # no more data
- # In both cases, we got at this stage all the data we
- # can have.
+ if self.pagination_limit is None:
break
- # if there is no 'next' link in the response, all data has
- # been read.
- if len([i for i in links if i.get('rel') == 'next']) == 0:
- break
+ links = resp.get('{}_links'.format(object_name), [])
+ # Glance has not <object>_links section but a 'next' item
+ has_next = len(
+ [i for i in links if i.get('rel') == 'next']) > 0 or \
+ resp.get('next')
- _opts['marker'] = bulk_objs[-1]['id']
+ if has_next:
+ _opts['marker'] = bulk_objs[-1]['id']
+ else:
+ # all data has been read
+ break
if not has_failure:
self._last_run = last_run