dockerapi 0.4.0 → 0.8.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.
@@ -2,42 +2,44 @@ module Docker
2
2
  module API
3
3
  class Network < Docker::API::Base
4
4
 
5
- def self.base_path
5
+ def base_path
6
6
  "/networks"
7
7
  end
8
8
 
9
- def self.list params = {}
10
- validate Docker::API::InvalidParameter, [:filters], params
11
- connection.get(build_path("/networks", params))
9
+ def inspect *args
10
+ return super.inspect if args.size == 0
11
+ name, params = args[0], args[1] || {}
12
+ validate Docker::API::InvalidParameter, [:verbose, :scope], params
13
+ @connection.get(build_path([name], params))
12
14
  end
13
15
 
14
- def self.inspect name, params = {}
15
- validate Docker::API::InvalidParameter, [:verbose, :scope], params
16
- connection.get(build_path([name], params))
16
+ def list params = {}
17
+ validate Docker::API::InvalidParameter, [:filters], params
18
+ @connection.get(build_path("/networks", params))
17
19
  end
18
20
 
19
- def self.create body = {}
21
+ def create body = {}
20
22
  validate Docker::API::InvalidRequestBody, [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels], body
21
- connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
23
+ @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
22
24
  end
23
25
 
24
- def self.remove name
25
- connection.delete(build_path([name]))
26
+ def remove name
27
+ @connection.delete(build_path([name]))
26
28
  end
27
29
 
28
- def self.prune params = {}
30
+ def prune params = {}
29
31
  validate Docker::API::InvalidParameter, [:filters], params
30
- connection.post(build_path(["prune"], params))
32
+ @connection.post(build_path(["prune"], params))
31
33
  end
32
34
 
33
- def self.connect name, body = {}
35
+ def connect name, body = {}
34
36
  validate Docker::API::InvalidRequestBody, [:Container, :EndpointConfig], body
35
- connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
37
+ @connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
36
38
  end
37
39
 
38
- def self.disconnect name, body = {}
40
+ def disconnect name, body = {}
39
41
  validate Docker::API::InvalidRequestBody, [:Container, :Force], body
40
- connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
42
+ @connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
41
43
  end
42
44
 
43
45
  end
@@ -0,0 +1,28 @@
1
+ module Docker
2
+ module API
3
+ class Node < Docker::API::Base
4
+
5
+ def inspect *args
6
+ return super.inspect if args.size == 0
7
+ name = args[0]
8
+ @connection.get("/nodes/#{name}")
9
+ end
10
+
11
+ def list params = {}
12
+ validate Docker::API::InvalidParameter, [:filters], params
13
+ @connection.get(build_path("/nodes", params))
14
+ end
15
+
16
+ def update name, params = {}, body = {}
17
+ validate Docker::API::InvalidParameter, [:version], params
18
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
19
+ @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
20
+ end
21
+
22
+ def delete name, params = {}
23
+ validate Docker::API::InvalidParameter, [:force], params
24
+ @connection.delete(build_path("/nodes/#{name}", params))
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module Docker
2
+ module API
3
+ class Response < Excon::Response
4
+ attr_reader(:json, :path)
5
+
6
+ def initialize data
7
+ super data
8
+ @json = parse_json @body
9
+ @path = @data[:path]
10
+ end
11
+
12
+ def success?
13
+ (200..204).include? @status
14
+ end
15
+
16
+ private
17
+
18
+ def parse_json data
19
+ return nil unless headers["Content-Type"] == "application/json"
20
+ return nil if data == ""
21
+ data.split("\r\n").size > 1 ? data.split("\r\n").map{ |e| eval(e) } : JSON.parse(data)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
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
+ caller.each { | el | return super.inspect if el.match(/inspector/) }
18
+ @connection.get("/swarm")
19
+ end
20
+
21
+ def unlock_key
22
+ @connection.get(build_path("/swarm/unlockkey"))
23
+ end
24
+
25
+ def unlock body = {}
26
+ validate Docker::API::InvalidRequestBody, [:UnlockKey], body
27
+ @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
28
+ end
29
+
30
+ def join body = {}
31
+ validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken], body
32
+ @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
33
+ end
34
+
35
+ def leave params = {}
36
+ validate Docker::API::InvalidParameter, [:force], params
37
+ @connection.post(build_path("/swarm/leave", params))
38
+ end
39
+ end
40
+ end
41
+ end
@@ -2,11 +2,33 @@ require "json"
2
2
  module Docker
