hcloud 0.1.0.pre.alpha3 → 0.1.0.pre.alpha4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hcloud/client.rb +16 -0
- data/lib/hcloud/floating_ip.rb +43 -0
- data/lib/hcloud/floating_ip_resource.rb +41 -0
- data/lib/hcloud/location_resource.rb +39 -0
- data/lib/hcloud/server_type_resource.rb +39 -0
- data/lib/hcloud/ssh_key.rb +24 -0
- data/lib/hcloud/ssh_key_resource.rb +44 -0
- data/lib/hcloud/version.rb +1 -1
- data/lib/hcloud.rb +6 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4dbd2d5d61d5bbe1fce20502673f677a67faf33
|
4
|
+
data.tar.gz: 0ddfe0a2a9a06490c46e843b6ada4a38ab269ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e60745c5f5d8692370d00bcab67ec354b2aa7bef9507417851713c58b687c61d274a039ae89635f1f0a4872fb5a376ab03f39fb3878d63f83b8d577f7faf4fe
|
7
|
+
data.tar.gz: 14ef3b03e95390258c8f1efc42586e97b6624b152cc61278b0f1b3c9cdffbd5fc79c8dd73228bd8df31df0ae3c4ceac1ffdb84ffbcb3364b13b64b8295b973e9
|
data/lib/hcloud/client.rb
CHANGED
@@ -35,6 +35,22 @@ module Hcloud
|
|
35
35
|
DatacenterResource.new(client: self)
|
36
36
|
end
|
37
37
|
|
38
|
+
def locations
|
39
|
+
LocationResource.new(client: self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def server_types
|
43
|
+
ServerTypeResource.new(client: self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def ssh_keys
|
47
|
+
SSHKeyResource.new(client: self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def floating_ips
|
51
|
+
FloatingIPResource.new(client: self)
|
52
|
+
end
|
53
|
+
|
38
54
|
def request(path, **options)
|
39
55
|
code = options.delete(:code)
|
40
56
|
if x = options.delete(:j)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class FloatingIP
|
3
|
+
Attributes = {
|
4
|
+
id: nil,
|
5
|
+
description: nil,
|
6
|
+
ip: nil,
|
7
|
+
type: nil,
|
8
|
+
dns_ptr: nil,
|
9
|
+
home_location: Location,
|
10
|
+
blocked: nil,
|
11
|
+
}
|
12
|
+
include EntryLoader
|
13
|
+
|
14
|
+
def update(description:)
|
15
|
+
j = Oj.load(request("floating_ips/#{id.to_i}",
|
16
|
+
j: {description: description},
|
17
|
+
method: :put).run.body)
|
18
|
+
FloatingIP.new(j["floating_ip"], self, client)
|
19
|
+
end
|
20
|
+
|
21
|
+
def assign(server:)
|
22
|
+
j = Oj.load(request("floating_ips/#{id.to_i}/actions/assign",
|
23
|
+
j: {server: server}).run.body)
|
24
|
+
Action.new(j["action"], self, client)
|
25
|
+
end
|
26
|
+
|
27
|
+
def unassign
|
28
|
+
j = Oj.load(request("floating_ips/#{id.to_i}/actions/unassign",
|
29
|
+
method: :post).run.body)
|
30
|
+
Action.new(j["action"], self, client)
|
31
|
+
end
|
32
|
+
|
33
|
+
def actions
|
34
|
+
ActionResource.new(client: client, parent: self, base_path: "floating_ips/#{id.to_i}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
request("floating_ips/#{id}", method: :delete).run.body
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class FloatingIPResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
j = Oj.load(request("floating_ips").run.body)
|
7
|
+
j["floating_ips"].map{|x| FloatingIP.new(x, self, client) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(type:, server: nil, home_location: nil, description: nil)
|
11
|
+
query = {}
|
12
|
+
method(:create).parameters.inject(query) do |r,x|
|
13
|
+
(var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
|
14
|
+
end
|
15
|
+
j = Oj.load(request("floating_ips", j: query, code: 200).run.body)
|
16
|
+
[
|
17
|
+
Action.new(j["action"], self, client),
|
18
|
+
FloatingIP.new(j["floating_ip"], self, client),
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def find(id)
|
23
|
+
FloatingIP.new(
|
24
|
+
Oj.load(request("floating_ips/#{id}").run.body)["floating_ip"],
|
25
|
+
self,
|
26
|
+
client
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def [](arg)
|
31
|
+
case arg
|
32
|
+
when Integer
|
33
|
+
begin
|
34
|
+
find(arg)
|
35
|
+
rescue Error::NotFound
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class LocationResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
j = Oj.load(request("locations").run.body)
|
7
|
+
j["locations"].map{|x| Location.new(x, self, client) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(id)
|
11
|
+
Location.new(
|
12
|
+
Oj.load(request("locations/#{id}").run.body)["location"],
|
13
|
+
self,
|
14
|
+
client
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by(name:)
|
19
|
+
x = Oj.load(request("locations", q: {name: name}).run.body)["locations"]
|
20
|
+
return nil if x.none?
|
21
|
+
x.each do |s|
|
22
|
+
return Location.new(s, self, client)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](arg)
|
27
|
+
case arg
|
28
|
+
when Integer
|
29
|
+
begin
|
30
|
+
find(arg)
|
31
|
+
rescue Error::NotFound
|
32
|
+
end
|
33
|
+
when String
|
34
|
+
find_by(name: arg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class ServerTypeResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
j = Oj.load(request("server_types").run.body)
|
7
|
+
j["server_types"].map{|x| ServerType.new(x, self, client) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(id)
|
11
|
+
ServerType.new(
|
12
|
+
Oj.load(request("server_types/#{id}").run.body)["server_type"],
|
13
|
+
self,
|
14
|
+
client
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by(name:)
|
19
|
+
x = Oj.load(request("server_types", q: {name: name}).run.body)["server_types"]
|
20
|
+
return nil if x.none?
|
21
|
+
x.each do |s|
|
22
|
+
return ServerType.new(s, self, client)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](arg)
|
27
|
+
case arg
|
28
|
+
when Integer
|
29
|
+
begin
|
30
|
+
find(arg)
|
31
|
+
rescue Error::NotFound
|
32
|
+
end
|
33
|
+
when String
|
34
|
+
find_by(name: arg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class SSHKey
|
3
|
+
Attributes = {
|
4
|
+
id: nil,
|
5
|
+
name: nil,
|
6
|
+
fingerprint: nil,
|
7
|
+
public_key: nil
|
8
|
+
}
|
9
|
+
include EntryLoader
|
10
|
+
|
11
|
+
def update(name:)
|
12
|
+
j = Oj.load(request("ssh_keys/#{id.to_i}",
|
13
|
+
j: {name: name},
|
14
|
+
method: :put).run.body)
|
15
|
+
SSHKey.new(j["ssh_key"], self, client)
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
request("ssh_keys/#{id}", method: :delete).run.body
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class SSHKeyResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
j = Oj.load(request("ssh_keys").run.body)
|
7
|
+
j["ssh_keys"].map{|x| SSHKey.new(x, self, client) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(name:, public_key:)
|
11
|
+
j = Oj.load(request("ssh_keys", j: {name: name, public_key: public_key}).run.body)
|
12
|
+
SSHKey.new(j, self, client)
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(id)
|
16
|
+
SSHKey.new(
|
17
|
+
Oj.load(request("ssh_keys/#{id}").run.body)["ssh_key"],
|
18
|
+
self,
|
19
|
+
client
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_by(name:)
|
24
|
+
x = Oj.load(request("ssh_keys", q: {name: name}).run.body)["ssh_keys"]
|
25
|
+
return nil if x.none?
|
26
|
+
x.each do |s|
|
27
|
+
return SSHKey.new(s, self, client)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](arg)
|
32
|
+
case arg
|
33
|
+
when Integer
|
34
|
+
begin
|
35
|
+
find(arg)
|
36
|
+
rescue Error::NotFound
|
37
|
+
end
|
38
|
+
when String
|
39
|
+
find_by(name: arg)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/hcloud/version.rb
CHANGED
data/lib/hcloud.rb
CHANGED
@@ -7,11 +7,17 @@ module Hcloud
|
|
7
7
|
autoload :AbstractResource, 'hcloud/abstract_resource'
|
8
8
|
autoload :ServerResource, 'hcloud/server_resource'
|
9
9
|
autoload :EntryLoader, 'hcloud/entry_loader'
|
10
|
+
autoload :FloatingIP, 'hcloud/floating_ip'
|
11
|
+
autoload :FloatingIPResource, 'hcloud/floating_ip_resource'
|
12
|
+
autoload :SSHKey, 'hcloud/ssh_key'
|
13
|
+
autoload :SSHKeyResource, 'hcloud/ssh_key_resource'
|
10
14
|
autoload :Server, 'hcloud/server'
|
11
15
|
autoload :ServerType, 'hcloud/server_type'
|
16
|
+
autoload :ServerTypeResource, 'hcloud/server_type_resource'
|
12
17
|
autoload :Datacenter, 'hcloud/datacenter'
|
13
18
|
autoload :DatacenterResource, 'hcloud/datacenter_resource'
|
14
19
|
autoload :Location, 'hcloud/location'
|
20
|
+
autoload :LocationResource, 'hcloud/location_resource'
|
15
21
|
autoload :Image, 'hcloud/image'
|
16
22
|
autoload :ImageResource, 'hcloud/image_resource'
|
17
23
|
autoload :Action, 'hcloud/action'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.alpha4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Foerster
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,14 +103,20 @@ files:
|
|
103
103
|
- lib/hcloud/datacenter_resource.rb
|
104
104
|
- lib/hcloud/entry_loader.rb
|
105
105
|
- lib/hcloud/errors.rb
|
106
|
+
- lib/hcloud/floating_ip.rb
|
107
|
+
- lib/hcloud/floating_ip_resource.rb
|
106
108
|
- lib/hcloud/image.rb
|
107
109
|
- lib/hcloud/image_resource.rb
|
108
110
|
- lib/hcloud/iso.rb
|
109
111
|
- lib/hcloud/iso_resource.rb
|
110
112
|
- lib/hcloud/location.rb
|
113
|
+
- lib/hcloud/location_resource.rb
|
111
114
|
- lib/hcloud/server.rb
|
112
115
|
- lib/hcloud/server_resource.rb
|
113
116
|
- lib/hcloud/server_type.rb
|
117
|
+
- lib/hcloud/server_type_resource.rb
|
118
|
+
- lib/hcloud/ssh_key.rb
|
119
|
+
- lib/hcloud/ssh_key_resource.rb
|
114
120
|
- lib/hcloud/version.rb
|
115
121
|
homepage: https://github.com/tonobo/hcloud
|
116
122
|
licenses: []
|