hcloud 1.0.3 → 1.2.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 +58 -0
- data/Gemfile.lock +56 -63
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/bin/console +4 -4
- data/hcloud.gemspec +1 -3
- data/lib/hcloud/certificate.rb +22 -0
- data/lib/hcloud/certificate_resource.rb +43 -0
- data/lib/hcloud/client.rb +24 -0
- data/lib/hcloud/entry_loader.rb +82 -13
- data/lib/hcloud/errors.rb +1 -1
- data/lib/hcloud/firewall.rb +37 -0
- data/lib/hcloud/firewall_resource.rb +30 -0
- data/lib/hcloud/floating_ip.rb +4 -0
- data/lib/hcloud/floating_ip_resource.rb +7 -2
- data/lib/hcloud/future.rb +26 -0
- data/lib/hcloud/image_resource.rb +1 -1
- data/lib/hcloud/load_balancer.rb +140 -0
- data/lib/hcloud/load_balancer_resource.rb +39 -0
- data/lib/hcloud/load_balancer_type.rb +13 -0
- data/lib/hcloud/load_balancer_type_resource.rb +16 -0
- data/lib/hcloud/network.rb +13 -2
- data/lib/hcloud/network_resource.rb +5 -2
- data/lib/hcloud/placement_group.rb +16 -0
- data/lib/hcloud/placement_group_resource.rb +30 -0
- data/lib/hcloud/primary_ip.rb +35 -0
- data/lib/hcloud/primary_ip_resource.rb +46 -0
- data/lib/hcloud/server.rb +16 -2
- data/lib/hcloud/server_resource.rb +7 -3
- data/lib/hcloud/ssh_key.rb +4 -0
- data/lib/hcloud/ssh_key_resource.rb +8 -2
- data/lib/hcloud/typhoeus_ext.rb +2 -2
- data/lib/hcloud/version.rb +1 -1
- data/lib/hcloud/volume.rb +5 -1
- data/lib/hcloud/volume_resource.rb +8 -2
- data/lib/hcloud.rb +20 -0
- metadata +19 -47
- data/Rakefile +0 -4
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hcloud
|
4
|
+
class FirewallResource < AbstractResource
|
5
|
+
filter_attributes :name, :label_selector
|
6
|
+
|
7
|
+
def [](arg)
|
8
|
+
case arg
|
9
|
+
when Integer then find_by(id: arg)
|
10
|
+
when String then find_by(name: arg)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(name:, rules: [], apply_to: [], labels: {})
|
15
|
+
raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
|
16
|
+
|
17
|
+
prepare_request(
|
18
|
+
'firewalls', j: COLLECT_ARGS.call(__method__, binding),
|
19
|
+
expected_code: 201
|
20
|
+
) do |response|
|
21
|
+
[
|
22
|
+
response.parsed_json[:actions].map do |action|
|
23
|
+
Action.new(client, action)
|
24
|
+
end,
|
25
|
+
Firewall.new(client, response.parsed_json[:firewall])
|
26
|
+
]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/hcloud/floating_ip.rb
CHANGED
@@ -18,6 +18,8 @@ module Hcloud
|
|
18
18
|
has_actions
|
19
19
|
|
20
20
|
def assign(server:)
|
21
|
+
raise Hcloud::Error::InvalidInput, 'no server given' if server.nil?
|
22
|
+
|
21
23
|
prepare_request('actions/assign', j: COLLECT_ARGS.call(__method__, binding))
|
22
24
|
end
|
23
25
|
|
@@ -26,6 +28,8 @@ module Hcloud
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def change_dns_ptr(ip:, dns_ptr:)
|
31
|
+
raise Hcloud::Error::InvalidInput, 'no IP given' if ip.blank?
|
32
|
+
|
29
33
|
prepare_request('actions/change_dns_ptr', j: COLLECT_ARGS.call(__method__, binding))
|
30
34
|
end
|
31
35
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Hcloud
|
4
4
|
class FloatingIPResource < AbstractResource
|
5
|
-
filter_attributes :name
|
5
|
+
filter_attributes :name, :label_selector
|
6
6
|
|
7
7
|
bind_to FloatingIP
|
8
8
|
|
@@ -13,7 +13,12 @@ module Hcloud
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def create(type:, server: nil, home_location: nil, description: nil)
|
16
|
+
def create(type:, server: nil, home_location: nil, description: nil, labels: {})
|
17
|
+
raise Hcloud::Error::InvalidInput, 'no type given' if type.blank?
|
18
|
+
if server.nil? && home_location.nil?
|
19
|
+
raise Hcloud::Error::InvalidInput, 'either server or home_location must be given'
|
20
|
+
end
|
21
|
+
|
17
22
|
prepare_request(
|
18
23
|
'floating_ips', j: COLLECT_ARGS.call(__method__, binding),
|
19
24
|
expected_code: 201
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
|
5
|
+
module Hcloud
|
6
|
+
class Future < Delegator
|
7
|
+
# rubocop: disable Lint/MissingSuper
|
8
|
+
def initialize(client, target_class, id)
|
9
|
+
@target_class = target_class
|
10
|
+
@id = id
|
11
|
+
@__client = client
|
12
|
+
end
|
13
|
+
# rubocop: enable Lint/MissingSuper
|
14
|
+
|
15
|
+
def __getobj__
|
16
|
+
# pluralize class name and convert it to symbol
|
17
|
+
@__getobj__ ||= @__client.public_send(
|
18
|
+
@target_class.name # full name of the class including namespaces
|
19
|
+
.demodulize # last module name only
|
20
|
+
.tableize # convert to table name, split words by _ + downcase
|
21
|
+
.pluralize
|
22
|
+
.to_sym
|
23
|
+
).find(@id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/keys'
|
4
|
+
|
5
|
+
module Hcloud
|
6
|
+
class LoadBalancer
|
7
|
+
require 'hcloud/load_balancer_resource'
|
8
|
+
|
9
|
+
include EntryLoader
|
10
|
+
|
11
|
+
schema(
|
12
|
+
location: Location,
|
13
|
+
load_balancer_type: LoadBalancerType,
|
14
|
+
created: :time
|
15
|
+
)
|
16
|
+
|
17
|
+
protectable :delete
|
18
|
+
updatable :name
|
19
|
+
destructible
|
20
|
+
|
21
|
+
has_metrics
|
22
|
+
has_actions
|
23
|
+
|
24
|
+
%w[enable_public_interface disable_public_interface].each do |action|
|
25
|
+
define_method(action) do
|
26
|
+
prepare_request("actions/#{action}", method: :post)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def attach_to_network(network:, ip: nil)
|
31
|
+
raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?
|
32
|
+
|
33
|
+
prepare_request('actions/attach_to_network', j: COLLECT_ARGS.call(__method__, binding))
|
34
|
+
end
|
35
|
+
|
36
|
+
def detach_from_network(network:)
|
37
|
+
raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?
|
38
|
+
|
39
|
+
prepare_request('actions/detach_from_network', j: COLLECT_ARGS.call(__method__, binding))
|
40
|
+
end
|
41
|
+
|
42
|
+
def change_dns_ptr(ip:, dns_ptr:)
|
43
|
+
raise Hcloud::Error::InvalidInput, 'no IP given' if ip.blank?
|
44
|
+
raise Hcloud::Error::InvalidInput, 'no dns_ptr given' if dns_ptr.blank?
|
45
|
+
|
46
|
+
prepare_request('actions/change_dns_ptr', j: COLLECT_ARGS.call(__method__, binding))
|
47
|
+
end
|
48
|
+
|
49
|
+
def change_type(load_balancer_type:)
|
50
|
+
raise Hcloud::Error::InvalidInput, 'no type given' if load_balancer_type.blank?
|
51
|
+
|
52
|
+
prepare_request('actions/change_type', j: COLLECT_ARGS.call(__method__, binding))
|
53
|
+
end
|
54
|
+
|
55
|
+
def change_algorithm(type:)
|
56
|
+
raise Hcloud::Error::InvalidInput, 'no type given' if type.blank?
|
57
|
+
|
58
|
+
prepare_request('actions/change_algorithm', j: COLLECT_ARGS.call(__method__, binding))
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_service(
|
62
|
+
protocol:, listen_port:, destination_port:, health_check:, proxyprotocol:, http: nil
|
63
|
+
)
|
64
|
+
validate_service_input(
|
65
|
+
protocol: protocol,
|
66
|
+
listen_port: listen_port,
|
67
|
+
destination_port: destination_port,
|
68
|
+
health_check: health_check,
|
69
|
+
proxyprotocol: proxyprotocol
|
70
|
+
)
|
71
|
+
|
72
|
+
prepare_request('actions/add_service', j: COLLECT_ARGS.call(__method__, binding))
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_service(
|
76
|
+
protocol:, listen_port:, destination_port:, health_check:, proxyprotocol:, http: nil
|
77
|
+
)
|
78
|
+
validate_service_input(
|
79
|
+
protocol: protocol,
|
80
|
+
listen_port: listen_port,
|
81
|
+
destination_port: destination_port,
|
82
|
+
health_check: health_check,
|
83
|
+
proxyprotocol: proxyprotocol
|
84
|
+
)
|
85
|
+
|
86
|
+
prepare_request('actions/update_service', j: COLLECT_ARGS.call(__method__, binding))
|
87
|
+
end
|
88
|
+
|
89
|
+
def delete_service(listen_port:)
|
90
|
+
raise Hcloud::Error::InvalidInput, 'no listen_port given' if listen_port.nil?
|
91
|
+
|
92
|
+
prepare_request('actions/delete_service', j: COLLECT_ARGS.call(__method__, binding))
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_target(type:, server: nil, label_selector: nil, ip: nil, use_private_ip: false)
|
96
|
+
validate_target_input(
|
97
|
+
type: type, server: server, label_selector: label_selector, ip: ip
|
98
|
+
)
|
99
|
+
|
100
|
+
prepare_request('actions/add_target', j: COLLECT_ARGS.call(__method__, binding))
|
101
|
+
end
|
102
|
+
|
103
|
+
def remove_target(type:, server: nil, label_selector: nil, ip: nil)
|
104
|
+
validate_target_input(
|
105
|
+
type: type, server: server, label_selector: label_selector, ip: ip
|
106
|
+
)
|
107
|
+
|
108
|
+
prepare_request('actions/remove_target', j: COLLECT_ARGS.call(__method__, binding))
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def validate_service_input(
|
114
|
+
protocol:, listen_port:, destination_port:, health_check:, proxyprotocol:
|
115
|
+
)
|
116
|
+
raise Hcloud::Error::InvalidInput, 'no protocol given' if protocol.blank?
|
117
|
+
raise Hcloud::Error::InvalidInput, 'no listen_port given' if listen_port.nil?
|
118
|
+
raise Hcloud::Error::InvalidInput, 'no destination_port given' if destination_port.nil?
|
119
|
+
raise Hcloud::Error::InvalidInput, 'no health_check given' if health_check.nil?
|
120
|
+
raise Hcloud::Error::InvalidInput, 'no proxyprotocol given' if proxyprotocol.nil?
|
121
|
+
end
|
122
|
+
|
123
|
+
def validate_target_input(type:, server: nil, label_selector: nil, ip: nil)
|
124
|
+
raise Hcloud::Error::InvalidInput, 'no type given' if type.nil?
|
125
|
+
|
126
|
+
case type.to_sym
|
127
|
+
when :server
|
128
|
+
raise Hcloud::Error::InvalidInput, 'invalid server given' unless server.to_h.key?(:id)
|
129
|
+
when :ip
|
130
|
+
raise Hcloud::Error::InvalidInput, 'no IP given' if ip.blank?
|
131
|
+
when :label_selector
|
132
|
+
unless label_selector.to_h.key?(:selector)
|
133
|
+
raise Hcloud::Error::InvalidInput, 'invalid label_selector given'
|
134
|
+
end
|
135
|
+
else
|
136
|
+
raise Hcloud::Error::InvalidInput, 'invalid type given'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hcloud
|
4
|
+
class LoadBalancerResource < AbstractResource
|
5
|
+
filter_attributes :name, :label_selector
|
6
|
+
|
7
|
+
bind_to LoadBalancer
|
8
|
+
|
9
|
+
def [](arg)
|
10
|
+
case arg
|
11
|
+
when Integer then find_by(id: arg)
|
12
|
+
when String then find_by(name: arg)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(
|
17
|
+
name:, load_balancer_type:, algorithm:, location: nil, network_zone: nil,
|
18
|
+
network: nil, public_interface: nil, services: nil, targets: nil,
|
19
|
+
labels: {}
|
20
|
+
)
|
21
|
+
raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
|
22
|
+
raise Hcloud::Error::InvalidInput, 'no type given' if load_balancer_type.blank?
|
23
|
+
if !algorithm.to_h.key?(:type) || algorithm[:type].blank?
|
24
|
+
raise Hcloud::Error::InvalidInput, 'invalid algorithm given'
|
25
|
+
end
|
26
|
+
if location.blank? && network_zone.blank?
|
27
|
+
raise Hcloud::Error::InvalidInput, 'either location or network_zone must be given'
|
28
|
+
end
|
29
|
+
|
30
|
+
prepare_request(
|
31
|
+
'load_balancers', j: COLLECT_ARGS.call(__method__, binding),
|
32
|
+
expected_code: 201
|
33
|
+
) do |response|
|
34
|
+
action = Action.new(client, response[:action]) if response[:action]
|
35
|
+
[action, LoadBalancer.new(client, response[:load_balancer])]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hcloud
|
4
|
+
class LoadBalancerTypeResource < AbstractResource
|
5
|
+
filter_attributes :name
|
6
|
+
|
7
|
+
bind_to LoadBalancerType
|
8
|
+
|
9
|
+
def [](arg)
|
10
|
+
case arg
|
11
|
+
when Integer then find_by(id: arg)
|
12
|
+
when String then find_by(name: arg)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/hcloud/network.rb
CHANGED
@@ -15,19 +15,30 @@ module Hcloud
|
|
15
15
|
has_actions
|
16
16
|
|
17
17
|
def add_subnet(type:, network_zone:, ip_range: nil)
|
18
|
+
raise Hcloud::Error::InvalidInput, 'no type given' if type.blank?
|
19
|
+
raise Hcloud::Error::InvalidInput, 'no network_zone given' if network_zone.blank?
|
20
|
+
|
18
21
|
prepare_request('actions/add_subnet', j: COLLECT_ARGS.call(__method__, binding))
|
19
22
|
end
|
20
23
|
|
21
24
|
def del_subnet(ip_range:)
|
22
|
-
|
25
|
+
raise Hcloud::Error::InvalidInput, 'no ip_range given' if ip_range.blank?
|
26
|
+
|
27
|
+
prepare_request('actions/delete_subnet', j: COLLECT_ARGS.call(__method__, binding))
|
23
28
|
end
|
24
29
|
|
25
30
|
def add_route(destination:, gateway:)
|
31
|
+
raise Hcloud::Error::InvalidInput, 'no destination given' if destination.blank?
|
32
|
+
raise Hcloud::Error::InvalidInput, 'no gateway given' if gateway.blank?
|
33
|
+
|
26
34
|
prepare_request('actions/add_route', j: COLLECT_ARGS.call(__method__, binding))
|
27
35
|
end
|
28
36
|
|
29
37
|
def del_route(destination:, gateway:)
|
30
|
-
|
38
|
+
raise Hcloud::Error::InvalidInput, 'no destination given' if destination.blank?
|
39
|
+
raise Hcloud::Error::InvalidInput, 'no gateway given' if gateway.blank?
|
40
|
+
|
41
|
+
prepare_request('actions/delete_route', j: COLLECT_ARGS.call(__method__, binding))
|
31
42
|
end
|
32
43
|
end
|
33
44
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Hcloud
|
4
4
|
class NetworkResource < AbstractResource
|
5
|
-
filter_attributes :name
|
5
|
+
filter_attributes :name, :label_selector
|
6
6
|
|
7
7
|
bind_to Network
|
8
8
|
|
@@ -13,7 +13,10 @@ module Hcloud
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def create(name:, ip_range:, subnets: nil, routes: nil)
|
16
|
+
def create(name:, ip_range:, subnets: nil, routes: nil, labels: {})
|
17
|
+
raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
|
18
|
+
raise Hcloud::Error::InvalidInput, 'no IP range given' if ip_range.blank?
|
19
|
+
|
17
20
|
prepare_request(
|
18
21
|
'networks', j: COLLECT_ARGS.call(__method__, binding),
|
19
22
|
expected_code: 201
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hcloud
|
4
|
+
class PlacementGroupResource < AbstractResource
|
5
|
+
filter_attributes :type, :name
|
6
|
+
|
7
|
+
bind_to PlacementGroup
|
8
|
+
|
9
|
+
def [](arg)
|
10
|
+
return find_by(name: arg) if arg.is_a?(String)
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
# currently only spread is available
|
16
|
+
def create(name:, type: 'spread', labels: {})
|
17
|
+
if type.to_s != 'spread'
|
18
|
+
raise Hcloud::Error::InvalidInput, "invalid type #{type.inspect}, only 'spread' is allowed"
|
19
|
+
end
|
20
|
+
raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
|
21
|
+
|
22
|
+
prepare_request(
|
23
|
+
'placement_groups', j: COLLECT_ARGS.call(__method__, binding),
|
24
|
+
expected_code: 201
|
25
|
+
) do |response|
|
26
|
+
PlacementGroup.new(client, response.parsed_json[:placement_group])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hcloud
|
4
|
+
class PrimaryIP
|
5
|
+
require 'hcloud/primary_ip_resource'
|
6
|
+
|
7
|
+
include EntryLoader
|
8
|
+
|
9
|
+
schema(
|
10
|
+
datacenter: Datacenter,
|
11
|
+
created: :time
|
12
|
+
)
|
13
|
+
|
14
|
+
protectable :delete
|
15
|
+
updatable :name, :auto_delete
|
16
|
+
destructible
|
17
|
+
|
18
|
+
def assign(assignee_id:, assignee_type: 'server')
|
19
|
+
raise Hcloud::Error::InvalidInput, 'no assignee_id given' if assignee_id.nil?
|
20
|
+
raise Hcloud::Error::InvalidInput, 'no assignee_type given' if assignee_type.nil?
|
21
|
+
|
22
|
+
prepare_request('actions/assign', j: COLLECT_ARGS.call(__method__, binding))
|
23
|
+
end
|
24
|
+
|
25
|
+
def unassign
|
26
|
+
prepare_request('actions/unassign', method: :post)
|
27
|
+
end
|
28
|
+
|
29
|
+
def change_dns_ptr(ip:, dns_ptr:)
|
30
|
+
raise Hcloud::Error::InvalidInput, 'no IP given' if ip.blank?
|
31
|
+
|
32
|
+
prepare_request('actions/change_dns_ptr', j: { ip: ip, dns_ptr: dns_ptr })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hcloud
|
4
|
+
class PrimaryIPResource < AbstractResource
|
5
|
+
filter_attributes :name, :label_selector, :ip
|
6
|
+
|
7
|
+
bind_to PrimaryIP
|
8
|
+
|
9
|
+
def [](arg)
|
10
|
+
case arg
|
11
|
+
when Integer then find_by(id: arg)
|
12
|
+
when String then find_by(name: arg)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(
|
17
|
+
name:,
|
18
|
+
type:,
|
19
|
+
assignee_id: nil,
|
20
|
+
assignee_type: 'server',
|
21
|
+
datacenter: nil,
|
22
|
+
auto_delete: nil,
|
23
|
+
labels: {}
|
24
|
+
)
|
25
|
+
raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
|
26
|
+
|
27
|
+
unless %w[ipv4 ipv6].include?(type.to_s)
|
28
|
+
raise Hcloud::Error::InvalidInput, 'invalid type given'
|
29
|
+
end
|
30
|
+
|
31
|
+
raise Hcloud::Error::InvalidInput, 'no assignee_type given' if assignee_type.blank?
|
32
|
+
|
33
|
+
if assignee_id.nil? && datacenter.nil?
|
34
|
+
raise Hcloud::Error::InvalidInput, 'either assignee_id or datacenter must be given'
|
35
|
+
end
|
36
|
+
|
37
|
+
prepare_request(
|
38
|
+
'primary_ips', j: COLLECT_ARGS.call(__method__, binding),
|
39
|
+
expected_code: 201
|
40
|
+
) do |response|
|
41
|
+
action = Action.new(client, response[:action]) if response[:action]
|
42
|
+
[action, PrimaryIP.new(client, response[:primary_ip])]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/hcloud/server.rb
CHANGED
@@ -10,7 +10,10 @@ module Hcloud
|
|
10
10
|
created: :time,
|
11
11
|
server_type: ServerType,
|
12
12
|
datacenter: Datacenter,
|
13
|
-
image: Image
|
13
|
+
image: Image,
|
14
|
+
iso: Iso,
|
15
|
+
private_net: [Network],
|
16
|
+
volumes: [Volume]
|
14
17
|
)
|
15
18
|
|
16
19
|
protectable :delete, :rebuild
|
@@ -34,10 +37,15 @@ module Hcloud
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def rebuild(image:)
|
40
|
+
raise Hcloud::Error::InvalidInput, 'no image given' if image.blank?
|
41
|
+
|
37
42
|
prepare_request('actions/rebuild', j: { image: image }) { |j| j[:root_password] }
|
38
43
|
end
|
39
44
|
|
40
|
-
def change_type(server_type:, upgrade_disk:
|
45
|
+
def change_type(server_type:, upgrade_disk:)
|
46
|
+
raise Hcloud::Error::InvalidInput, 'no server_type given' if server_type.blank?
|
47
|
+
raise Hcloud::Error::InvalidInput, 'no upgrade_disk given' if upgrade_disk.nil?
|
48
|
+
|
41
49
|
prepare_request('actions/change_type', j: COLLECT_ARGS.call(__method__, binding))
|
42
50
|
end
|
43
51
|
|
@@ -48,14 +56,20 @@ module Hcloud
|
|
48
56
|
end
|
49
57
|
|
50
58
|
def attach_iso(iso:)
|
59
|
+
raise Hcloud::Error::InvalidInput, 'no iso given' if iso.blank?
|
60
|
+
|
51
61
|
prepare_request('actions/attach_iso', j: { iso: iso })
|
52
62
|
end
|
53
63
|
|
54
64
|
def attach_to_network(network:, ip: nil, alias_ips: nil)
|
65
|
+
raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?
|
66
|
+
|
55
67
|
prepare_request('actions/attach_to_network', j: COLLECT_ARGS.call(__method__, binding))
|
56
68
|
end
|
57
69
|
|
58
70
|
def detach_from_network(network:)
|
71
|
+
raise Hcloud::Error::InvalidInput, 'no network given' if network.nil?
|
72
|
+
|
59
73
|
prepare_request('actions/detach_from_network', j: { network: network })
|
60
74
|
end
|
61
75
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Hcloud
|
4
4
|
class ServerResource < AbstractResource
|
5
|
-
filter_attributes :status, :name
|
5
|
+
filter_attributes :status, :name, :label_selector
|
6
6
|
|
7
7
|
bind_to Server
|
8
8
|
|
@@ -13,13 +13,17 @@ module Hcloud
|
|
13
13
|
start_after_create: nil,
|
14
14
|
ssh_keys: [],
|
15
15
|
networks: [],
|
16
|
-
user_data: nil
|
16
|
+
user_data: nil,
|
17
|
+
labels: {})
|
17
18
|
prepare_request('servers', j: COLLECT_ARGS.call(__method__, binding),
|
18
19
|
expected_code: 201) do |response|
|
19
20
|
[
|
20
21
|
Action.new(client, response.parsed_json[:action]),
|
21
22
|
Server.new(client, response.parsed_json[:server]),
|
22
|
-
response.parsed_json[:root_password]
|
23
|
+
response.parsed_json[:root_password],
|
24
|
+
response.parsed_json[:next_actions].to_a.map do |action|
|
25
|
+
Action.new(client, action)
|
26
|
+
end
|
23
27
|
]
|
24
28
|
end
|
25
29
|
end
|
data/lib/hcloud/ssh_key.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Hcloud
|
4
4
|
class SSHKeyResource < AbstractResource
|
5
|
-
filter_attributes :name
|
5
|
+
filter_attributes :name, :label_selector
|
6
6
|
|
7
7
|
def [](arg)
|
8
8
|
case arg
|
@@ -11,7 +11,13 @@ module Hcloud
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def create(name:, public_key:)
|
14
|
+
def create(name:, public_key:, labels: {})
|
15
|
+
raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
|
16
|
+
|
17
|
+
unless public_key.to_s.starts_with?('ssh')
|
18
|
+
raise Hcloud::Error::InvalidInput, 'no valid SSH key given'
|
19
|
+
end
|
20
|
+
|
15
21
|
prepare_request(
|
16
22
|
'ssh_keys', j: COLLECT_ARGS.call(__method__, binding),
|
17
23
|
expected_code: 201
|
data/lib/hcloud/typhoeus_ext.rb
CHANGED
@@ -30,7 +30,7 @@ module Hcloud
|
|
30
30
|
def parsed_json
|
31
31
|
return {} if code == 204
|
32
32
|
|
33
|
-
@parsed_json ||= Oj.load(body, symbol_keys: true).tap do |json|
|
33
|
+
@parsed_json ||= Oj.load(body, symbol_keys: true, mode: :compat).tap do |json|
|
34
34
|
next unless request.hydra
|
35
35
|
|
36
36
|
check_for_error(
|
@@ -58,7 +58,7 @@ module Hcloud
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def pagination
|
61
|
-
@pagination ||= Pagination.new(parsed_json[:meta].to_h[:pagination])
|
61
|
+
@pagination ||= Pagination.new(nil, parsed_json[:meta].to_h[:pagination])
|
62
62
|
end
|
63
63
|
|
64
64
|
def resource_attributes
|
data/lib/hcloud/version.rb
CHANGED
data/lib/hcloud/volume.rb
CHANGED
@@ -17,7 +17,9 @@ module Hcloud
|
|
17
17
|
|
18
18
|
has_actions
|
19
19
|
|
20
|
-
def attach(server:, automount:)
|
20
|
+
def attach(server:, automount: nil)
|
21
|
+
raise Hcloud::Error::InvalidInput, 'no server given' if server.nil?
|
22
|
+
|
21
23
|
prepare_request('actions/attach', j: COLLECT_ARGS.call(__method__, binding))
|
22
24
|
end
|
23
25
|
|
@@ -26,6 +28,8 @@ module Hcloud
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def resize(size:)
|
31
|
+
raise Hcloud::Error::InvalidInput, 'invalid size given' unless size.to_i > self.size
|
32
|
+
|
29
33
|
prepare_request('actions/resize', j: COLLECT_ARGS.call(__method__, binding))
|
30
34
|
end
|
31
35
|
end
|