fog-hetznercloud 0.0.1
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +139 -0
- data/Rakefile +24 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fog-hetznercloud.gemspec +33 -0
- data/lib/fog/hetznercloud.rb +13 -0
- data/lib/fog/hetznercloud/client.rb +55 -0
- data/lib/fog/hetznercloud/compute.rb +146 -0
- data/lib/fog/hetznercloud/errors.rb +37 -0
- data/lib/fog/hetznercloud/models/compute/action.rb +31 -0
- data/lib/fog/hetznercloud/models/compute/actions.rb +22 -0
- data/lib/fog/hetznercloud/models/compute/datacenter.rb +15 -0
- data/lib/fog/hetznercloud/models/compute/datacenters.rb +22 -0
- data/lib/fog/hetznercloud/models/compute/floating_ip.rb +154 -0
- data/lib/fog/hetznercloud/models/compute/floating_ips.rb +22 -0
- data/lib/fog/hetznercloud/models/compute/image.rb +78 -0
- data/lib/fog/hetznercloud/models/compute/images.rb +22 -0
- data/lib/fog/hetznercloud/models/compute/location.rb +18 -0
- data/lib/fog/hetznercloud/models/compute/locations.rb +22 -0
- data/lib/fog/hetznercloud/models/compute/server.rb +393 -0
- data/lib/fog/hetznercloud/models/compute/server_type.rb +17 -0
- data/lib/fog/hetznercloud/models/compute/server_types.rb +22 -0
- data/lib/fog/hetznercloud/models/compute/servers.rb +47 -0
- data/lib/fog/hetznercloud/models/compute/ssh_key.rb +65 -0
- data/lib/fog/hetznercloud/models/compute/ssh_keys.rb +22 -0
- data/lib/fog/hetznercloud/request_helper.rb +32 -0
- data/lib/fog/hetznercloud/requests/compute/create_floating_ip.rb +29 -0
- data/lib/fog/hetznercloud/requests/compute/create_server.rb +31 -0
- data/lib/fog/hetznercloud/requests/compute/create_ssh_key.rb +24 -0
- data/lib/fog/hetznercloud/requests/compute/delete_floating_ip.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/delete_image.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/delete_server.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/delete_ssh_key.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/execute_server_action.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/floating_ip_assign_to_server.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/floating_ip_unassign.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/floating_ip_update_dns_ptr.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_action.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_datacenter.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_floating_ip.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_image.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_location.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_server.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_server_type.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/get_ssh_key.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_actions.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_datacenters.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_floating_ips.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_images.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_locations.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_server_types.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_servers.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/list_ssh_keys.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/update_floating_ip.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/update_image.rb +17 -0
- data/lib/fog/hetznercloud/requests/compute/update_server.rb +77 -0
- data/lib/fog/hetznercloud/requests/compute/update_ssh_key.rb +17 -0
- data/lib/fog/hetznercloud/version.rb +5 -0
- metadata +244 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class ServerType < Fog::Model
|
5
|
+
identity :id
|
6
|
+
|
7
|
+
attribute :name
|
8
|
+
attribute :description
|
9
|
+
attribute :cores
|
10
|
+
attribute :memory
|
11
|
+
attribute :disk
|
12
|
+
attribute :prices
|
13
|
+
attribute :storage_type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class ServerTypes < Fog::Collection
|
5
|
+
model Fog::Hetznercloud::Compute::ServerType
|
6
|
+
|
7
|
+
def all(filters = {})
|
8
|
+
server_types = service.list_server_types(filters).body['server_types'] || []
|
9
|
+
load(server_types)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(identity)
|
13
|
+
if (server_type = service.get_server_type(identity).body['server_type'])
|
14
|
+
new(server_type)
|
15
|
+
end
|
16
|
+
rescue Fog::Hetznercloud::Compute::UnknownResourceError
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Servers < Fog::Collection
|
5
|
+
model Fog::Hetznercloud::Compute::Server
|
6
|
+
|
7
|
+
def all(filters = {})
|
8
|
+
servers = service.list_servers(filters).body['servers'] || []
|
9
|
+
load(servers)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(identity)
|
13
|
+
if (server = service.get_server(identity).body['server'])
|
14
|
+
new(server)
|
15
|
+
end
|
16
|
+
rescue Fog::Hetznercloud::Compute::UnknownResourceError
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def bootstrap(bootstap_timeout: 120, new_attributes: {}, ssh_keys:)
|
21
|
+
require 'securerandom'
|
22
|
+
|
23
|
+
defaults = {
|
24
|
+
name: "hc-#{SecureRandom.hex(3)}",
|
25
|
+
image: 'centos-7',
|
26
|
+
server_type: 'cx11',
|
27
|
+
ssh_keys: ssh_keys
|
28
|
+
}
|
29
|
+
|
30
|
+
server = create(defaults.merge(new_attributes))
|
31
|
+
|
32
|
+
status = false
|
33
|
+
begin
|
34
|
+
status = Timeout.timeout(bootstap_timeout) do
|
35
|
+
server.wait_for { sshable?(auth_methods: %w[publickey]) }
|
36
|
+
end
|
37
|
+
rescue Timeout::Error => e
|
38
|
+
server.destroy
|
39
|
+
raise e
|
40
|
+
end
|
41
|
+
|
42
|
+
server
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# https://docs.hetzner.cloud/#resources-actions-get
|
2
|
+
module Fog
|
3
|
+
module Hetznercloud
|
4
|
+
class Compute
|
5
|
+
class SshKey < Fog::Model
|
6
|
+
identity :id
|
7
|
+
|
8
|
+
attribute :name
|
9
|
+
attribute :fingerprint
|
10
|
+
attribute :public_key
|
11
|
+
|
12
|
+
def destroy
|
13
|
+
requires :identity
|
14
|
+
|
15
|
+
service.delete_ssh_key(identity)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def public_key=(value)
|
20
|
+
attributes[:public_key] = if value =~ /^\.?\/[^\/]+/
|
21
|
+
File.read(value)
|
22
|
+
else
|
23
|
+
value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
if persisted?
|
29
|
+
update
|
30
|
+
else
|
31
|
+
create
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def create
|
38
|
+
requires :name, :public_key
|
39
|
+
|
40
|
+
if (ssh_key = service.create_ssh_key(name, public_key).body['ssh_key'])
|
41
|
+
merge_attributes(ssh_key)
|
42
|
+
true
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
requires :identity, :name
|
50
|
+
|
51
|
+
body = attributes.dup
|
52
|
+
|
53
|
+
body[:name] = name
|
54
|
+
|
55
|
+
if (ssh_key = service.update_ssh_key(identity, body).body['ssh_key'])
|
56
|
+
merge_attributes(ssh_key)
|
57
|
+
true
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class SshKeys < Fog::Collection
|
5
|
+
model Fog::Hetznercloud::Compute::SshKey
|
6
|
+
|
7
|
+
def all(filters = {})
|
8
|
+
ssh_keys = service.list_ssh_keys(filters).body['ssh_keys'] || []
|
9
|
+
load(ssh_keys)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(identity)
|
13
|
+
if (ssh_key = service.get_ssh_key(identity).body['ssh_key'])
|
14
|
+
new(ssh_key)
|
15
|
+
end
|
16
|
+
rescue Fog::Hetznercloud::Compute::UnknownResourceError
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
module RequestHelper
|
4
|
+
def create(path, body)
|
5
|
+
request(method: :post,
|
6
|
+
path: "/v1#{path}",
|
7
|
+
body: body,
|
8
|
+
expects: [201])
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(path, query = {})
|
12
|
+
request(method: :get,
|
13
|
+
path: "/v1#{path}",
|
14
|
+
query: query,
|
15
|
+
expects: [200])
|
16
|
+
end
|
17
|
+
|
18
|
+
def update(path, body)
|
19
|
+
request(method: :put,
|
20
|
+
path: "/v1#{path}",
|
21
|
+
body: body,
|
22
|
+
expects: [200])
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(path)
|
26
|
+
request(method: :delete,
|
27
|
+
path: "/v1#{path}",
|
28
|
+
expects: [200, 204])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_floating_ip(type, options = {})
|
6
|
+
body = {
|
7
|
+
type: type
|
8
|
+
}
|
9
|
+
|
10
|
+
# if !@datacenter.nil?
|
11
|
+
# body.merge!({datacenter: @datacenter})
|
12
|
+
# elsif !@location.nil?
|
13
|
+
# body.merge!({location: @location})
|
14
|
+
# end
|
15
|
+
|
16
|
+
body.merge!(options)
|
17
|
+
|
18
|
+
create('/floating_ips', body)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Mock
|
23
|
+
def create_floating_ip(_type, _options = {})
|
24
|
+
Fog::Mock.not_implemented
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_server(name, image, server_type, options = {})
|
6
|
+
body = {
|
7
|
+
name: name,
|
8
|
+
image: image,
|
9
|
+
server_type: server_type
|
10
|
+
}
|
11
|
+
|
12
|
+
# if !@datacenter.nil?
|
13
|
+
# body.merge!({datacenter: @datacenter})
|
14
|
+
# elsif !@location.nil?
|
15
|
+
# body.merge!({location: @location})
|
16
|
+
# end
|
17
|
+
|
18
|
+
body.merge!(options)
|
19
|
+
|
20
|
+
create('/servers', body)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def create_server(_name, _image, _volumes, _options = {})
|
26
|
+
Fog::Mock.not_implemented
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def create_ssh_key(name, public_key, options = {})
|
6
|
+
body = {
|
7
|
+
name: name,
|
8
|
+
public_key: public_key
|
9
|
+
}
|
10
|
+
|
11
|
+
body.merge!(options)
|
12
|
+
|
13
|
+
create('/ssh_keys', body)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Mock
|
18
|
+
def create_ssh_key(_type, _home_location, _server, _options = {})
|
19
|
+
Fog::Mock.not_implemented
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def delete_server(server_id)
|
6
|
+
delete("/servers/#{server_id}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def delete_server(_server_id)
|
12
|
+
Fog::Mock.not_implemented
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def execute_server_action(id, action, body = {})
|
6
|
+
create("/servers/#{id}/actions/#{action}", body)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def execute_server_action(_id, _action)
|
12
|
+
Fog::Mock.not_implemented
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def floating_ip_assign_to_server(id, body)
|
6
|
+
create("/floating_ips/#{id}/actions/assign", body)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def floating_ip_assign_to_server(_type, _body)
|
12
|
+
Fog::Mock.not_implemented
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def floating_ip_unassign(id, body)
|
6
|
+
create("/floating_ips/#{id}/actions/unassign", body)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def floating_ip_unassign(_type, _body)
|
12
|
+
Fog::Mock.not_implemented
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hetznercloud
|
3
|
+
class Compute
|
4
|
+
class Real
|
5
|
+
def floating_ip_update_dns_ptr(id, body)
|
6
|
+
create("/floating_ips/#{id}/actions/change_dns_ptr", body)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
def floating_ip_update_dns_ptr(_type, _body)
|
12
|
+
Fog::Mock.not_implemented
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|