Wiredcraft / dopy

Digital Ocean Python
MIT License
95 stars 62 forks source link

Only first page of API results returned #29

Closed rhartkopf closed 8 years ago

rhartkopf commented 9 years ago

DigitalOcean paginates their results, returning a default of 20 and max of 200 entries. When requesting a list of my 48 droplets, only 20 are returned. I have only confirmed this with droplet requests, but I'm sure it affects others as well.

https://developers.digitalocean.com/documentation/changelog/api-v2/tweak-per-page/

Here is an example of curl requests against the API with and without the per_page option:

ryan@ops-server:dopy$ curl -s -X GET -H "Authorization: Bearer $TOKEN" \
"https://api.digitalocean.com/v2/droplets" \
| python -m json.tool | grep version | wc -l
20
ryan@ops-server:dopy$ curl -s -X GET -H "Authorization: Bearer $TOKEN" \
"https://api.digitalocean.com/v2/droplets?per_page=100" \
| python -m json.tool | grep version | wc -l
48

I'm a python novice but am doing some testing to see if I can implement this.

zbal commented 9 years ago

You are correct - let me see how we could implement that.

CheRuisiBesares commented 9 years ago

Would love to see this fixed too. Anyone using the DO dynamic inventory plugin for ansible are getting hit by this bug.

rhartkopf commented 9 years ago

For anyone waiting for a fix who just wants to get this working, I just modified the flags in /usr/local/lib/python2.7/dist-packages/dopy/manager.py to return the max results:

 29     def all_active_droplets(self):
 30         json = self.request('/droplets?per_page=200')

This will be overwritten by pip at the next upgrade, so it's not a permanent solution by any means.