dockerapi 0.7.0 → 0.8.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: 756ada080034328ec7c5e7950d5565e6e7d3612bc92af58d9c8f89558a75f5c5
4
- data.tar.gz: cba4ac000ef8e9d4374bc36be4e87dd3c2227b2fa59cc062f24ad7a06de11c52
3
+ metadata.gz: 4e010cc4d2a5c4aa102ffe7cd9d58e7e4823bf4ba9079f9a622cb021dad8cd0e
4
+ data.tar.gz: 47163ffb19a35b4a473da7f88f40d5eac418a15638ccc8d91b6b1672a1af09f6
5
5
  SHA512:
6
- metadata.gz: 0c6c059fa47afc4749dac18c62d61a984c2874b41046c2926d7eb884a7761ea088fef4209deaf71fe5864e5351e8e96a975f29520760ae6559209d323dd4f4b6
7
- data.tar.gz: 25bad2ed4c92a2b5551d78e3a12833037623e7f26045a829b587d4136c383d7431ae7a3d17bf6b9ca139c4fcc060cbf07f15a61854a4a43f601455613174f943
6
+ metadata.gz: b48b06f99c46c936d4458a1908c08fe13f862ce7c63394077f52d8b621b2eb9e0be959682227f9b7ba59946f18b9098f2983a4bf1a781d16218ad66b08c730a3
7
+ data.tar.gz: ee2cb40d653054ea9bb559b9d39f43dd28556dcc25374033904f5c292403e371176ce1233636209bd5678df06f90436f6214aaafadd255d0b438cc870c318591
@@ -1,3 +1,22 @@
1
+ # 0.8.0
2
+
3
+ Add Docker::API::Swarm methods:
4
+ * init
5
+ * update
6
+ * inspect
7
+ * unlock_key
8
+ * unlock
9
+ * join
10
+ * leave
11
+
12
+ Add Docker::API::Node methods:
13
+ * list
14
+ * inspect
15
+ * update
16
+ * delete
17
+
18
+ Query parameters and request body json can now skip the validation step with `:skip_validation => true` option.
19
+
1
20
  # 0.7.0
2
21
 
3
22
  Major changes: Docker::API::Connection is now a regular class intead of a Singleton, allowing multiple connections to be stablished within the same program (replacing the connect_to implementation). To leverage this feature, API-related classes must be initialized and may or may not receive a Docker::API::Connection as parameter, or it'll connect to /var/run/docker.sock by default. For this reason, class methods were replaced with instance methods. Documentation will reflect this changes of implementation.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.7.0)
