lsymds / hetznercloud-py

Python SDK for the new Hetzner cloud
MIT License
30 stars 12 forks source link

ISOs missing due to pagination #8

Closed nh2 closed 4 years ago

nh2 commented 6 years ago

When I run

isos = client.isos().get_all()
for l in isos:
    print(l.id, l.name)

it prints

(26, u'virtio-win-0.1.141.iso')
(27, u'ubuntu-16.04.3-server-amd64.iso')
(28, u'ubuntu-17.10.1-server-amd64.iso')
(29, u'debian-9.3.0-amd64-netinst.iso')
(30, u'SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_English_-2_MLF_X21-22843.iso')
(31, u'coreos_beta_production.iso')
(32, u'SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_German_-2_MLF_X21-22827.iso')
(33, u'gparted-live-0.30.0-1-amd64.iso')
(34, u'CentOS-6.9-x86_64-netinstall.iso')
(35, u'SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_Russian_-2_MLF_X21-22838.iso')
(36, u'SW_DVD9_NTRL_Win_Svr_Language_Pack_2016_64Bit_MultiLang_-3_X21-22616.iso')
(38, u'Fedora-Server-netinst-x86_64-27-1.6.iso')
(39, u'CentOS-7-x86_64-NetInstall-1708.iso')
(41, u'debian-8.10.0-amd64-netinst.iso')
(42, u'openSUSE-Leap-42.3-NET-x86_64.iso')
(43, u'SW_DVD5_NTRL_Win_Svr_Language_Pack_2012_R2_64Bit_MultiLang_FPP_VL_OEM_X19-05196.iso')
(44, u'FreeBSD-11.1-RELEASE-amd64-bootonly.iso')
(45, u'FreeBSD-10.4-RELEASE-amd64-bootonly.iso')
(46, u'FreeBSD-10.3-RELEASE-amd64-bootonly.iso')
(47, u'mikrotik-6.41.iso')
(48, u'install62.iso')
(49, u'rancheros.iso')
(50, u'pfSense-CE-2.4.2-RELEASE-amd64.iso')
(52, u'coreos_stable_production.iso')
(53, u'Fedora-Atomic-ostree-x86_64-27-20180117.1.iso')

Many ISOs are missing here; this due to pagination. curling https://api.hetzner.cloud/v1/isos directly shows:

{ ... stuff
  "meta": {
    "pagination": {
      "page": 1,
      "per_page": 25,
      "previous_page": null,
      "next_page": 2,
      "last_page": 2,
      "total_entries": 40
    }
  }
}

As per https://docs.hetzner.cloud/#header-pagination-1:

A per_page parameter specifies the number of items returned per page. The default value is 25, the maximum value is 50 except otherwise specified in the documentation.

nh2 commented 6 years ago

In general it would be clever for the project to always check whether a meta.pagination field is present, even for endpoints where the author expects that they do not paginate, so that e.g. the server list doesn't accidentally contain less results than expected when there are many servers.

ghost commented 6 years ago

Good idea, and thanks for looking into this. I will raise this as a feature and implement it sometime this week.

lsymds commented 4 years ago

Hi! You should look into using the official HCloud Python library as this one is deprecated (and has been for a while now).

https://github.com/hetznercloud/hcloud-python