dockerapi 0.3.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ module Docker
2
+ module API
3
+ class Network < Docker::API::Base
4
+
5
+ def base_path
6
+ "/networks"
7
+ end
8
+
9
+ def list params = {}
10
+ validate Docker::API::InvalidParameter, [:filters], params
11
+ @connection.get(build_path("/networks", params))
12
+ end
13
+
14
+ def inspect name, params = {}
15
+ validate Docker::API::InvalidParameter, [:verbose, :scope], params
16
+ @connection.get(build_path([name], params))
17
+ end
18
+
19
+ def create body = {}
20
+ 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)
22
+ end
23
+
24
+ def remove name
25
+ @connection.delete(build_path([name]))
26
+ end
27
+
28
+ def prune params = {}
29
+ validate Docker::API::InvalidParameter, [:filters], params
30
+ @connection.post(build_path(["prune"], params))
31
+ end
32
+
33
+ def connect name, body = {}
34
+ 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)
36
+ end
37
+
38
+ def disconnect name, body = {}
39
+ 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)
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -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,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,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
@@ -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.3.0"
3
+ GEM_VERSION = "0.8.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -1,32 +1,32 @@
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 = {}
8
+ def list params = {}
9
9
  validate Docker::API::InvalidParameter, [:filters], params
10
- connection.get(build_path("/volumes", params))
10
+ @connection.get(build_path("/volumes", params))
11
11
  end
12
12
 
13
- def self.create body = {}
13
+ def create body = {}
14
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)
15
+ @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
16
16
  end
17
17
 
18
- def self.inspect name
19
- connection.get(build_path([name]))
18
+ def inspect name
19
+ @connection.get(build_path([name]))
20
20
  end
21
21
 
22
- def self.remove name, params = {}
22
+ def remove name, params = {}
23
23
  validate Docker::API::InvalidParameter, [:force], params
24
- connection.delete(build_path([name]))
24
+ @connection.delete(build_path([name]))
25
25
  end
26
26
 
27
- def self.prune params = {}
27
+ def prune params = {}
28
28
  validate Docker::API::InvalidParameter, [:filters], params
29
- connection.post(build_path(["prune"], params))
29
+ @connection.post(build_path(["prune"], params))
30
30
  end
31
31
 
32
32
  end
@@ -1,12 +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"
12
+ require "docker/api/network"
13
+ require "docker/api/exec"
9
14
  require "docker/api/system"
15
+ require "docker/api/swarm"
16
+ require "docker/api/node"
10
17
 
11
18
  module Docker
12
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.3.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-06-26 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
@@ -47,7 +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
52
+ - lib/docker/api/network.rb
53
+ - lib/docker/api/node.rb
54
+ - lib/docker/api/response.rb
55
+ - lib/docker/api/swarm.rb
51
56
  - lib/docker/api/system.rb
52
57
  - lib/docker/api/version.rb
53
58
  - lib/docker/api/volume.rb