hetznercloud 3.0.0 → 4.1.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +105 -6
  3. data/README.md +49 -32
  4. data/lib/hcloud/action_collection.rb +2 -2
  5. data/lib/hcloud/client.rb +28 -2
  6. data/lib/hcloud/collection.rb +10 -2
  7. data/lib/hcloud/concerns/actionable.rb +1 -1
  8. data/lib/hcloud/concerns/creatable.rb +21 -6
  9. data/lib/hcloud/concerns/deletable.rb +8 -3
  10. data/lib/hcloud/concerns/meterable.rb +1 -1
  11. data/lib/hcloud/concerns/queryable.rb +3 -3
  12. data/lib/hcloud/concerns/subresource.rb +62 -0
  13. data/lib/hcloud/concerns/updatable.rb +1 -1
  14. data/lib/hcloud/entities/storage_box_access_settings.rb +17 -0
  15. data/lib/hcloud/entities/storage_box_price.rb +10 -0
  16. data/lib/hcloud/entities/storage_box_snapshot_plan.rb +11 -0
  17. data/lib/hcloud/entities/storage_box_snapshot_stats.rb +8 -0
  18. data/lib/hcloud/entities/storage_box_stats.rb +9 -0
  19. data/lib/hcloud/entities/storage_box_subaccount_access_settings.rb +19 -0
  20. data/lib/hcloud/errors.rb +2 -1
  21. data/lib/hcloud/http.rb +4 -2
  22. data/lib/hcloud/resource.rb +1 -0
  23. data/lib/hcloud/resource_type.rb +10 -0
  24. data/lib/hcloud/resources/certificate.rb +1 -1
  25. data/lib/hcloud/resources/datacenter.rb +1 -1
  26. data/lib/hcloud/resources/firewall.rb +1 -1
  27. data/lib/hcloud/resources/floating_ip.rb +1 -1
  28. data/lib/hcloud/resources/load_balancer.rb +1 -1
  29. data/lib/hcloud/resources/network.rb +1 -1
  30. data/lib/hcloud/resources/placement_group.rb +1 -1
  31. data/lib/hcloud/resources/primary_ip.rb +1 -1
  32. data/lib/hcloud/resources/server.rb +1 -1
  33. data/lib/hcloud/resources/server_type.rb +1 -0
  34. data/lib/hcloud/resources/ssh_key.rb +1 -1
  35. data/lib/hcloud/resources/storage_box.rb +195 -0
  36. data/lib/hcloud/resources/storage_box_snapshot.rb +108 -0
  37. data/lib/hcloud/resources/storage_box_subaccount.rb +129 -0
  38. data/lib/hcloud/resources/storage_box_type.rb +43 -0
  39. data/lib/hcloud/resources/volume.rb +2 -2
  40. data/lib/hcloud/sub_collection.rb +79 -0
  41. data/lib/hcloud/version.rb +2 -2
  42. data/lib/http/features/compression.rb +1 -1
  43. data/lib/http/features/request/brotli_body.rb +1 -1
  44. data/lib/http/features/response/brotli_inflater.rb +1 -1
  45. data/lib/http/rate_limiter.rb +2 -0
  46. metadata +18 -6
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCloud
4
+ class StorageBoxSubaccountAccessSettings < Entity
5
+ attribute :samba_enabled, :boolean
6
+ attribute :ssh_enabled, :boolean
7
+ attribute :webdav_enabled, :boolean
8
+
9
+ attribute :readonly, :boolean
10
+ attribute :reachable_externally, :boolean
11
+
12
+ alias samba_enabled? samba_enabled
13
+ alias ssh_enabled? ssh_enabled
14
+ alias webdav_enabled? webdav_enabled
15
+
16
+ alias readonly? readonly
17
+ alias reachable_externally? reachable_externally
18
+ end
19
+ end
data/lib/hcloud/errors.rb CHANGED
@@ -12,7 +12,7 @@ module HCloud
12
12
  end
13
13
 
14
14
  def full_messages
15
- return unless data[:details]
15
+ return unless data[:details] && data[:details][:fields]
16
16
 
17
17
  data[:details][:fields].flat_map do |field|
18
18
  Array(field.fetch(:messages, data[:message])).map do |detail|
@@ -36,6 +36,7 @@ module HCloud
36
36
  class InvalidInput < Error; end
37
37
  class JSONError < Error; end