4
+ dockerapi (0.8.0)
5
5
  excon (~> 0.74.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -249,6 +249,56 @@ print response.data[:stream]
249
249
  exe.inspect(id)
250
250
  ```
251
251
 
252
+ ### Swarm
253
+ ```ruby
254
+ # Connect to local swarm endpoints
255
+ swarm = Docker::API::Swarm.new
256
+
257
+ # Init swarm
258
+ swarm.init({AdvertiseAddr: "local-ip-address:2377", ListenAddr: "0.0.0.0:4567"})
259
+
260
+ # Inspect swarm
261
+ swarm.inspect
262
+
263
+ # Update swarm
264
+ swarm.update(version, {rotateWorkerToken: true})
265
+ swarm.update(version, {rotateManagerToken: true})
266
+ swarm.update(version, {rotateManagerUnlockKey: true})
267
+ swarm.update(version, {EncryptionConfig: { AutoLockManagers: true }})
268
+
269
+ # Get unlock key
270
+ swarm.unlock_key
271
+
272
+ # Unlock swarm
273
+ swarm.unlock(UnlockKey: "key-value")
274
+
275
+ # Join an existing swarm
276
+ swarm.join(RemoteAddrs: ["remote-manager-address:2377"], JoinToken: "Join-Token-Here")
277
+
278
+ # Leave a swarm
279
+ swarm.leave(force: true)
280
+ ```
281
+
282
+ ### Node
283
+ ```ruby
284
+ # Connect to local node endpoints
285
+ node = Docker::API::Node.new
286
+
287
+ # List nodes
288
+ node.list
289
+
290
+ # Inspect node
291
+ node.inspect("node-id")
292
+
293
+ # Update node (version, Role and Availability must be present)
294
+ node.update("node-id", {version: "version"}, {Role: "worker", Availability: "pause" })
295
+ node.update("node-id", {version: "version"}, {Role: "worker", Availability: "active" })
296
+ node.update("node-id", {version: "version"}, {Role: "manager", Availability: "active" })
297
+
298
+ # Delete node
299
+ node.delete("node-id")
300
+ ```
301
+
252
302
  ### Connection
253
303
 
254
304
  By default Docker::API::Connection will connect to local Docker socket at `/var/run/docker.sock`. See examples below to use a different path or connect to a remote address.
@@ -311,6 +361,8 @@ response.success?
311
361
 
312
362
  `Docker::API::InvalidParameter` and `Docker::API::InvalidRequestBody` may be raised when an invalid option is passed as argument (ie: an option not described in Docker API documentation for request query parameters nor request body (json) parameters). Even if no errors were raised, consider validating the status code and/or message of the response to check if the Docker daemon has fulfilled the operation properly.
313
363
 
364
+ To completely skip the validation process, add `:skip_validation => true` in the hash to be validated.
365
+
314
366
  ## Development
315
367
 
316
368
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -319,28 +371,19 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
319
371
 
320
372
  ### Road to 1.0.0
321
373
 
322
- NS: Not Started
323
-
324
- WIP: Work In Progress
325
-
326
-
327
374
  | Class | Tests | Implementation | Refactoring |
328
375
  |---|---|---|---|
329
- | Container | Ok | Ok | NS |
330
- | Image | Ok | Ok | NS |
331
- | Volume | Ok | Ok | NS |
332
- | Network | Ok | Ok | NS |
333
- | System | Ok | Ok | NS |
334
- | Exec | Ok | Ok | NS |
335
- | Swarm | NS | NS | NS |
336
- | Node | NS | NS | NS |
337
- | Service | NS | NS | NS |
338
- | Task | NS | NS | NS |
339
- | Secret | NS | NS | NS |
340
-
341
- Misc:
342
- * ~~Improve response object~~
343
- * ~~Improve error objects~~
376
+ | Container | Ok | Ok | 7/24 |
377
+ | Image | Ok | Ok | 7/31 |
378
+ | Volume | Ok | Ok | 8/7 |
379
+ | Network | Ok | Ok | 8/7 |
380
+ | System | Ok | Ok | 8/7 |
381
+ | Exec | Ok | Ok | 8/7 |
382
+ | Swarm | Ok | Ok | 8/14 |
383
+ | Node | Ok | Ok | 8/14 |
384
+ | Service | 7/17 | 7/17 | 8/14 |
385
+ | Task | 7/17 | 7/17 | 8/14 |
386
+ | Secret | 7/17 | 7/17 | 8/14 |
344
387
 
345
388
  ## Contributing
346
389
 
@@ -3,16 +3,18 @@ module Docker
3
3
  class Base
4
4
 
5
5
  def initialize connection = nil
6
+ raise Docker::API::Error.new("Expect connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
6
7
  @connection = connection || Docker::API::Connection.new
7
8
  end
8
9
 
9
10
  private
10
11
 
11
- def base_path
12
+ def base_path # TODO: this method to be removed?
12
13
  "/"
13
14
  end
14
15
 
15
16
  def validate error, permitted, params
17
+ return if params[:skip_validation]
16
18
  unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
17
19
  raise error.new(permitted, unpermitted) if unpermitted.size > 0
18
20
  end
@@ -22,12 +24,12 @@ module Docker
22
24
  ## If value is another Hash, it should keep a json syntax {key:value}
23
25
  def hash_to_params h
24
26
  p = []
25
- h.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
27
+ h.delete_if{ | k, v | k.to_s == "skip_validation" }.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
26
28
  p.join("&").gsub(" ","")
27
29
  end
28
30
 
29
31
  def build_path path, params = {}
30
- p = path.is_a?(Array) ? ([base_path] << path).join("/") : path
32
+ p = path.is_a?(Array) ? ([base_path] << path).join("/") : path # TODO: this line to be removed?
31
33
  params.size > 0 ? [p, hash_to_params(params)].join("?") : p
32
34
  end
33
35
 
@@ -0,0 +1,26 @@
1
+ module Docker
2
+ module API
3
+ class Node < Docker::API::Base
4
+
5
+ def list params = {}
6
+ validate Docker::API::InvalidParameter, [:filters], params
7
+ @connection.get(build_path("/nodes", params))
8
+ end
9
+
10
+ def inspect name
11
+ @connection.get("/nodes/#{name}")
12
+ end
13
+
14
+ def update name, params = {}, body = {}
15
+ validate Docker::API::InvalidParameter, [:version], params
16
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
17
+ @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
18
+ end
19
+
20
+ def delete name, params = {}
21
+ validate Docker::API::InvalidParameter, [:force], params
22
+ @connection.delete(build_path("/nodes/#{name}", params))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module Docker
2
+ module API
3
+ class Swarm < Docker::API::Base
4
+
5
+ def init body = {}
6
+ validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec], body
7
+ @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
8
+ end
9
+
10
+ def update params = {}, body = {}
11
+ validate Docker::API::InvalidParameter, [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey], params
12
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults], body
13
+ @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
+ end
15
+
16
+ def inspect
17
+ @connection.get("/swarm")
18
+ end
19
+
20
+ def unlock_key
21
+ @connection.get(build_path("/swarm/unlockkey"))
22
+ end
23
+
24
+ def unlock body = {}
25
+ validate Docker::API::InvalidRequestBody, [:UnlockKey], body
26
+ @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
+ end
28
+
29
+ def join body = {}
30
+ validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken], body
31
+ @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
32
+ end
33
+
34
+ def leave params = {}
35
+ validate Docker::API::InvalidParameter, [:force], params
36
+ @connection.post(build_path("/swarm/leave", params))
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.7.0"
3
+ GEM_VERSION = "0.8.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -12,6 +12,8 @@ require "docker/api/volume"
12
12
  require "docker/api/network"
13
13
  require "docker/api/exec"
14
14
  require "docker/api/system"
15
+ require "docker/api/swarm"
16
+ require "docker/api/node"
15
17
 
16
18
  module Docker
17
19
  module API
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alysson A. Costa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -50,7 +50,9 @@ files:
50
50
  - lib/docker/api/exec.rb
51
51
  - lib/docker/api/image.rb
52
52
  - lib/docker/api/network.rb
53
+ - lib/docker/api/node.rb
53
54
  - lib/docker/api/response.rb
55
+ - lib/docker/api/swarm.rb
54
56
  - lib/docker/api/system.rb
55
57
  - lib/docker/api/version.rb
56
58
  - lib/docker/api/volume.rb