3
3
  module API
4
4
  class System < Docker::API::Base
5
-
6
- def self.auth body = {}
5
+
6
+ def auth body = {}
7
7
  validate Docker::API::InvalidRequestBody, [:username, :password, :email, :serveraddress, :identitytoken], body
8
- connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
8
+ @connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
9
9
  end
10
+
11
+ def events params = {}
12
+ validate Docker::API::InvalidParameter, [:since, :until, :filters], params
13
+ @connection.request(method: :get, path: build_path("/events", params), response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect } )
14
+ end
15
+
16
+ def ping
17
+ @connection.get("/_ping")
18
+ end
19
+
20
+ def info
21
+ @connection.get("/info")
22
+ end
23
+
24
+ def version
25
+ @connection.get("/version")
26
+ end
27
+
28
+ def df
29
+ @connection.get("/system/df")
30
+ end
31
+
10
32
  end
11
33
  end
12
34
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.4.0"
3
+ GEM_VERSION = "0.8.1"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -1,32 +1,34 @@
1
1
  module Docker
2
2
  module API
3
3
  class Volume < Docker::API::Base
4
- def self.base_path
4
+ def base_path
5
5
  "/volumes"
6
6
  end
7
7
 
8
- def self.list params = {}
9
- validate Docker::API::InvalidParameter, [:filters], params
10
- connection.get(build_path("/volumes", params))
8
+ def inspect *args
9
+ return super.inspect if args.size == 0
10
+ name = args[0]
11
+ @connection.get(build_path([name]))
11
12
  end
12
13
 
13
- def self.create body = {}
14
- validate Docker::API::InvalidRequestBody, [:Name, :Driver, :DriverOpts, :Labels], body
15
- connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
+ def list params = {}
15
+ validate Docker::API::InvalidParameter, [:filters], params
16
+ @connection.get(build_path("/volumes", params))
16
17
  end
17
18
 
18
- def self.inspect name
19
- connection.get(build_path([name]))
19
+ def create body = {}
20
+ validate Docker::API::InvalidRequestBody, [:Name, :Driver, :DriverOpts, :Labels], body
21
+ @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
20
22
  end
21
23
 
22
- def self.remove name, params = {}
24
+ def remove name, params = {}
23
25
  validate Docker::API::InvalidParameter, [:force], params
24
- connection.delete(build_path([name]))
26
+ @connection.delete(build_path([name]))
25
27
  end
26
28
 
27
- def self.prune params = {}
29
+ def prune params = {}
28
30
  validate Docker::API::InvalidParameter, [:filters], params
29
- connection.post(build_path(["prune"], params))
31
+ @connection.post(build_path(["prune"], params))
30
32
  end
31
33
 
32
34
  end
@@ -1,13 +1,19 @@
1
- require "docker/api/version"
1
+ require "excon"
2
+ require "json"
2
3
 
4
+ require "docker/api/version"
3
5
  require "docker/api/error"
4
6
  require "docker/api/connection"
7
+ require "docker/api/response"
5
8
  require "docker/api/base"
6
9
  require "docker/api/container"
7
10
  require "docker/api/image"
8
11
  require "docker/api/volume"
9
12
  require "docker/api/network"
13
+ require "docker/api/exec"
10
14
  require "docker/api/system"
15
+ require "docker/api/swarm"
16
+ require "docker/api/node"
11
17
 
12
18
  module Docker
13
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.4.0
4
+ version: 0.8.1
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-06-28 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -47,8 +47,12 @@ files:
47
47
  - lib/docker/api/connection.rb
48
48
  - lib/docker/api/container.rb
49
49
  - lib/docker/api/error.rb
50
+ - lib/docker/api/exec.rb
50
51
  - lib/docker/api/image.rb
51
52
  - lib/docker/api/network.rb
53
+ - lib/docker/api/node.rb
54
+ - lib/docker/api/response.rb
55
+ - lib/docker/api/swarm.rb
52
56
  - lib/docker/api/system.rb
53
57
  - lib/docker/api/version.rb
54
58
  - lib/docker/api/volume.rb