38
38
  class LoadBalancerNotAttachedToNetwork < Error; end
39
+ class LoadBalancerPublicInterfaceDisabled < Error; end
39
40
  class Locked < Error; end
40
41
  class Maintenance < Error; end
41
42
  class NetworksOverlap < Error; end
data/lib/hcloud/http.rb CHANGED
@@ -73,14 +73,16 @@ module HCloud
73
73
  response = http
74
74
  .delete(url_for(path))
75
75
 
76
- return if response.status.success?
77
-
78
76
  raise Errors::ServerError, response if response.status.server_error?
79
77
 
78
+ return if response.status.success? && response.body.empty?
79
+
80
80
  data = response
81
81
  .parse(:json)
82
82
  .deep_symbolize_keys
83
83
 
84
+ return data if response.status.success?
85
+
84
86
  raise Errors.const_get(data.dig(:error, :code).camelize), data[:error]
85
87
  end
86
88
 
@@ -7,6 +7,7 @@ module HCloud
7
7
 
8
8
  include Concerns
9
9
  include DynamicAttributes
10
+ include Subresource
10
11
 
11
12
  def initialize(attributes = {})
12
13
  super()
@@ -137,6 +137,16 @@ ActiveModel::Type.register(:server_type_price, HCloud::ResourceType.Type("HCloud
137
137
  ActiveModel::Type.register(:service, HCloud::ResourceType.Type("HCloud::Service"))
138
138
  ActiveModel::Type.register(:service_http, HCloud::ResourceType.Type("HCloud::ServiceHTTP"))
139
139
  ActiveModel::Type.register(:ssh_key, HCloud::ResourceType.Type("HCloud::SSHKey"))
140
+ ActiveModel::Type.register(:storage_box, HCloud::ResourceType.Type("HCloud::StorageBox"))
141
+ ActiveModel::Type.register(:storage_box_access_settings, HCloud::ResourceType.Type("HCloud::StorageBoxAccessSettings"))
142
+ ActiveModel::Type.register(:storage_box_price, HCloud::ResourceType.Type("HCloud::StorageBoxPrice"))
143
+ ActiveModel::Type.register(:storage_box_snapshot_plan, HCloud::ResourceType.Type("HCloud::StorageBoxSnapshotPlan"))
144
+ ActiveModel::Type.register(:storage_box_stats, HCloud::ResourceType.Type("HCloud::StorageBoxStats"))
145
+ ActiveModel::Type.register(:storage_box_type, HCloud::ResourceType.Type("HCloud::StorageBoxType"))
146
+ ActiveModel::Type.register(:storage_box_snapshot, HCloud::ResourceType.Type("HCloud::StorageBoxSnapshot"))
147
+ ActiveModel::Type.register(:storage_box_snapshot_stats, HCloud::ResourceType.Type("HCloud::StorageBoxSnapshotStats"))
148
+ ActiveModel::Type.register(:storage_box_subaccount, HCloud::ResourceType.Type("HCloud::StorageBoxSubaccount"))
149
+ ActiveModel::Type.register(:storage_box_subaccount_access_settings, HCloud::ResourceType.Type("HCloud::StorageBoxSubaccountAccessSettings"))
140
150
  ActiveModel::Type.register(:subnet, HCloud::ResourceType.Type("HCloud::Subnet"))
141
151
  ActiveModel::Type.register(:target, HCloud::ResourceType.Type("HCloud::Target"))
142
152
  ActiveModel::Type.register(:targets, HCloud::ResourceType.Type("HCloud::Targets"))
@@ -25,7 +25,7 @@ module HCloud
25
25
  # HCloud::Certificate.where(type: "uploaded")
26
26
  # # => #<HCloud::Certificate id: 1, ...>
27
27
  #
28
- # HCloud::Certificate.where(label_selector: { environment: "production" })
28
+ # HCloud::Certificate.where(label_selector: "environment=production")
29
29
  # # => #<HCloud::Certificate id: 1, ...>
30
30
  #
31
31
  # == Find certificate by ID
@@ -44,7 +44,7 @@ module HCloud
44
44
 
45
45
  def self.recommendation
46
46
  find client
47
- .get("/#{resource_name.pluralize}")
47
+ .get(resource_path)
48
48
  .fetch(:recommendation)
49
49
  end
50
50
  end
@@ -22,7 +22,7 @@ module HCloud
22
22
  # HCloud::Firewall.where(name: "my_firewall")
23
23
  # # => #<HCloud::Firewall id: 1, ...>
24
24
  #
25
- # HCloud::Firewall.where(label_selector: { environment: "production" })
25
+ # HCloud::Firewall.where(label_selector: "environment=production")
26
26
  # # => #<HCloud::Firewall id: 1, ...>
27
27
  #
28
28
  # == Find firewall by ID
@@ -22,7 +22,7 @@ module HCloud
22
22
  # HCloud::FloatingIP.where(name: "my_floating_ip")
23
23
  # # => #<HCloud::FloatingIP id: 1, ...>
24
24
  #
25
- # HCloud::FloatingIP.where(label_selector: { environment: "production" })
25
+ # HCloud::FloatingIP.where(label_selector: "environment=production")
26
26
  # # => #<HCloud::FloatingIP id: 1, ...>
27
27
  #
28
28
  # == Find floating IP by ID
@@ -22,7 +22,7 @@ module HCloud
22
22
  # HCloud::LoadBalancer.where(name: "my_load_balancer")
23
23
  # # => #<HCloud::LoadBalancer id: 1, ...>
24
24
  #
25
- # HCloud::LoadBalancer.where(label_selector: { environment: "production" })
25
+ # HCloud::LoadBalancer.where(label_selector: "environment=production")
26
26
  # # => #<HCloud::LoadBalancer id: 1, ...>
27
27
  #
28
28
  # == Find load balancer by ID
@@ -14,7 +14,7 @@ module HCloud
14
14
  # HCloud::Network.where(name: "my_network")
15
15
  # # => #<HCloud::Network id: 1, ...>
16
16
  #
17
- # HCloud::Network.where(label_selector: { environment: "production" })
17
+ # HCloud::Network.where(label_selector: "environment=production")
18
18
  # # => #<HCloud::Network id: 1, ...>
19
19
  #
20
20
  # == Find network by ID
@@ -22,7 +22,7 @@ module HCloud
22
22
  # HCloud::PlacementGroup.where(name: "my_placement_group")
23
23
  # # => #<HCloud::PlacementGroup id: 2, ...>
24
24
  #
25
- # HCloud::PlacementGroup.where(label_selector: { environment: "production" })
25
+ # HCloud::PlacementGroup.where(label_selector: "environment=production")
26
26
  # # => #<HCloud::PlacementGroup id: 2, ...>
27
27
  #
28
28
  # == Find placement group by ID
@@ -25,7 +25,7 @@ module HCloud
25
25
  # HCloud::PrimaryIP.where(ip: "1.2.3.4")
26
26
  # # => #<HCloud::PrimaryIP id: 1, ...>
27
27
  #
28
- # HCloud::PrimaryIP.where(label_selector: { environment: "production" })
28
+ # HCloud::PrimaryIP.where(label_selector: "environment=production")
29
29
  # # => #<HCloud::PrimaryIP id: 1, ...>
30
30
  #
31
31
  # == Find primary IP by ID
@@ -25,7 +25,7 @@ module HCloud
25
25
  # HCloud::Server.where(status: "running")
26
26
  # # => #<HCloud::Server id: 1, ...>
27
27
  #
28
- # HCloud::Server.where(label_selector: { environment: "production" })
28
+ # HCloud::Server.where(label_selector: "environment=production")
29
29
  # # => #<HCloud::Server id: 1, ...>
30
30
  #
31
31
  # == Find server by ID
@@ -25,6 +25,7 @@ module HCloud
25
25
  attribute :id, :integer
26
26
  attribute :name
27
27
  attribute :description
28
+ attribute :category
28
29
 
29
30
  attribute :architecture
30
31
  attribute :cores, :integer
@@ -25,7 +25,7 @@ module HCloud
25
25
  # HCloud::SSHKey.where(fingerprint: "B6:6C:CD:DA:A2:24:43:39:98:80:0F:F5:51:17:7E")
26
26
  # # => #<HCloud::SSHKey id: 1, ...>
27
27
  #
28
- # HCloud::SSHKey.where(label_selector: { environment: "production" })
28
+ # HCloud::SSHKey.where(label_selector: "environment=production")
29
29
  # # => #<HCloud::SSHKey id: 1, ...>
30
30
  #
31
31
  # == Find SSH key by ID
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCloud
4
+ ##
5
+ # Represents a storage box
6
+ #
7
+ # == List all storage boxes
8
+ #
9
+ # HCloud::StorageBox.all
10
+ # # => [#<HCloud::StorageBox id: 1, ...>, ...]
11
+ #
12
+ # == Search storage boxes
13
+ #
14
+ # HCloud::StorageBox.where(name: "my_storage_box")
15
+ # # => #<HCloud::StorageBox id: 1, ...>
16
+ #
17
+ # HCloud::StorageBox.where(label_selector: "environment=production")
18
+ # # => #<HCloud::StorageBox id: 1, ...>
19
+ #
20
+ # == Find storage box by ID
21
+ #
22
+ # HCloud::StorageBox.find(1)
23
+ # # => #<HCloud::StorageBox id: 1, ...>
24
+ #
25
+ # == Create storage box
26
+ #
27
+ # storage_box = HCloud::StorageBox.new(name: "my_storage_box", storage_box_type: "bx20", location: "fsn1", password: "my_password")
28
+ # storage_box.create
29
+ # storage_box.created?
30
+ # # => true
31
+ #
32
+ # storage_box = HCloud::StorageBox.create(name: "my_storage_box", storage_box_type: "bx20", location: "fsn1", password: "my_password")
33
+ # # => #<HCloud::Action id: 1, ...>
34
+ #
35
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself
36
+ #
37
+ # == Update storage box
38
+ #
39
+ # storage_box = HCloud::StorageBox.find(1)
40
+ # storage_box.name = "another_storage_box"
41
+ # storage_box.update
42
+ #
43
+ # == Delete storage box
44
+ #
45
+ # storage_box = HCloud::StorageBox.find(1)
46
+ # storage_box.delete
47
+ # # => #<HCloud::Action id: 1, ...>
48
+ #
49
+ # storage_box.deleted?
50
+ # # => true
51
+ #
52
+ # Note: this method returns a {HCloud::Action} instance rather than the deleted resource itself
53
+ #
54
+ # == List storage box contents
55
+ #
56
+ # storage_box = HCloud::StorageBox.find(1)
57
+ # storage_box.contents
58
+ # # => ["photos", "documents", ...]
59
+ #
60
+ # storage_box = HCloud::StorageBox.find(1)
61
+ # storage_box.contents(folder: "photos")
62
+ # # => ["photo1.jpg", "photo2.jpg", ...]
63
+ #
64
+ # = Actions
65
+ # == List actions
66
+ #
67
+ # actions = HCloud::StorageBox.find(1).actions
68
+ # # => [#<HCloud::Action id: 1, ...>, ...]
69
+ #
70
+ # == Sort actions
71
+ #
72
+ # HCloud::StorageBox.find(1).actions.sort(finished: :desc)
73
+ # # => [#<HCloud::Action id: 1, ...>, ...]
74
+ #
75
+ # HCloud::StorageBox.find(1).actions.sort(:command, finished: :asc)
76
+ # # => [#<HCloud::Actions id: 1, ...>, ...]
77
+ #
78
+ # == Search actions
79
+ #
80
+ # HCloud::StorageBox.find(1).actions.where(command: "start_resource")
81
+ # # => #<HCloud::Action id: 1, ...>
82
+ #
83
+ # HCloud::StorageBox.find(1).actions.where(status: "success")
84
+ # # => #<HCloud::Action id: 1, ...>
85
+ #
86
+ # == Find action by ID
87
+ #
88
+ # HCloud::StorageBox.find(1).actions.find(1)
89
+ # # => #<HCloud::Action id: 1, ...>
90
+ #
91
+ # = Resource-specific actions
92
+ # == Change type
93
+ #
94
+ # HCloud::StorageBox.find(1).change_type(storage_box_type: "bx21")
95
+ # # => #<HCloud::Action id: 1, ...>
96
+ #
97
+ # == Reset password
98
+ #
99
+ # HCloud::StorageBox.find(1).reset_password(password: "mypassword")
100
+ # # => #<HCloud::Action id: 1, ...>
101
+ #
102
+ # == Update access settings
103
+ #
104
+ # HCloud::StorageBox.find(1).update_access_settings(samba_enabled: false, ssh_enabled: true, webdav_enabled: false, zfs_enabled: false, reachable_externally: false)
105
+ # # => #<HCloud::Action id: 1, ...>
106
+ #
107
+ # == Enable snapshot plan
108
+ #
109
+ # HCloud::StorageBox.find(1).enable_snapshot_plan(max_snapshots: 10, minute: 30, hour: 3, day_of_week: nil, day_of_month: nil)
110
+ # # => #<HCloud::Action id: 1, ...>
111
+ #
112
+ # == Disable snapshot plan
113
+ #
114
+ # HCloud::StorageBox.find(1).disable_snapshot_plan
115
+ # # => #<HCloud::Action id: 1, ...>
116
+ #
117
+ # == Rollback snapshot
118
+ #
119
+ # HCloud::StorageBox.find(1).rollback_snapshot(snapshot_id: 42)
120
+ # # => #<HCloud::Action id: 1, ...>
121
+ #
122
+ # == Change protection
123
+ #
124
+ # HCloud::StorageBox.find(1).change_protection(delete: true)
125
+ # # => #<HCloud::Action id: 1, ...>
126
+ #
127
+ # = Snapshots
128
+ #
129
+ # See {HCloud::StorageBoxSnapshot} for more information on snapshots.
130
+ #
131
+ # = Subaccounts
132
+ #
133
+ # See {HCloud::StorageBoxSubaccount} for more information on subaccounts.
134
+ #
135
+ class StorageBox < Resource
136
+ actionable
137
+ queryable
138
+ creatable
139
+ updatable
140
+ deletable
141
+ labelable
142
+
143
+ subresource :snapshot, :storage_box_snapshot
144
+ subresource :subaccount, :storage_box_subaccount
145
+
146
+ attribute :id, :integer
147
+ attribute :name
148
+ attribute :location, :location
149
+
150
+ attribute :username
151
+
152
+ attribute :status
153
+
154
+ attribute :storage_box_type, :storage_box_type
155
+ attribute :access_settings, :storage_box_access_settings
156
+
157
+ # String, not a Server resource
158
+ attribute :server
159
+ attribute :system
160
+
161
+ attribute :stats, :storage_box_stats
162
+ attribute :snapshot_plan, :storage_box_snapshot_plan
163
+
164
+ attribute :protection, :protection
165
+
166
+ action :change_type
167
+ action :reset_password
168
+ action :update_access_settings
169
+
170
+ action :enable_snapshot_plan
171
+ action :disable_snapshot_plan
172
+
173
+ action :rollback_snapshot
174
+
175
+ action :change_protection
176
+
177
+ def contents(path: nil)
178
+ client
179
+ .get("#{resource_path}/#{id}/folders", path: path)
180
+ .fetch(:folders)
181
+ end
182
+
183
+ def creatable_attributes
184
+ [:name, :storage_box_type, :password, :ssh_keys, :location, :labels, access_settings: [:samba_enabled, :ssh_enabled, :webdav_enabled, :zfs_enabled, :reachable_externally]]
185
+ end
186
+
187
+ def updatable_attributes
188
+ [:name, :labels]
189
+ end
190
+
191
+ def self.client
192
+ HCloud::Client.connection.storage_box_client
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCloud
4
+ ##
5
+ # Represents a storage box's snapshot
6
+ #
7
+ # == List all snapshots
8
+ #
9
+ # storage_box = HCloud::StorageBox.find(1)
10
+ # storage_box.snapshots
11
+ # # => [#<HCloud::StorageBox::Snapshot id: 1, ...>, ...]
12
+ #
13
+ # == Search snapshots
14
+ #
15
+ # storage_box = HCloud::StorageBox.find(1)
16
+ # storage_box.snapshots.where(name: "monthly_backup")
17
+ # # => #<HCloud::StorageBox::Snapshot id: 1, ...>
18
+ #
19
+ # storage_box = HCloud::StorageBox.find(1)
20
+ # storage_box.snapshots.where(label_selector: "environment=production")
21
+ # # => #<HCloud::StorageBox::Snapshot id: 1, ...>
22
+ #
23
+ # == Find snapshot by ID
24
+ #
25
+ # storage_box = HCloud::StorageBox.find(1)
26
+ # storage_box.snapshots.find(1)
27
+ # # => #<HCloud::StorageBox::Snapshot id: 1, ...>
28
+ #
29
+ # == Create snapshot
30
+ #
31
+ # storage_box = HCloud::StorageBox.find(1)
32
+ # snapshot = storage_box.snapshots.new(description: "my_snapshot")
33
+ # snapshot.create
34
+ # snapshot.created?
35
+ # # => false
36
+ #
37
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself, as the snapshot is created asynchronously.
38
+ # Reload the snapshot to check if it was created successfully.
39
+ #
40
+ # snapshot.reload
41
+ # snapshot.created?
42
+ # # => true
43
+ #
44
+ # snapshot = storage_box.snapshots.create(description: "my_snapshot")
45
+ # # => #<HCloud::Action id: 1, ...>
46
+ #
47
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself
48
+ #
49
+ # snapshot = HCloud::StorageBox::Snapshot.create(storage_box: 1, description: "my_snapshot")
50
+ # # => #<HCloud::Action id: 1, ...>
51
+ #
52
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself
53
+ #
54
+ # == Update snapshot
55
+ #
56
+ # storage_box = HCloud::StorageBox.find(1)
57
+ # snapshot = storage_box.snapshots.find(1)
58
+ # snapshot.description = "another_snapshot"
59
+ # snapshot.update
60
+ #
61
+ # == Delete snapshot
62
+ #
63
+ # storage_box = HCloud::StorageBox.find(1)
64
+ # snapshot = storage_box.snapshots.find(1)
65
+ # snapshot.delete
66
+ # # => #<HCloud::Action id: 1, ...>
67
+ #
68
+ # snapshot.deleted?
69
+ # # => true
70
+ #
71
+ # Note: this method returns a {HCloud::Action} instance rather than the deleted resource itself
72
+ #
73
+ class StorageBoxSnapshot < Resource
74
+ subresource_of :storage_box
75
+
76
+ queryable
77
+ creatable
78
+ updatable
79
+ deletable
80
+ labelable
81
+
82
+ attribute :id, :integer
83
+ attribute :name
84
+ attribute :description
85
+
86
+ attribute :is_automatic, :boolean
87
+
88
+ attribute :stats, :storage_box_snapshot_stats
89
+
90
+ attribute :protection, :protection
91
+
92
+ def creatable_attributes
93
+ [:description]
94
+ end
95
+
96
+ def updatable_attributes
97
+ [:description, :labels]
98
+ end
99
+
100
+ def self.resource_name
101
+ "snapshot"
102
+ end
103
+
104
+ def self.client
105
+ HCloud::Client.connection.storage_box_client
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCloud
4
+ ##
5
+ # Represents a storage box's subaccount
6
+ #
7
+ # == List all subaccounts
8
+ #
9
+ # storage_box = HCloud::StorageBox.find(1)
10
+ # storage_box.subaccounts
11
+ # # => [#<HCloud::StorageBox::Subaccount id: 1, ...>, ...]
12
+ #
13
+ # == Search subaccounts
14
+ #
15
+ # storage_box = HCloud::StorageBox.find(1)
16
+ # storage_box.subaccounts.where(label_selector: "environment=production")
17
+ # # => #<HCloud::StorageBox::Subaccount id: 1, ...>
18
+ #
19
+ # == Find subaccount by ID
20
+ #
21
+ # storage_box = HCloud::StorageBox.find(1)
22
+ # storage_box.subaccounts.find(1)
23
+ # # => #<HCloud::StorageBox::Subaccount id: 1, ...>
24
+ #
25
+ # == Create subaccount
26
+ #
27
+ # storage_box = HCloud::StorageBox.find(1)
28
+ # subaccount = storage_box.subaccounts.new(password: "my_password", description: "my_subaccount", home_directory: "backup/", access_settings: { samba_enabled: false, ssh_enabled: true, webdav_enabled: false, readonly: false, reachable_externally: false })
29
+ # subaccount.create
30
+ # subaccount.created?
31
+ # # => false
32
+ #
33
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself, as the subaccount is created asynchronously.
34
+ # Reload the subaccount to check if it was created successfully.
35
+ #
36
+ # subaccount.reload
37
+ # subaccount.created?
38
+ # # => true
39
+ #
40
+ # subaccount = storage_box.subaccounts.create(password: "my_password", description: "my_subaccount", home_directory: "backup/", access_settings: { samba_enabled: false, ssh_enabled: true, webdav_enabled: false, readonly: false, reachable_externally: false })
41
+ # # => #<HCloud::Action id: 1, ...>
42
+ #
43
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself
44
+ #
45
+ # subaccount = HCloud::StorageBox::Subaccount.create(storage_box: 1, password: "my_password", description: "my_subaccount", home_directory: "backup/", access_settings: { samba_enabled: false, ssh_enabled: true, webdav_enabled: false, readonly: false, reachable_externally: false })
46
+ # # => #<HCloud::Action id: 1, ...>
47
+ #
48
+ # Note: this method returns a {HCloud::Action} instance rather than the created resource itself
49
+ #
50
+ # == Update subaccount
51
+ #
52
+ # storage_box = HCloud::StorageBox.find(1)
53
+ # subaccount = storage_box.subaccounts.find(1)
54
+ # subaccount.description = "another_subaccount"
55
+ # subaccount.update
56
+ #
57
+ # == Delete subaccount
58
+ #
59
+ # storage_box = HCloud::StorageBox.find(1)
60
+ # subaccount = storage_box.subaccounts.find(1)
61
+ # subaccount.delete
62
+ # # => #<HCloud::Action id: 1, ...>
63
+ #
64
+ # subaccount.deleted?
65
+ # # => true
66
+ #
67
+ # Note: this method returns a {HCloud::Action} instance rather than the deleted resource itself
68
+ #
69
+ # = Resource-specific actions
70
+ # == Reset password
71
+ #
72
+ # storage_box = HCloud::StorageBox.find(1)
73
+ # subaccount = storage_box.subaccounts.find(1)
74
+ # subaccount.reset_subaccount_password(password: "mypassword")
75
+ # # => #<HCloud::Action id: 1, ...>
76
+ #
77
+ # == Update access settings
78
+ #
79
+ # storage_box = HCloud::StorageBox.find(1)
80
+ # subaccount = storage_box.subaccounts.find(1)
81
+ # subaccount.update_access_settings(samba_enabled: false, ssh_enabled: true, webdav_enabled: false, zfs_enabled: false, reachable_externally: false)
82
+ # # => #<HCloud::Action id: 1, ...>
83
+ #
84
+ class StorageBoxSubaccount < Resource
85
+ subresource_of :storage_box
86
+
87
+ actionable
88
+ queryable
89
+ creatable
90
+ updatable
91
+ deletable
92
+ labelable
93
+
94
+ attribute :id, :integer
95
+ attribute :username
96
+ attribute :home_directory
97
+ attribute :description
98
+ attribute :comment
99
+
100
+ # String, not a Server resource
101
+ attribute :server
102
+
103
+ attribute :access_settings, :storage_box_subaccount_access_settings
104
+
105
+ attribute :protection, :protection
106
+
107
+ # Creatable attributes
108
+ attribute :password
109
+
110
+ action :reset_subaccount_password
111
+ action :update_access_settings
112
+
113
+ def creatable_attributes
114
+ [:password, :home_directory, :description, :labels, :access_settings]
115
+ end
116
+
117
+ def updatable_attributes
118
+ [:description, :labels]
119
+ end
120
+
121
+ def self.resource_name
122
+ "subaccount"
123
+ end
124
+
125
+ def self.client
126
+ HCloud::Client.connection.storage_box_client
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HCloud
4
+ ##
5
+ # Represents a storage box type
6
+ #
7
+ # == List all storage box types
8
+ #
9
+ # HCloud::StorageBoxType.all
10
+ # # => [#<HCloud::StorageBoxType id: 1, ...>, ...]
11
+ #
12
+ # == Search storage box types
13
+ #
14
+ # HCloud::StorageBoxType.where(name: "bx11")
15
+ # # => #<HCloud::StorageBoxType id: 1, ...>
16
+ #
17
+ # == Find storage box type by ID
18
+ #
19
+ # HCloud::StorageBoxType.find(1)
20
+ # # => #<HCloud::StorageBoxType id: 1, ...>
21
+ #
22
+ class StorageBoxType < Resource
23
+ queryable
24
+
25
+ attribute :id, :integer
26
+ attribute :name
27
+ attribute :description
28
+
29
+ attribute :size, :integer
30
+
31
+ attribute :snapshot_limit, :integer
32
+ attribute :automatic_snapshot_limit, :integer
33
+ attribute :subaccounts_limit, :integer
34
+
35
+ attribute :prices, :storage_box_price, array: true, default: -> { [] }
36
+
37
+ attribute :deprecation, :deprecation
38
+
39
+ def self.client
40
+ HCloud::Client.connection.storage_box_client
41
+ end
42
+ end
43
+ end