hcloud 0.1.0.pre.alpha0 → 0.1.0.pre.alpha1

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
  SHA1:
3
- metadata.gz: 9cdf9035c8dc3386625887bdb9e02a25f8fe2c0b
4
- data.tar.gz: c3b771e29328e7708f3f7251eb135a14335b0294
3
+ metadata.gz: 864f8cc69037ab4a88ff373bc5a89fb89176dc32
4
+ data.tar.gz: e4da295f210321c4021414a50d100edda921b741
5
5
  SHA512:
6
- metadata.gz: fb30c007428c885f476da3f59bd7c9bf918b0362a775822d31cc0ebb8a623d68fcbee05daea20d112d93acf4af21791a5ba36b24ddb6bf78bde184259ef71324
7
- data.tar.gz: f6a1ae0b6cbc07df8786655579c27893c5e213b709d020064e335f0a7f0a031b099c4368c318f58e3e8c5fa415460350e6b3c643d06cc77d8080567f871bc96e
6
+ metadata.gz: 800337279a9b7d2c0c8a8aace03da6e2ca9b352ce33061533ab79096dd726c709b5c904d79c37754b54eb4f039f0e9728bbd4ca5ffcd3970319370445a0641a1
7
+ data.tar.gz: 4879ddfb318509306ae1bde0a588935d6086bd613c4306dec4c3f913f82ce4ec02c11b4fd8b08bd236beea7af8802994c43b7fee4f8dfe77c9cca38afc129216
data/lib/hcloud.rb CHANGED
@@ -13,4 +13,5 @@ module Hcloud
13
13
  autoload :Location, 'hcloud/location'
14
14
  autoload :Image, 'hcloud/image'
15
15
  autoload :Action, 'hcloud/action'
16
+ autoload :ActionResource, 'hcloud/action_resource'
16
17
  end
@@ -1,8 +1,17 @@
1
1
  module Hcloud
2
2
  class AbstractResource
3
- attr_reader :client
4
- def initialize(client:)
3
+ attr_reader :client, :parent, :base_path
4
+
5
+ def initialize(client:, parent: nil, base_path: "")
5
6
  @client = client
7
+ @parent = parent
8
+ @base_path = base_path
9
+ end
10
+
11
+ def each(&block)
12
+ all.each do |member|
13
+ block.call(member)
14
+ end
6
15
  end
7
16
 
8
17
  protected
@@ -0,0 +1,13 @@
1
+
2
+ module Hcloud
3
+ class ActionResource < AbstractResource
4
+ include Enumerable
5
+
6
+ def all
7
+ Oj.load(request(base_path + "/actions").run.body)["actions"].map do |x|
8
+ Action.new(x, self, client)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
data/lib/hcloud/server.rb CHANGED
@@ -29,17 +29,80 @@ module Hcloud
29
29
  end
30
30
 
31
31
  def destroy
32
- Action.new(
33
- Oj.load(request(base_path, method: :delete).run.body)["action"],
34
- parent,
35
- client
36
- )
32
+ action(request(base_path, method: :delete))[0]
33
+ end
34
+
35
+ def enable_rescue(type: "linux64", ssh_keys: [])
36
+ query = {}
37
+ method(:enable_rescue).parameters.inject(query) do |r,x|
38
+ (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
39
+ end
40
+ a , j = action(request(base_path("actions/enable_rescue"), j: query))
41
+ [a, j["root_password"]]
42
+ end
43
+
44
+ def reset_password
45
+ a , j = action(request(base_path("actions/reset_password"), method: :post))
46
+ [a, j["root_password"]]
47
+ end
48
+
49
+ def create_image(description: nil, type: nil)
50
+ query = {}
51
+ method(:create_image).parameters.inject(query) do |r,x|
52
+ (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
53
+ end
54
+ a , j = action(request(base_path("actions/create_image"), j: query))
55
+ [a, Image.new(j["image"], parent, client)]
56
+ end
57
+
58
+ def rebuild(image:)
59
+ a , j = action(request(base_path("actions/rebuild"), j: {image: image}))
60
+ [a, j["root_password"]]
61
+ end
62
+
63
+ def change_type(server_type:, upgrade_disk: nil)
64
+ query = {}
65
+ method(:change_type).parameters.inject(query) do |r,x|
66
+ (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
67
+ end
68
+ action(request(base_path("actions/change_type"), j: query))[0]
69
+ end
70
+
71
+ def enable_backup(backup_window:)
72
+ action(request(base_path("actions/enable_backup"),
73
+ j: {backup_window: backup_window}))[0]
74
+ end
75
+
76
+ def attach_iso(iso:)
77
+ action(request(base_path("actions/attach_iso"),
78
+ j: {iso: iso}))[0]
79
+ end
80
+
81
+ %w(
82
+ poweron poweroff shutdown reboot reset
83
+ disable_rescue disable_backup detach_iso
84
+ ).each do |action|
85
+ define_method(action) do
86
+ action(request(base_path("actions/#{action}"), method: :post))[0]
87
+ end
88
+ end
89
+
90
+ def actions
91
+ ActionResource.new(client: client, parent: self, base_path: base_path)
37
92
  end
38
93
 
39
94
  private
40
95
 
41
- def base_path
42
- return "servers/#{id}" unless id.nil?
96
+ def action(request)
97
+ j = Oj.load(request.run.body)
98
+ [
99
+ Action.new(j["action"],parent,client),
100
+ j
101
+ ]
102
+ end
103
+
104
+ def base_path(ext=nil)
105
+ return ["servers/#{id}",ext].compact.join("/") unless id.nil?
43
106
  raise ResourcePathError, "Unable to build resource path. Id is nil."
44
107
  end
45
108
 
@@ -26,12 +26,5 @@ module Hcloud
26
26
  Server.new(x, self, client)
27
27
  end
28
28
  end
29
-
30
- def each(&block)
31
- all.each do |member|
32
- block.call(member)
33
- end
34
- end
35
-
36
29
  end
37
30
  end
@@ -1,3 +1,3 @@
1
1
  module Hcloud
2
- VERSION = "0.1.0-alpha0"
2
+ VERSION = "0.1.0-alpha1"
3
3
  end
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.alpha0
4
+ version: 0.1.0.pre.alpha1
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-27 00:00:00.000000000 Z
11
+ date: 2018-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,6 +97,7 @@ files:
97
97
  - lib/hcloud.rb
98
98
  - lib/hcloud/abstract_resource.rb
99
99
  - lib/hcloud/action.rb
100
+ - lib/hcloud/action_resource.rb
100
101
  - lib/hcloud/client.rb
101
102
  - lib/hcloud/datacenter.rb
102
103
  - lib/hcloud/entry_loader.rb