hetznercloud 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7de89d0a6117d05ba5b57c40b41601aecb419a6ca8c9bd5b639117051a6501e4
4
- data.tar.gz: 9b3a8d86043d7c2a7622816f987b4bfa7c2584b2fe0b2535e8e3300f4a5117ab
3
+ metadata.gz: a1b9b0de15d2fe2aecdbfa6b00b46df9ec658855ebdafcabebe72f371dd98d50
4
+ data.tar.gz: 6c39c3ee93d35767d355e522408d1285ce3777fc841753968ae9c33d0916cc6c
5
5
  SHA512:
6
- metadata.gz: ae331dfc72e7baf0bda9b6e6ad9354630166d4faa9169538d56f69c3d5117703955df6d5b7f10851e5f1cbd082d4b942826914091d2f22ec628040259e63405f
7
- data.tar.gz: 2898e89f00a5ba8be3b7d75eb27ba3b3d507a83683f0b214555600c89482c7fc317b5cbf3f1e7e5461a784a5e047e6f302a08047320e230ab0bc5049eda70fc4
6
+ metadata.gz: 7a9971d0195c839594b88759d828dc04f98e36d37eab7880d27f4299f8266d2e37676eea3b60399440bed9240e6d39190dba0af75f2d32bfe78c5e42bb160cd5
7
+ data.tar.gz: bbecc7998329638d8499d0a33c877cdc5857b2a94c80633672a874f6828cc69f29e67d8e3a618b21db5cd84d87cf66cecd2e2ee3ddcfa16db00f841394f0ea85
data/CHANGELOG.md CHANGED
@@ -1,11 +1,26 @@
1
1
  # Changelog
2
2
 
3
- ## HCloud v1.3.0
3
+ ## HCloud v1.4.0 (2023-01-22)
4
+
5
+ - Implemented Primary IPs
6
+ - Implemented Primary IP Actions
7
+ - Allow calling `#update` with additional attributes to be updated
8
+ - Return the resource when calling `#create`, `#update` or `#delete`
9
+ - Add additional primary IP mismatch errors:
10
+ - `PrimaryIPAssigned`
11
+ - `PrimaryIPDatacenterMismatch`
12
+ - `PrimaryIPVersionMismatch`
13
+
14
+ ## HCloud v1.3.1 (2022-02-06)
15
+
16
+ - Add missing `Server#user_data`
17
+
18
+ ## HCloud v1.3.0 (2022-02-04)
4
19
 
5
20
  - Implemented Load Balancers
6
21
  - Implemented Load Balancer Types
7
22
 
8
- ## HCloud v1.2.0
23
+ ## HCloud v1.2.0 (2022-02-01)
9
24
 
10
25
  - Implemented Networks
11
26
  - Implemented Network Actions
@@ -13,10 +28,10 @@
13
28
  - Implemented Certificates
14
29
  - Implemented Certificate Actions
15
30
 
16
- ## HCloud v1.1.0
31
+ ## HCloud v1.1.0 (2022-01-30)
17
32
 
18
33
  - Implemented Firewall Actions
19
34
 
20
- ## HCloud v1.0.0
35
+ ## HCloud v1.0.0 (2022-01-16)
21
36
 
22
37
  Initial release
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Florian Dejonckheere
3
+ Copyright (c) 2023 Florian Dejonckheere
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -88,6 +88,8 @@ Not all Hetzner Cloud API endpoints have been implemented yet.
88
88
  | Load Balancer Actions | Not implemented |
89
89
  | Load Balancer Types | Implemented |
90
90
  | Locations | Implemented |
91
+ | Primary IPs | Implemented |
92
+ | Primary IP Actions | Implemented |
91
93
  | Networks | Implemented |
92
94
  | Network Actions | Implemented |
93
95
  | Placement Groups | Implemented |
