Skip to content

Commit 0214c15

Browse files
committed
Merge branch 'main' of github.com:vitobotta/hetzner-k3s
2 parents 47a40c1 + 592da26 commit 0214c15

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/hetzner/client.cr

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,28 @@ class Hetzner::Client
3939
end
4040

4141
private def fetch_instance_types : Array(InstanceType)
42-
success, response = get("/server_types")
42+
instance_types = [] of InstanceType
43+
page = 1
4344

44-
if success
45-
Hetzner::InstanceTypesList.from_json(response).server_types
46-
else
47-
puts "[Preflight checks] Unable to fetch instance types via Hetzner API"
48-
exit 1
45+
while true
46+
success, response = get("/server_types", {"page" => page.to_s})
47+
48+
unless success
49+
puts "[Preflight checks] Unable to fetch instance types via Hetzner API"
50+
exit 1
51+
end
52+
53+
list = Hetzner::InstanceTypesList.from_json(response)
54+
instance_types.concat(list.server_types)
55+
56+
next_page = list.meta.try &.pagination.try &.next_page
57+
58+
break unless next_page
59+
60+
page = next_page
4961
end
62+
63+
instance_types
5064
end
5165

5266
def get(path, params : Hash = {} of Symbol => String | Bool | Nil)

src/hetzner/instance_types_list.cr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,22 @@ class Hetzner::InstanceTypesList
44
include JSON::Serializable
55

66
property server_types : Array(Hetzner::InstanceType)
7+
property meta : Hetzner::Meta?
8+
end
9+
10+
class Hetzner::Meta
11+
include JSON::Serializable
12+
13+
property pagination : Hetzner::Pagination?
14+
end
15+
16+
class Hetzner::Pagination
17+
include JSON::Serializable
18+
19+
property page : Int32
20+
property per_page : Int32
21+
property total_entries : Int32
22+
property last_page : Int32
23+
property next_page : Int32?
24+
property previous_page : Int32?
725
end

0 commit comments

Comments
 (0)