hcloud 0.1.0.pre.alpha2 → 0.1.0.pre.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/hcloud.gemspec +3 -3
- data/lib/hcloud.rb +4 -0
- data/lib/hcloud/client.rb +12 -0
- data/lib/hcloud/datacenter.rb +1 -0
- data/lib/hcloud/datacenter_resource.rb +47 -0
- data/lib/hcloud/image.rb +20 -0
- data/lib/hcloud/image_resource.rb +52 -0
- data/lib/hcloud/iso.rb +12 -0
- data/lib/hcloud/iso_resource.rb +40 -0
- data/lib/hcloud/server_resource.rb +6 -5
- data/lib/hcloud/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff06cea6db9abf71dea821a768e79bf514fb323d
|
4
|
+
data.tar.gz: 0ca5cbeaf98c743d1daf2e825ab8f1d898a4037a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15b166fcbce6790f1d1cc9d9212a1209a1f2920fc6a7d7d55d583c4f72fecfbc1e629fb77307cc1a6802365d184f13ad4fb9aa267a2a4c296bc3c1ba87f01ea4
|
7
|
+
data.tar.gz: 1a0b2519e11ceb2944ff860cc9b2c78bcc6f5318f867767e08d0402c69d4cdd1d104ac8cceae4959fcfd0ff35f7bd98ccd5ad8b4d06be1a8c854b63d332a30f9
|
data/README.md
CHANGED
data/hcloud.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.15"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.
|
25
|
-
spec.
|
26
|
-
spec.
|
24
|
+
spec.add_runtime_dependency "typhoeus"
|
25
|
+
spec.add_runtime_dependency "oj"
|
26
|
+
spec.add_runtime_dependency "activesupport"
|
27
27
|
end
|
data/lib/hcloud.rb
CHANGED
@@ -10,8 +10,12 @@ module Hcloud
|
|
10
10
|
autoload :Server, 'hcloud/server'
|
11
11
|
autoload :ServerType, 'hcloud/server_type'
|
12
12
|
autoload :Datacenter, 'hcloud/datacenter'
|
13
|
+
autoload :DatacenterResource, 'hcloud/datacenter_resource'
|
13
14
|
autoload :Location, 'hcloud/location'
|
14
15
|
autoload :Image, 'hcloud/image'
|
16
|
+
autoload :ImageResource, 'hcloud/image_resource'
|
15
17
|
autoload :Action, 'hcloud/action'
|
16
18
|
autoload :ActionResource, 'hcloud/action_resource'
|
19
|
+
autoload :Iso, 'hcloud/iso'
|
20
|
+
autoload :IsoResource, 'hcloud/iso_resource'
|
17
21
|
end
|
data/lib/hcloud/client.rb
CHANGED
@@ -23,6 +23,18 @@ module Hcloud
|
|
23
23
|
ActionResource.new(client: self)
|
24
24
|
end
|
25
25
|
|
26
|
+
def isos
|
27
|
+
IsoResource.new(client: self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def images
|
31
|
+
ImageResource.new(client: self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def datacenters
|
35
|
+
DatacenterResource.new(client: self)
|
36
|
+
end
|
37
|
+
|
26
38
|
def request(path, **options)
|
27
39
|
code = options.delete(:code)
|
28
40
|
if x = options.delete(:j)
|
data/lib/hcloud/datacenter.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class DatacenterResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
j = Oj.load(request("datacenters").run.body)
|
7
|
+
dc = j["datacenters"].map{|x| Datacenter.new(x, self, client) }
|
8
|
+
dc.reject{|x| x.id == j["recommendation"]}.unshift(
|
9
|
+
dc.find{|x| x.id == j["recommendation"]}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def recommended
|
14
|
+
all.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(id)
|
18
|
+
Datacenter.new(
|
19
|
+
Oj.load(request("datacenters/#{id}").run.body)["datacenter"],
|
20
|
+
self,
|
21
|
+
client
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by(name:)
|
26
|
+
x = Oj.load(request("datacenters", q: {name: name}).run.body)["datacenters"]
|
27
|
+
return nil if x.none?
|
28
|
+
x.each do |s|
|
29
|
+
return Datacenter.new(s, self, client)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def [](arg)
|
34
|
+
case arg
|
35
|
+
when Integer
|
36
|
+
begin
|
37
|
+
find(arg)
|
38
|
+
rescue Error::NotFound
|
39
|
+
end
|
40
|
+
when String
|
41
|
+
find_by(name: arg)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/lib/hcloud/image.rb
CHANGED
@@ -18,5 +18,25 @@ module Hcloud
|
|
18
18
|
|
19
19
|
include EntryLoader
|
20
20
|
|
21
|
+
def to_snapshot
|
22
|
+
update(type: "snapshot")
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(description: nil, type: nil)
|
26
|
+
query = {}
|
27
|
+
method(:update).parameters.inject(query) do |r,x|
|
28
|
+
(var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
|
29
|
+
end
|
30
|
+
Image.new(
|
31
|
+
Oj.load(request("images/#{id.to_i}", j: query, method: :put).run.body)["image"],
|
32
|
+
parent,
|
33
|
+
client
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def destory
|
38
|
+
request("images/#{id.to_i}", method: :delete).run
|
39
|
+
true
|
40
|
+
end
|
21
41
|
end
|
22
42
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class ImageResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
Oj.load(request("images").run.body)["images"].map do |x|
|
7
|
+
Image.new(x, self, client)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](arg)
|
12
|
+
case arg
|
13
|
+
when Integer
|
14
|
+
begin
|
15
|
+
find(arg)
|
16
|
+
rescue Error::NotFound
|
17
|
+
end
|
18
|
+
when String
|
19
|
+
find_by(name: arg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(id)
|
24
|
+
Image.new(
|
25
|
+
Oj.load(request("images/#{id.to_i}").run.body)["image"],
|
26
|
+
self,
|
27
|
+
client
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def where(sort: nil, type: nil, bound_to: nil, name: nil)
|
32
|
+
query = {}
|
33
|
+
method(:where).parameters.inject(query) do |r,x|
|
34
|
+
(var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
|
35
|
+
end
|
36
|
+
Oj.load(
|
37
|
+
request("images", q: query).run.body
|
38
|
+
)["images"].map do |x|
|
39
|
+
Image.new(x, self, client)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_by(name:)
|
44
|
+
j = Oj.load(request("images", q: {name: name}).run.body)["images"]
|
45
|
+
return if j.none?
|
46
|
+
j.each do |x|
|
47
|
+
return Image.new(x, self, client)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/hcloud/iso.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Hcloud
|
2
|
+
class IsoResource < AbstractResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def all
|
6
|
+
Oj.load(request("isos").run.body)["isos"].map do |x|
|
7
|
+
Iso.new(x, self, client)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](arg)
|
12
|
+
case arg
|
13
|
+
when Integer
|
14
|
+
begin
|
15
|
+
find(arg)
|
16
|
+
rescue Error::NotFound
|
17
|
+
end
|
18
|
+
when String
|
19
|
+
find_by(name: arg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(id)
|
24
|
+
Iso.new(
|
25
|
+
Oj.load(request("isos/#{id.to_i}").run.body)["iso"],
|
26
|
+
self,
|
27
|
+
client
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_by(name:)
|
32
|
+
j = Oj.load(request("isos", q: {name: name}).run.body)["isos"]
|
33
|
+
return if j.none?
|
34
|
+
j.each do |x|
|
35
|
+
return Iso.new(x, self, client)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -14,11 +14,12 @@ module Hcloud
|
|
14
14
|
method(:create).parameters.inject(query) do |r,x|
|
15
15
|
(var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
self,
|
20
|
-
client
|
21
|
-
|
17
|
+
j = Oj.load(request("servers", j: query, code: 200).run.body)
|
18
|
+
[
|
19
|
+
Action.new(j["action"], self, client),
|
20
|
+
Server.new(j["server"], self, client),
|
21
|
+
j["root_password"]
|
22
|
+
]
|
22
23
|
end
|
23
24
|
|
24
25
|
def all
|
data/lib/hcloud/version.rb
CHANGED
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.alpha3
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
|
-
type: :
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
type: :
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -100,9 +100,13 @@ files:
|
|
100
100
|
- lib/hcloud/action_resource.rb
|
101
101
|
- lib/hcloud/client.rb
|
102
102
|
- lib/hcloud/datacenter.rb
|
103
|
+
- lib/hcloud/datacenter_resource.rb
|
103
104
|
- lib/hcloud/entry_loader.rb
|
104
105
|
- lib/hcloud/errors.rb
|
105
106
|
- lib/hcloud/image.rb
|
107
|
+
- lib/hcloud/image_resource.rb
|
108
|
+
- lib/hcloud/iso.rb
|
109
|
+
- lib/hcloud/iso_resource.rb
|
106
110
|
- lib/hcloud/location.rb
|
107
111
|
- lib/hcloud/server.rb
|
108
112
|
- lib/hcloud/server_resource.rb
|