@@ -14,6 +14,7 @@ HCloud.loader.inflector.inflect(
14
14
  "ipv6" => "IPv6",
15
15
  "iso" => "ISO",
16
16
  "iso_type" => "ISOType",
17
+ "primary_ip" => "PrimaryIP",
17
18
  "service_http" => "ServiceHTTP",
18
19
  "ssh_key" => "SSHKey",
19
20
  "target_ip" => "TargetIP",
@@ -23,6 +24,8 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
23
24
  inflect.acronym "DNS"
24
25
  inflect.acronym "HTTP"
25
26
  inflect.acronym "IP"
27
+ inflect.acronym "IPv4"
28
+ inflect.acronym "IPv6"
26
29
  inflect.acronym "ISO"
27
30
  inflect.acronym "JSON"
28
31
  end
@@ -12,6 +12,8 @@ module HCloud
12
12
  .post("/#{resource_name.pluralize}", creatable_params)
13
13
  .tap { |r| r[resource_name.to_sym].merge!(r.slice(:root_password)) }
14
14
  .fetch(resource_name.to_sym)
15
+
16
+ self
15
17
  end
16
18
 
17
19
  def created?
@@ -12,6 +12,8 @@ module HCloud
12
12
  .delete("/#{resource_name.pluralize}/#{id}")
13
13
 
14
14
  @deleted = true
15
+
16
+ self
15
17
  end
16
18
 
17
19
  def deleted?
@@ -5,12 +5,16 @@ module HCloud
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- def update
8
+ def update(**attributes)
9
9
  raise Errors::MissingIDError unless id
10
10
 
11
+ assign_attributes attributes
12
+
11
13
  assign_attributes client
12
14
  .put("/#{resource_name.pluralize}/#{id}", updatable_params)
13
15
  .fetch(resource_name.to_sym)
16
+
17
+ self
14
18
  end
15
19
 
16
20
  def updatable_attributes
data/lib/hcloud/errors.rb CHANGED
@@ -43,6 +43,10 @@ module HCloud
43
43
  class NotFound < Error; end
44
44
  class PlacementError < Error; end
45
45
  class PlacementError < Error; end
46
+ class PrimaryIPAssigned < Error; end
47
+ class PrimaryIPAlreadyAssigned < Error; end
48
+ class PrimaryIPDatacenterMismatch < Error; end
49
+ class PrimaryIPVersionMismatch < Error; end
46
50
  class Protected < Error; end
47
51
  class RateLimitExceeded < Error; end
48
52
  class ResourceInUse < Error; end
@@ -52,7 +56,11 @@ module HCloud
52
56
  class ServerAlreadyAdded < Error; end
53
57
  class ServerAlreadyAttached < Error; end
54
58
  class ServerError < Error; end
59
+ class ServerHasIPv4 < Error; end
60
+ class ServerHasIPv6 < Error; end
61
+ class ServerIsLoadBalancerTarget < Error; end
55
62
  class ServerNotAttachedToNetwork < Error; end
63
+ class ServerNotStopped < Error; end
56
64
  class ServiceError < Error; end
57
65
  class SourcePortAlreadyUsed < Error; end
58
66
  class TargetAlreadyDefined < Error; end
@@ -90,6 +90,7 @@ ActiveModel::Type.register(:network, HCloud::ResourceType.Type("HCloud::Network"
90
90
  ActiveModel::Type.register(:placement_group, HCloud::ResourceType.Type("HCloud::PlacementGroup"))
91
91
  ActiveModel::Type.register(:price, HCloud::ResourceType.Type("HCloud::Price"))
92
92
  ActiveModel::Type.register(:pricing, HCloud::ResourceType.Type("HCloud::Pricing"))
93
+ ActiveModel::Type.register(:primary_ip, HCloud::ResourceType.Type("HCloud::PrimaryIP"))
93
94
  ActiveModel::Type.register(:private_net, HCloud::ResourceType.Type("HCloud::PrivateNet"))
94
95
  ActiveModel::Type.register(:protection, HCloud::ResourceType.Type("HCloud::Protection"))
95
96
  ActiveModel::Type.register(:public_net, HCloud::ResourceType.Type("HCloud::PublicNet"))
@@ -0,0 +1,148 @@
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.all.sort(id: :asc)
15
+ # # => [#<HCloud::PrimaryIP id: 1, ...>, ...]
16
+ #
17
+ # HCloud::PrimaryIP.all.sort(:id, created: :asc)
18
+ # # => [#<HCloud::PrimaryIP id: 1, ...>, ...]
19
+ #
20
+ # == Search primary IPs
21
+ #
22
+ # HCloud::PrimaryIP.all.where(name: "my_primary_ip")
23
+ # # => #<HCloud::PrimaryIP id: 1, ...>
24
+ #
25
+ # HCloud::PrimaryIP.all.where(ip: "1.2.3.4")
26
+ # # => #<HCloud::PrimaryIP id: 1, ...>
27
+ #
28
+ # == Find primary IP by ID
29
+ #
30
+ # HCloud::PrimaryIP.find(1)
31
+ # # => #<HCloud::PrimaryIP id: 1, ...>
32
+ #
33
+ # == Create primary IP
34
+ #
35
+ # primary IP = HCloud::PrimaryIP.new(name: "my_primary_ip", type: "ipv4", datacenter: "fsn1-dc8")
36
+ # primary IP.create
37
+ # primary IP.created?
38
+ # # => true
39
+ #
40
+ # firewall = HCloud::PrimaryIP.create(name: "my_primary_ip")
41
+ # # => #<HCloud::PrimaryIP id: 1, ...>
42
+ #
43
+ # == Update primary IP
44
+ #
45
+ # primary IP = HCloud::PrimaryIP.find(1)
46
+ # primary IP.name = "another_primary_ip"
47
+ # primary IP.update
48
+ #
49
+ # == Delete primary IP
50
+ #
51
+ # primary IP = HCloud::PrimaryIP.find(1)
52
+ # primary IP.delete
53
+ # primary IP.deleted?
54
+ # # => true
55
+ #
56
+ # = Actions
57
+ # == List actions
58
+ #
59
+ # actions = HCloud::PrimaryIP.find(1).actions
60
+ # # => [#<HCloud::Action id: 1, ...>, ...]
61
+ #
62
+ # == Sort actions
63
+ #
64
+ # HCloud::PrimaryIP.find(1).actions.sort(finished: :desc)
65
+ # # => [#<HCloud::Action id: 1, ...>, ...]
66
+ #
67
+ # HCloud::PrimaryIP.find(1).actions.sort(:command, finished: :asc)
68
+ # # => [#<HCloud::Actions id: 1, ...>, ...]
69
+ #
70
+ # == Search actions
71
+ #
72
+ # HCloud::PrimaryIP.find(1).actions.where(command: "assign_primary_ip")
73
+ # # => #<HCloud::Action id: 1, ...>
74
+ #
75
+ # HCloud::PrimaryIP.find(1).actions.where(status: "success")
76
+ # # => #<HCloud::Action id: 1, ...>
77
+ #
78
+ # == Find action by ID
79
+ #
80
+ # HCloud::PrimaryIP.find(1).actions.find(1)
81
+ # # => #<HCloud::Action id: 1, ...>
82
+ #
83
+ # = Resource-specific actions
84
+ # == Assign a primary IP to a server
85
+ #
86
+ # HCloud::PrimaryIP.find(1).assign(assignee_id: 1, assignee_type: "server")
87
+ # # => #<HCloud::Action id: 1, ...>
88
+ #
89
+ # == Unassign a primary IP from a server
90
+ #
91
+ # HCloud::PrimaryIP.find(1).unassign
92
+ # # => #<HCloud::Action id: 1, ...>
93
+ #
94
+ # == Change reverse DNS entry
95
+ #
96
+ # HCloud::PrimaryIP.find(1).change_dns_ptr(dns_ptr: "server.example.com", ip: "1.2.3.4")
97
+ # # => #<HCloud::Action id: 1, ...>
98
+ #
99
+ # == Change protection
100
+ #
101
+ # HCloud::PrimaryIP.find(1).change_protection(delete: true)
102
+ # # => #<HCloud::Action id: 1, ...>
103
+ #
104
+ class PrimaryIP < Resource
105
+ actionable
106
+ queryable
107
+ creatable
108
+ updatable
109
+ deletable
110
+
111
+ attribute :id, :integer
112
+ attribute :name
113
+
114
+ attribute :type
115
+ attribute :ip
116
+ attribute :dns_ptr, :dns_pointer, array: true, default: -> { [] }
117
+
118
+ attribute :assignee_id
119
+ attribute :assignee_type, default: "server"
120
+
121
+ attribute :auto_delete, :boolean
122
+ attribute :blocked, :boolean
123
+
124
+ attribute :datacenter, :datacenter
125
+
126
+ attribute :protection, :protection
127
+
128
+ attribute :labels, default: -> { {} }
129
+
130
+ alias auto_delete? auto_delete
131
+ alias blocked? blocked
132
+
133
+ action :assign
134
+ action :unassign
135
+
136
+ action :change_dns_ptr
137
+
138
+ action :change_protection
139
+
140
+ def creatable_attributes
141
+ [:name, :type, :assignee_id, :assignee_type, :auto_delete, :labels, datacenter: [:id, :name]]
142
+ end
143
+
144
+ def updatable_attributes
145
+ [:name, :auto_delete, :labels]
146
+ end
147
+ end
148
+ end
@@ -33,7 +33,7 @@ module HCloud
33
33
  # == Create server
34
34
  #
35
35
  # user_data = File.read("user_data.yml")
36
- # server = HCloud::Server.new(name: "my_server", image: "debian-11", server_type: "cx11")
36
+ # server = HCloud::Server.new(name: "my_server", image: "debian-11", server_type: "cx11", user_data: user_data)
37
37
  # server.create
38
38
  # server.created?
39
39
  # # => true
@@ -82,6 +82,9 @@ module HCloud
82
82
 
83
83
  attribute :backup_window
84
84
 
85
+ # TODO: use only for creation
86
+ attribute :user_data
87
+
85
88
  # TODO: use only for creation
86
89
  attribute :location, :location
87
90
 
@@ -3,7 +3,7 @@
3
3
  module HCloud
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 3
6
+ MINOR = 4
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
data/lib/hcloud.rb CHANGED
@@ -16,7 +16,7 @@ module HCloud
16
16
  end
17
17
 
18
18
  def setup
19
- @loader = Zeitwerk::Loader.for_gem
19
+ @loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
20
20
 
21
21
  # Register inflections
22
22
  require root.join("config/inflections.rb")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hetznercloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -275,6 +275,7 @@ files:
275
275
  - lib/hcloud/resources/network.rb
276
276
  - lib/hcloud/resources/placement_group.rb
277
277
  - lib/hcloud/resources/pricing.rb
278
+ - lib/hcloud/resources/primary_ip.rb
278
279
  - lib/hcloud/resources/server.rb
279
280
  - lib/hcloud/resources/server_type.rb
280
281
  - lib/hcloud/resources/ssh_key.rb
@@ -301,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
302
  - !ruby/object:Gem::Version
302
303
  version: '0'
303
304
  requirements: []
304
- rubygems_version: 3.1.2
305
+ rubygems_version: 3.3.5
305
306
  signing_key:
306
307
  specification_version: 4
307
308
  summary: Ruby library wrapping the Hetzner Cloud API