hetznercloud 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -6
- data/Gemfile +13 -0
- data/LICENSE.md +1 -1
- data/README.md +76 -30
- data/config/inflections.rb +6 -0
- data/lib/hcloud/client.rb +4 -3
- data/lib/hcloud/collection.rb +4 -2
- data/lib/hcloud/concerns/concerns.rb +4 -0
- data/lib/hcloud/concerns/creatable.rb +2 -0
- data/lib/hcloud/concerns/deletable.rb +2 -0
- data/lib/hcloud/concerns/labelable.rb +11 -0
- data/lib/hcloud/concerns/queryable.rb +2 -0
- data/lib/hcloud/concerns/updatable.rb +5 -1
- data/lib/hcloud/entities/primary_ip_prices.rb +8 -0
- data/lib/hcloud/entities/private_network.rb +15 -0
- data/lib/hcloud/entities/protection.rb +0 -2
- data/lib/hcloud/entities/server_protection.rb +11 -0
- data/lib/hcloud/errors.rb +8 -0
- data/lib/hcloud/http.rb +4 -2
- data/lib/hcloud/resource_type.rb +33 -2
- data/lib/hcloud/resources/action.rb +5 -6
- data/lib/hcloud/resources/certificate.rb +8 -6
- data/lib/hcloud/resources/datacenter.rb +1 -1
- data/lib/hcloud/resources/firewall.rb +7 -5
- data/lib/hcloud/resources/floating_ip.rb +7 -5
- data/lib/hcloud/resources/image.rb +6 -7
- data/lib/hcloud/resources/iso.rb +1 -1
- data/lib/hcloud/resources/load_balancer.rb +7 -5
- data/lib/hcloud/resources/load_balancer_type.rb +1 -1
- data/lib/hcloud/resources/location.rb +1 -1
- data/lib/hcloud/resources/metadata.rb +33 -0
- data/lib/hcloud/resources/network.rb +5 -3
- data/lib/hcloud/resources/placement_group.rb +7 -5
- data/lib/hcloud/resources/pricing.rb +2 -0
- data/lib/hcloud/resources/primary_ip.rb +150 -0
- data/lib/hcloud/resources/server.rb +9 -7
- data/lib/hcloud/resources/server_type.rb +1 -1
- data/lib/hcloud/resources/ssh_key.rb +8 -6
- data/lib/hcloud/resources/volume.rb +8 -6
- data/lib/hcloud/version.rb +2 -2
- data/lib/hcloud.rb +1 -1
- data/lib/http/mime_type/yaml.rb +23 -0
- data/lib/http/rate_limiter.rb +40 -0
- metadata +11 -129
@@ -11,15 +11,18 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort firewalls
|
13
13
|
#
|
14
|
-
# HCloud::Firewall.
|
14
|
+
# HCloud::Firewall.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::Firewall id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::Firewall.
|
17
|
+
# HCloud::Firewall.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::Firewall id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search firewalls
|
21
21
|
#
|
22
|
-
# HCloud::Firewall.
|
22
|
+
# HCloud::Firewall.where(name: "my_firewall")
|
23
|
+
# # => #<HCloud::Firewall id: 1, ...>
|
24
|
+
#
|
25
|
+
# HCloud::Firewall.where(label_selector: { environment: "production" })
|
23
26
|
# # => #<HCloud::Firewall id: 1, ...>
|
24
27
|
#
|
25
28
|
# == Find firewall by ID
|
@@ -107,6 +110,7 @@ module HCloud
|
|
107
110
|
creatable
|
108
111
|
updatable
|
109
112
|
deletable
|
113
|
+
labelable
|
110
114
|
|
111
115
|
attribute :id, :integer
|
112
116
|
attribute :name
|
@@ -117,8 +121,6 @@ module HCloud
|
|
117
121
|
|
118
122
|
attribute :rules, :rule, array: true, default: -> { [] }
|
119
123
|
|
120
|
-
attribute :labels, default: -> { {} }
|
121
|
-
|
122
124
|
action :apply_to_resources
|
123
125
|
action :remove_from_resources
|
124
126
|
action :set_rules
|
@@ -11,15 +11,18 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort floating IPs
|
13
13
|
#
|
14
|
-
# HCloud::FloatingIP.
|
14
|
+
# HCloud::FloatingIP.sort(id: :asc)
|
15
15
|
# # => [#<HCloud::FloatingIP id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::FloatingIP.
|
17
|
+
# HCloud::FloatingIP.sort(:id, created: :asc)
|
18
18
|
# # => [#<HCloud::FloatingIP id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search floating IPs
|
21
21
|
#
|
22
|
-
# HCloud::FloatingIP.
|
22
|
+
# HCloud::FloatingIP.where(name: "my_floating_ip")
|
23
|
+
# # => #<HCloud::FloatingIP id: 1, ...>
|
24
|
+
#
|
25
|
+
# HCloud::FloatingIP.where(label_selector: { environment: "production" })
|
23
26
|
# # => #<HCloud::FloatingIP id: 1, ...>
|
24
27
|
#
|
25
28
|
# == Find floating IP by ID
|
@@ -104,6 +107,7 @@ module HCloud
|
|
104
107
|
creatable
|
105
108
|
updatable
|
106
109
|
deletable
|
110
|
+
labelable
|
107
111
|
|
108
112
|
attribute :id, :integer
|
109
113
|
attribute :name
|
@@ -121,8 +125,6 @@ module HCloud
|
|
121
125
|
|
122
126
|
attribute :server, :server
|
123
127
|
|
124
|
-
attribute :labels, default: -> { {} }
|
125
|
-
|
126
128
|
alias blocked? blocked
|
127
129
|
|
128
130
|
action :assign
|
@@ -11,21 +11,21 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort images
|
13
13
|
#
|
14
|
-
# HCloud::Image.
|
14
|
+
# HCloud::Image.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::Image id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::Image.
|
17
|
+
# HCloud::Image.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::Image id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search images
|
21
21
|
#
|
22
|
-
# HCloud::Image.
|
22
|
+
# HCloud::Image.where(name: "my_image")
|
23
23
|
# # => #<HCloud::Image id: 1, ...>
|
24
24
|
#
|
25
|
-
# HCloud::Image.
|
25
|
+
# HCloud::Image.where(status: "available", include_deprecated: false)
|
26
26
|
# # => #<HCloud::Image id: 1, ...>
|
27
27
|
#
|
28
|
-
# HCloud::Image.
|
28
|
+
# HCloud::Image.where(type: "backup", bound_to: 1)
|
29
29
|
# # => #<HCloud::Image id: 1, ...>
|
30
30
|
#
|
31
31
|
# == Find image by ID
|
@@ -85,6 +85,7 @@ module HCloud
|
|
85
85
|
queryable
|
86
86
|
updatable
|
87
87
|
deletable
|
88
|
+
labelable
|
88
89
|
|
89
90
|
attribute :id, :integer
|
90
91
|
attribute :name
|
@@ -113,8 +114,6 @@ module HCloud
|
|
113
114
|
|
114
115
|
attribute :rapid_deploy
|
115
116
|
|
116
|
-
attribute :labels, default: -> { {} }
|
117
|
-
|
118
117
|
action :change_protection
|
119
118
|
|
120
119
|
def created?
|
data/lib/hcloud/resources/iso.rb
CHANGED
@@ -11,15 +11,18 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort load balancers
|
13
13
|
#
|
14
|
-
# HCloud::LoadBalancer.
|
14
|
+
# HCloud::LoadBalancer.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::LoadBalancer id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::LoadBalancer.
|
17
|
+
# HCloud::LoadBalancer.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::LoadBalancer id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search load balancers
|
21
21
|
#
|
22
|
-
# HCloud::LoadBalancer.
|
22
|
+
# HCloud::LoadBalancer.where(name: "my_load_balancer")
|
23
|
+
# # => #<HCloud::LoadBalancer id: 1, ...>
|
24
|
+
#
|
25
|
+
# HCloud::LoadBalancer.where(label_selector: { environment: "production" })
|
23
26
|
# # => #<HCloud::LoadBalancer id: 1, ...>
|
24
27
|
#
|
25
28
|
# == Find load balancer by ID
|
@@ -65,6 +68,7 @@ module HCloud
|
|
65
68
|
updatable
|
66
69
|
deletable
|
67
70
|
meterable
|
71
|
+
labelable
|
68
72
|
|
69
73
|
attribute :id, :integer
|
70
74
|
attribute :name
|
@@ -94,8 +98,6 @@ module HCloud
|
|
94
98
|
|
95
99
|
attribute :protection, :protection
|
96
100
|
|
97
|
-
attribute :labels, default: -> { {} }
|
98
|
-
|
99
101
|
def creatable_attributes
|
100
102
|
[:name, :labels, :algorithm, :network_zone, :public_interface, :services, :targets, load_balancer_type: [:id, :name], location: [:id, :name], network: [:id, :name]]
|
101
103
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HCloud
|
4
|
+
##
|
5
|
+
# Server metadata.
|
6
|
+
#
|
7
|
+
# This resource allows a Hetzner server to retrieve metadata about itself.
|
8
|
+
# It cannot be used outside of Hetzner servers.
|
9
|
+
#
|
10
|
+
# == Find metadata
|
11
|
+
#
|
12
|
+
# HCloud::Metadata.find
|
13
|
+
# # => #<HCloud::Metadata ...>
|
14
|
+
#
|
15
|
+
class Metadata < Resource
|
16
|
+
ENDPOINT = "https://169.254.169.254/hetzner/v1/metadata"
|
17
|
+
|
18
|
+
attribute :hostname
|
19
|
+
attribute :instance_id, :integer
|
20
|
+
attribute :public_ipv4
|
21
|
+
attribute :availability_zone
|
22
|
+
attribute :region
|
23
|
+
|
24
|
+
attribute :private_networks, :private_network, array: true, default: -> { [] }
|
25
|
+
|
26
|
+
def self.find
|
27
|
+
new(::HTTP
|
28
|
+
.get(ENDPOINT)
|
29
|
+
.parse(:yaml)
|
30
|
+
.deep_transform_keys { |key| key.underscore.to_sym })
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -11,7 +11,10 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Search networks
|
13
13
|
#
|
14
|
-
# HCloud::Network.
|
14
|
+
# HCloud::Network.where(name: "my_network")
|
15
|
+
# # => #<HCloud::Network id: 1, ...>
|
16
|
+
#
|
17
|
+
# HCloud::Network.where(label_selector: { environment: "production" })
|
15
18
|
# # => #<HCloud::Network id: 1, ...>
|
16
19
|
#
|
17
20
|
# == Find network by ID
|
@@ -106,6 +109,7 @@ module HCloud
|
|
106
109
|
creatable
|
107
110
|
updatable
|
108
111
|
deletable
|
112
|
+
labelable
|
109
113
|
|
110
114
|
attribute :id, :integer
|
111
115
|
attribute :name
|
@@ -121,8 +125,6 @@ module HCloud
|
|
121
125
|
|
122
126
|
attribute :protection, :protection
|
123
127
|
|
124
|
-
attribute :labels, default: -> { {} }
|
125
|
-
|
126
128
|
action :change_protection
|
127
129
|
|
128
130
|
action :add_route
|
@@ -11,15 +11,18 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort placement groups
|
13
13
|
#
|
14
|
-
# HCloud::PlacementGroup.
|
14
|
+
# HCloud::PlacementGroup.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::PlacementGroup id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::PlacementGroup.
|
17
|
+
# HCloud::PlacementGroup.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::PlacementGroup id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search placement groups
|
21
21
|
#
|
22
|
-
# HCloud::PlacementGroup.
|
22
|
+
# HCloud::PlacementGroup.where(name: "my_placement_group")
|
23
|
+
# # => #<HCloud::PlacementGroup id: 2, ...>
|
24
|
+
#
|
25
|
+
# HCloud::PlacementGroup.where(label_selector: { environment: "production" })
|
23
26
|
# # => #<HCloud::PlacementGroup id: 2, ...>
|
24
27
|
#
|
25
28
|
# == Find placement group by ID
|
@@ -55,6 +58,7 @@ module HCloud
|
|
55
58
|
creatable
|
56
59
|
updatable
|
57
60
|
deletable
|
61
|
+
labelable
|
58
62
|
|
59
63
|
attribute :id, :integer
|
60
64
|
attribute :name
|
@@ -62,8 +66,6 @@ module HCloud
|
|
62
66
|
|
63
67
|
attribute :servers, :server, array: true, default: -> { [] }
|
64
68
|
|
65
|
-
attribute :labels, default: -> { {} }
|
66
|
-
|
67
69
|
def creatable_attributes
|
68
70
|
[:name, :type, :labels]
|
69
71
|
end
|
@@ -21,6 +21,8 @@ module HCloud
|
|
21
21
|
|
22
22
|
attribute :load_balancer_types, :load_balancer_type_price, array: true, default: -> { [] }
|
23
23
|
|
24
|
+
attribute :primary_ips, :primary_ip_prices, array: true, default: -> { [] }
|
25
|
+
|
24
26
|
attribute :server_backup, :server_backup_price
|
25
27
|
|
26
28
|
attribute :server_types, :server_type_price, array: true, default: -> { [] }
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HCloud
|
4
|
+
##
|
5
|
+
# Represents a primary IP
|
6
|
+
#
|
7
|
+
# == List all primary IPs
|
8
|
+
#
|
9
|
+
# HCloud::PrimaryIP.all
|
10
|
+
# # => [#<HCloud::PrimaryIP id: 1, ...>, ...]
|
11
|
+
#
|
12
|
+
# == Sort primary IPs
|
13
|
+
#
|
14
|
+
# HCloud::PrimaryIP.sort(id: :asc)
|
15
|
+
# # => [#<HCloud::PrimaryIP id: 1, ...>, ...]
|
16
|
+
#
|
17
|
+
# HCloud::PrimaryIP.sort(:id, created: :asc)
|
18
|
+
# # => [#<HCloud::PrimaryIP id: 1, ...>, ...]
|
19
|
+
#
|
20
|
+
# == Search primary IPs
|
21
|
+
#
|
22
|
+
# HCloud::PrimaryIP.where(name: "my_primary_ip")
|
23
|
+
# # => #<HCloud::PrimaryIP id: 1, ...>
|
24
|
+
#
|
25
|
+
# HCloud::PrimaryIP.where(ip: "1.2.3.4")
|
26
|
+
# # => #<HCloud::PrimaryIP id: 1, ...>
|
27
|
+
#
|
28
|
+
# HCloud::PrimaryIP.where(label_selector: { environment: "production" })
|
29
|
+
# # => #<HCloud::PrimaryIP id: 1, ...>
|
30
|
+
#
|
31
|
+
# == Find primary IP by ID
|
32
|
+
#
|
33
|
+
# HCloud::PrimaryIP.find(1)
|
34
|
+
# # => #<HCloud::PrimaryIP id: 1, ...>
|
35
|
+
#
|
36
|
+
# == Create primary IP
|
37
|
+
#
|
38
|
+
# primary IP = HCloud::PrimaryIP.new(name: "my_primary_ip", type: "ipv4", datacenter: "fsn1-dc8")
|
39
|
+
# primary IP.create
|
40
|
+
# primary IP.created?
|
41
|
+
# # => true
|
42
|
+
#
|
43
|
+
# firewall = HCloud::PrimaryIP.create(name: "my_primary_ip")
|
44
|
+
# # => #<HCloud::PrimaryIP id: 1, ...>
|
45
|
+
#
|
46
|
+
# == Update primary IP
|
47
|
+
#
|
48
|
+
# primary IP = HCloud::PrimaryIP.find(1)
|
49
|
+
# primary IP.name = "another_primary_ip"
|
50
|
+
# primary IP.update
|
51
|
+
#
|
52
|
+
# == Delete primary IP
|
53
|
+
#
|
54
|
+
# primary IP = HCloud::PrimaryIP.find(1)
|
55
|
+
# primary IP.delete
|
56
|
+
# primary IP.deleted?
|
57
|
+
# # => true
|
58
|
+
#
|
59
|
+
# = Actions
|
60
|
+
# == List actions
|
61
|
+
#
|
62
|
+
# actions = HCloud::PrimaryIP.find(1).actions
|
63
|
+
# # => [#<HCloud::Action id: 1, ...>, ...]
|
64
|
+
#
|
65
|
+
# == Sort actions
|
66
|
+
#
|
67
|
+
# HCloud::PrimaryIP.find(1).actions.sort(finished: :desc)
|
68
|
+
# # => [#<HCloud::Action id: 1, ...>, ...]
|
69
|
+
#
|
70
|
+
# HCloud::PrimaryIP.find(1).actions.sort(:command, finished: :asc)
|
71
|
+
# # => [#<HCloud::Actions id: 1, ...>, ...]
|
72
|
+
#
|
73
|
+
# == Search actions
|
74
|
+
#
|
75
|
+
# HCloud::PrimaryIP.find(1).actions.where(command: "assign_primary_ip")
|
76
|
+
# # => #<HCloud::Action id: 1, ...>
|
77
|
+
#
|
78
|
+
# HCloud::PrimaryIP.find(1).actions.where(status: "success")
|
79
|
+
# # => #<HCloud::Action id: 1, ...>
|
80
|
+
#
|
81
|
+
# == Find action by ID
|
82
|
+
#
|
83
|
+
# HCloud::PrimaryIP.find(1).actions.find(1)
|
84
|
+
# # => #<HCloud::Action id: 1, ...>
|
85
|
+
#
|
86
|
+
# = Resource-specific actions
|
87
|
+
# == Assign a primary IP to a server
|
88
|
+
#
|
89
|
+
# HCloud::PrimaryIP.find(1).assign(assignee_id: 1, assignee_type: "server")
|
90
|
+
# # => #<HCloud::Action id: 1, ...>
|
91
|
+
#
|
92
|
+
# == Unassign a primary IP from a server
|
93
|
+
#
|
94
|
+
# HCloud::PrimaryIP.find(1).unassign
|
95
|
+
# # => #<HCloud::Action id: 1, ...>
|
96
|
+
#
|
97
|
+
# == Change reverse DNS entry
|
98
|
+
#
|
99
|
+
# HCloud::PrimaryIP.find(1).change_dns_ptr(dns_ptr: "server.example.com", ip: "1.2.3.4")
|
100
|
+
# # => #<HCloud::Action id: 1, ...>
|
101
|
+
#
|
102
|
+
# == Change protection
|
103
|
+
#
|
104
|
+
# HCloud::PrimaryIP.find(1).change_protection(delete: true)
|
105
|
+
# # => #<HCloud::Action id: 1, ...>
|
106
|
+
#
|
107
|
+
class PrimaryIP < Resource
|
108
|
+
actionable
|
109
|
+
queryable
|
110
|
+
creatable
|
111
|
+
updatable
|
112
|
+
deletable
|
113
|
+
labelable
|
114
|
+
|
115
|
+
attribute :id, :integer
|
116
|
+
attribute :name
|
117
|
+
|
118
|
+
attribute :type
|
119
|
+
attribute :ip
|
120
|
+
attribute :dns_ptr, :dns_pointer, array: true, default: -> { [] }
|
121
|
+
|
122
|
+
attribute :assignee_id
|
123
|
+
attribute :assignee_type, default: "server"
|
124
|
+
|
125
|
+
attribute :auto_delete, :boolean
|
126
|
+
attribute :blocked, :boolean
|
127
|
+
|
128
|
+
attribute :datacenter, :datacenter
|
129
|
+
|
130
|
+
attribute :protection, :protection
|
131
|
+
|
132
|
+
alias auto_delete? auto_delete
|
133
|
+
alias blocked? blocked
|
134
|
+
|
135
|
+
action :assign
|
136
|
+
action :unassign
|
137
|
+
|
138
|
+
action :change_dns_ptr
|
139
|
+
|
140
|
+
action :change_protection
|
141
|
+
|
142
|
+
def creatable_attributes
|
143
|
+
[:name, :type, :assignee_id, :assignee_type, :auto_delete, :labels, datacenter: [:id, :name]]
|
144
|
+
end
|
145
|
+
|
146
|
+
def updatable_attributes
|
147
|
+
[:name, :auto_delete, :labels]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -11,18 +11,21 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort servers
|
13
13
|
#
|
14
|
-
# HCloud::Server.
|
14
|
+
# HCloud::Server.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::Server id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::Server.
|
17
|
+
# HCloud::Server.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::Server id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search servers
|
21
21
|
#
|
22
|
-
# HCloud::Server.
|
22
|
+
# HCloud::Server.where(name: "my_server")
|
23
23
|
# # => #<HCloud::Server id: 1, ...>
|
24
24
|
#
|
25
|
-
# HCloud::Server.
|
25
|
+
# HCloud::Server.where(status: "running")
|
26
|
+
# # => #<HCloud::Server id: 1, ...>
|
27
|
+
#
|
28
|
+
# HCloud::Server.where(label_selector: { environment: "production" })
|
26
29
|
# # => #<HCloud::Server id: 1, ...>
|
27
30
|
#
|
28
31
|
# == Find server by ID
|
@@ -72,6 +75,7 @@ module HCloud
|
|
72
75
|
updatable
|
73
76
|
deletable
|
74
77
|
meterable
|
78
|
+
labelable
|
75
79
|
|
76
80
|
attribute :id, :integer
|
77
81
|
attribute :name
|
@@ -107,7 +111,7 @@ module HCloud
|
|
107
111
|
|
108
112
|
attribute :primary_disk_size, :integer
|
109
113
|
|
110
|
-
attribute :protection, :
|
114
|
+
attribute :protection, :server_protection
|
111
115
|
|
112
116
|
attribute :image, :image
|
113
117
|
|
@@ -118,8 +122,6 @@ module HCloud
|
|
118
122
|
|
119
123
|
attribute :iso, :iso
|
120
124
|
|
121
|
-
attribute :labels, default: -> { {} }
|
122
|
-
|
123
125
|
attribute :load_balancers, :load_balancer, array: true, default: -> { [] }
|
124
126
|
|
125
127
|
attribute :volumes, :volume, array: true, default: -> { [] }
|
@@ -11,18 +11,21 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort SSH keys
|
13
13
|
#
|
14
|
-
# HCloud::SSHKey.
|
14
|
+
# HCloud::SSHKey.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::SSHKey id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::SSHKey.
|
17
|
+
# HCloud::SSHKey.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::SSHKey id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search SSH keys
|
21
21
|
#
|
22
|
-
# HCloud::SSHKey.
|
22
|
+
# HCloud::SSHKey.where(name: "cx11")
|
23
23
|
# # => #<HCloud::SSHKey id: 1, ...>
|
24
24
|
#
|
25
|
-
# HCloud::SSHKey.
|
25
|
+
# HCloud::SSHKey.where(fingerprint: "B6:6C:CD:DA:A2:24:43:39:98:80:0F:F5:51:17:7E")
|
26
|
+
# # => #<HCloud::SSHKey id: 1, ...>
|
27
|
+
#
|
28
|
+
# HCloud::SSHKey.where(label_selector: { environment: "production" })
|
26
29
|
# # => #<HCloud::SSHKey id: 1, ...>
|
27
30
|
#
|
28
31
|
# == Find SSH key by ID
|
@@ -58,14 +61,13 @@ module HCloud
|
|
58
61
|
creatable
|
59
62
|
updatable
|
60
63
|
deletable
|
64
|
+
labelable
|
61
65
|
|
62
66
|
attribute :id, :integer
|
63
67
|
attribute :name
|
64
68
|
attribute :public_key
|
65
69
|
attribute :fingerprint
|
66
70
|
|
67
|
-
attribute :labels, default: -> { {} }
|
68
|
-
|
69
71
|
def creatable_attributes
|
70
72
|
[:name, :public_key, :labels]
|
71
73
|
end
|
@@ -11,18 +11,21 @@ module HCloud
|
|
11
11
|
#
|
12
12
|
# == Sort volumes
|
13
13
|
#
|
14
|
-
# HCloud::Volume.
|
14
|
+
# HCloud::Volume.sort(name: :desc)
|
15
15
|
# # => [#<HCloud::Volume id: 1, ...>, ...]
|
16
16
|
#
|
17
|
-
# HCloud::Volume.
|
17
|
+
# HCloud::Volume.sort(:id, name: :asc)
|
18
18
|
# # => [#<HCloud::Volume id: 1, ...>, ...]
|
19
19
|
#
|
20
20
|
# == Search volumes
|
21
21
|
#
|
22
|
-
# HCloud::Volume.
|
22
|
+
# HCloud::Volume.where(name: "my_volume")
|
23
23
|
# # => #<HCloud::Volume id: 1, ...>
|
24
24
|
#
|
25
|
-
# HCloud::Volume.
|
25
|
+
# HCloud::Volume.where(status: "available")
|
26
|
+
# # => #<HCloud::Volume id: 1, ...>
|
27
|
+
#
|
28
|
+
# HCloud::Volume.where(label_selector: { environment: "production" })
|
26
29
|
# # => #<HCloud::Volume id: 1, ...>
|
27
30
|
#
|
28
31
|
# == Find volume by ID
|
@@ -107,6 +110,7 @@ module HCloud
|
|
107
110
|
creatable
|
108
111
|
updatable
|
109
112
|
deletable
|
113
|
+
labelable
|
110
114
|
|
111
115
|
attribute :id, :integer
|
112
116
|
attribute :name
|
@@ -124,8 +128,6 @@ module HCloud
|
|
124
128
|
|
125
129
|
attribute :server, :server
|
126
130
|
|
127
|
-
attribute :labels, default: -> { {} }
|
128
|
-
|
129
131
|
alias automount? automount
|
130
132
|
|
131
133
|
action :attach
|
data/lib/hcloud/version.rb
CHANGED
data/lib/hcloud.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module HTTP
|
6
|
+
module MimeType
|
7
|
+
class YAML < Adapter
|
8
|
+
def encode(obj)
|
9
|
+
return obj.to_yaml if obj.respond_to?(:to_yaml)
|
10
|
+
|
11
|
+
::YAML.dump(obj)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Decodes JSON
|
15
|
+
def decode(str)
|
16
|
+
::YAML.safe_load(str)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
HTTP::MimeType.register_adapter "application/x-yaml", HTTP::MimeType::YAML
|
23
|
+
HTTP::MimeType.register_alias "application/x-yaml", :yaml
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HTTP
|
4
|
+
class RateLimiter < Feature
|
5
|
+
attr_reader :limit, :remaining, :reset, :at, :rate
|
6
|
+
|
7
|
+
def initialize(...)
|
8
|
+
super
|
9
|
+
|
10
|
+
@limit = Float::INFINITY
|
11
|
+
@remaining = Float::INFINITY
|
12
|
+
@reset = Time.at(0)
|
13
|
+
@at = Time.at(0)
|
14
|
+
@rate = 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def wrap_request(request)
|
18
|
+
sleep rate while remaining.zero? && (at + rate).future?
|
19
|
+
|
20
|
+
request
|
21
|
+
end
|
22
|
+
|
23
|
+
def wrap_response(response)
|
24
|
+
# Extract rate limits
|
25
|
+
@limit = response["RateLimit-Limit"].to_i
|
26
|
+
@remaining = response["RateLimit-Remaining"].to_i
|
27
|
+
@reset = Time.at(response["RateLimit-Reset"].to_i)
|
28
|
+
|
29
|
+
# Extract request date
|
30
|
+
@at = Time.parse(response.headers["Date"])
|
31
|
+
|
32
|
+
# Calculate remaining increment rate
|
33
|
+
@rate = 3600 / limit
|
34
|
+
|
35
|
+
response
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
HTTP::Options.register_feature(:rate_limiter, HTTP::RateLimiter)
|