dockerapi 0.12.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1,86 @@
1
- module Docker
2
- module API
3
- class Network < Docker::API::Base
4
-
5
- def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
- @connection.get(build_path("/networks", params))
8
- end
9
-
10
- def details name, params = {}
11
- validate Docker::API::InvalidParameter, [:verbose, :scope], params
12
- @connection.get(build_path([name], params))
13
- end
14
-
15
- def create body = {}
16
- validate Docker::API::InvalidRequestBody, [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels], body
17
- @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
18
- end
19
-
20
- def remove name
21
- @connection.delete(build_path([name]))
22
- end
23
-
24
- def prune params = {}
25
- validate Docker::API::InvalidParameter, [:filters], params
26
- @connection.post(build_path(["prune"], params))
27
- end
28
-
29
- def connect name, body = {}
30
- validate Docker::API::InvalidRequestBody, [:Container, :EndpointConfig], body
31
- @connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
32
- end
33
-
34
- def disconnect name, body = {}
35
- validate Docker::API::InvalidRequestBody, [:Container, :Force], body
36
- @connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
37
- end
38
-
39
- #################################################
40
- # Items in this area to be removed before 1.0.0 #
41
- #################################################
42
- def base_path
43
- "/networks"
44
- end
45
-
46
- def inspect *args
47
- return super.inspect if args.size == 0
48
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
49
- name, params = args[0], args[1] || {}
50
- details(name, params)
51
- end
52
- #################################################
53
-
54
- end
1
+ ##
2
+ # This class represents the Docker API endpoints regarding networks.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Network
4
+ class Docker::API::Network < Docker::API::Base
5
+
6
+ ##
7
+ # List networks.
8
+ #
9
+ # Docker API: GET /networks
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkList
11
+ #
12
+ # @param params [Hash]: Parameters that are appended to the URL.
13
+ def list params = {}
14
+ @connection.get(build_path("/networks", params))
15
+ end
16
+
17
+ ##
18
+ # Inspect a network.
19
+ #
20
+ # Docker API: GET /networks/{id}
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkInspect
22
+ #
23
+ # @param name [String]: The ID or name of the network.
24
+ # @param params [Hash]: Parameters that are appended to the URL.
25
+ def details name, params = {}
26
+ @connection.get(build_path("/networks/#{name}", params))
27
+ end
28
+
29
+ ##
30
+ # Create a network.
31
+ #
32
+ # Docker API: POST /networks/create
33
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkCreate
34
+ #
35
+ # @param body [Hash]: Request body to be sent as json.
36
+ def create body = {}
37
+ @connection.request(method: :post, path: "/networks/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
38
+ end
39
+
40
+ ##
41
+ # Remove a network.
42
+ #
43
+ # Docker API: DELETE /networks/{id}
44
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkDelete
45
+ #
46
+ # @param name [String]: The ID or name of the network.
47
+ def remove name
48
+ @connection.delete("/networks/#{name}")
55
49
  end
50
+
51
+ ##
52
+ # Delete unused networks.
53
+ #
54
+ # Docker API: POST /networks/prune
55
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkPrune
56
+ #
57
+ # @param params [Hash]: Parameters that are appended to the URL.
58
+ def prune params = {}
59
+ @connection.post(build_path("/networks/prune", params))
60
+ end
61
+
62
+ ##
63
+ # Connect a container to a network.
64
+ #
65
+ # Docker API: POST /networks/{id}/connect
66
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkConnect
67
+ #
68
+ # @param name [String]: The ID or name of the network.
69
+ # @param body [Hash]: Request body to be sent as json.
70
+ def connect name, body = {}
71
+ @connection.request(method: :post, path: "/networks/#{name}/connect", headers: {"Content-Type": "application/json"}, body: body.to_json)
72
+ end
73
+
74
+ ##
75
+ # Disconnect a container from a network.
76
+ #
77
+ # Docker API: POST /networks/{id}/disconnect
78
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkDisconnect
79
+ #
80
+ # @param name [String]: The ID or name of the network.
81
+ # @param body [Hash]: Request body to be sent as json.
82
+ def disconnect name, body = {}
83
+ @connection.request(method: :post, path: "/networks/#{name}/disconnect", headers: {"Content-Type": "application/json"}, body: body.to_json)
84
+ end
85
+
56
86
  end
@@ -1,38 +1,53 @@
1
- module Docker
2
- module API
3
- class Node < Docker::API::Base
1
+ # This class represents the Docker API endpoints regarding nodes.
2
+ #
3
+ # Nodes are instances of the Engine participating in a swarm. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Node
5
+ class Docker::API::Node < Docker::API::Base
4
6
 
5
- def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
- @connection.get(build_path("/nodes", params))
8
- end
9
-
10
- def update name, params = {}, body = {}
11
- validate Docker::API::InvalidParameter, [:version], params
12
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
13
- @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
- end
15
-
16
- def delete name, params = {}
17
- validate Docker::API::InvalidParameter, [:force], params
18
- @connection.delete(build_path("/nodes/#{name}", params))
19
- end
7
+ ##
8
+ # List nodes.
9
+ #
10
+ # Docker API: GET /nodes
11
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NodeList
12
+ #
13
+ # @param params [Hash]: Parameters that are appended to the URL.
14
+ def list params = {}
15
+ @connection.get(build_path("/nodes", params))
16
+ end
20
17
 
21
- def details name
22
- @connection.get("/nodes/#{name}")
23
- end
18
+ ##
19
+ # Update a node.
20
+ #
21
+ # Docker API: POST /nodes/{id}/update
22
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NodeUpdate
23
+ #
24
+ # @param name [String]: The ID or name of the node.
25
+ # @param params [Hash]: Parameters that are appended to the URL.
26
+ # @param body [Hash]: Request body to be sent as json.
27
+ def update name, params = {}, body = {}
28
+ @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
29
+ end
24
30
 
25
- #################################################
26
- # Items in this area to be removed before 1.0.0 #
27
- #################################################
28
- def inspect *args
29
- return super.inspect if args.size == 0
30
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
31
- name = args[0]
32
- details(name)
33
- end
34
- #################################################
31
+ ##
32
+ # Delete a node.
33
+ #
34
+ # Docker API: DELETE /nodes/{id}
35
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NodeDelete
36
+ #
37
+ # @param name [String]: The ID or name of the node.
38
+ # @param params [Hash]: Parameters that are appended to the URL.
39
+ def delete name, params = {}
40
+ @connection.delete(build_path("/nodes/#{name}", params))
41
+ end
35
42
 
36
- end
43
+ ##
44
+ # Inspect a node.
45
+ #
46
+ # Docker API: GET /nodes/{id}
47
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/NodeInspect
48
+ #
49
+ # @param name [String]: The ID or name of the node.
50
+ def details name
51
+ @connection.get("/nodes/#{name}")
37
52
  end
38
53
  end
@@ -11,7 +11,6 @@ class Docker::API::Plugin < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- validate Docker::API::InvalidParameter, [:filters], params
15
14
  @connection.get(build_path("/plugins", params))
16
15
  end
17
16
 
@@ -23,7 +22,6 @@ class Docker::API::Plugin < Docker::API::Base
23
22
  #
24
23
  # @param params [Hash]: Parameters that are appended to the URL.
25
24
  def privileges params = {}
26
- validate Docker::API::InvalidParameter, [:remote], params
27
25
  @connection.get(build_path("/plugins/privileges", params))
28
26
  end
29
27
 
@@ -41,7 +39,6 @@ class Docker::API::Plugin < Docker::API::Base
41
39
  #
42
40
  # @param authentication [Hash]: Authentication parameters.
43
41
  def install params = {}, privileges = [], authentication = {}
44
- validate Docker::API::InvalidParameter, [:remote, :name], params
45
42
  headers = {"Content-Type": "application/json"}
46
43
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
47
44
  @connection.request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json )
@@ -68,7 +65,6 @@ class Docker::API::Plugin < Docker::API::Base
68
65
  #
69
66
  # @param params [Hash]: Parameters that are appended to the URL.
70
67
  def remove name, params = {}
71
- validate Docker::API::InvalidParameter, [:force], params
72
68
  @connection.delete(build_path("/plugins/#{name}",params))
73
69
  end
74
70
 
@@ -82,7 +78,6 @@ class Docker::API::Plugin < Docker::API::Base
82
78
  #
83
79
  # @param params [Hash]: Parameters that are appended to the URL.
84
80
  def enable name, params = {}
85
- validate Docker::API::InvalidParameter, [:timeout], params
86
81
  @connection.post(build_path("/plugins/#{name}/enable", params))
87
82
  end
88
83
 
@@ -111,7 +106,6 @@ class Docker::API::Plugin < Docker::API::Base
111
106
  #
112
107
  # @param authentication [Hash]: Authentication parameters.
113
108
  def upgrade name, params = {}, privileges = [], authentication = {}
114
- validate Docker::API::InvalidParameter, [:remote], params
115
109
  headers = {"Content-Type": "application/json"}
116
110
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
117
111
  @connection.request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json )
@@ -1,25 +1,33 @@
1
- module Docker
2
- module API
3
- class Response < Excon::Response
4
- attr_reader(:json, :path)
1
+ ##
2
+ # Reponse class.
3
+ class Docker::API::Response < Excon::Response
4
+ attr_reader(:json, :path)
5
5
 
6
- def initialize data
7
- super data
8
- @json = parse_json @body
9
- @path = @data[:path]
10
- end
6
+ ##
7
+ # Initialize a new Response object.
8
+ #
9
+ # @params data [Object]: Reponse's data.
10
+ def initialize data
11
+ super data
12
+ @json = parse_json @body
13
+ @path = @data[:path]
14
+ end
11
15
 
12
- def success?
13
- (200..204).include? @status
14
- end
16
+ ##
17
+ # Returns true if Response status is in 200..204 range.
18
+ def success?
19
+ (200..204).include? @status
20
+ end
15
21
 
16
- private
22
+ private
17
23
 
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
+ ##
25
+ # Creates a json from Response data attribute.
26
+ #
27
+ # @params data [String]: String to be converted in json.
28
+ def parse_json data
29
+ return nil unless headers["Content-Type"] == "application/json"
30
+ return nil if data == ""
31
+ data.split("\r\n").size > 1 ? data.split("\r\n").map{ |e| eval(e) } : JSON.parse(data)
24
32
  end
25
33
  end
@@ -1,38 +1,32 @@
1
1
  # This class represents the Docker API endpoints regarding secrets.
2
2
  #
3
- # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
4
- #
5
3
  # Secrets are sensitive data that can be used by services. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
6
5
  class Docker::API::Secret < Docker::API::Base
7
6
 
8
7
  # List secrets
9
8
  #
10
9
  # Docker API: GET /secrets
11
- #
12
10
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretList
13
11
  #
14
12
  # @param params [Hash]: Parameters that are appended to the URL.
15
13
  def list params = {}
16
- validate Docker::API::InvalidParameter, [:filters], params
17
14
  @connection.get(build_path("/secrets",params))
18
15
  end
19
16
 
20
17
  # Create a secret
21
18
  #
22
19
  # Docker API: POST /secrets/create
23
- #
24
20
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretCreate
25
21
  #
26
22
  # @param body [Hash]: Request body to be sent as json.
27
23
  def create body = {}
28
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
29
24
  @connection.request(method: :post, path: "/secrets/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
30
25
  end
31
26
 
32
27
  # Inspect a secret
33
28
  #
34
29
  # Docker API: GET /secrets/{id}
35
- #
36
30
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretInspect
37
31
  #
38
32
  # @param name [String]: The ID or name of the secret.
@@ -43,24 +37,18 @@ class Docker::API::Secret < Docker::API::Base
43
37
  # Update a secret
44
38
  #
45
39
  # Docker API: POST /secrets/{id}/update
46
- #
47
40
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretUpdate
48
41
  #
49
42
  # @param name [String]: The ID or name of the secret.
50
- #
51
43
  # @param params [Hash]: Parameters that are appended to the URL.
52
- #
53
44
  # @param body [Hash]: Request body to be sent as json.
54
45
  def update name, params = {}, body = {}
55
- validate Docker::API::InvalidParameter, [:version], params
56
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
57
46
  @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
58
47
  end
59
48
 
60
49
  # Delete a secret
61
50
  #
62
51
  # Docker API: DELETE /secrets/{id}
63
- #
64
52
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretDelete
65
53
  #
66
54
  # @param name [String]: The ID or name of the secret.
@@ -1,94 +1,73 @@
1
1
  # This class represents the Docker API endpoints regarding services.
2
2
  #
3
- # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
4
- #
5
3
  # Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
6
5
  class Docker::API::Service < Docker::API::Base
7
6
 
8
7
  # List services
9
8
  #
10
9
  # Docker API: GET /services
11
- #
12
10
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
13
11
  #
14
12
  # @param params [Hash]: Parameters that are appended to the URL.
15
13
  def list params = {}
16
- validate Docker::API::InvalidParameter, [:filters], params
17
14
  @connection.get(build_path("/services", params))
18
15
  end
19
16
 
20
17
  # Create a service
21
18
  #
22
19
  # Docker API: POST /services/create
23
- #
24
20
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceCreate
25
21
  #
26
22
  # @param body [Hash]: Request body to be sent as json.
27
- #
28
23
  # @param authentication [Hash]: Authentication parameters.
29
24
  def create body = {}, authentication = {}
30
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
31
25
  headers = {"Content-Type": "application/json"}
32
- headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
26
+ headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
33
27
  @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
34
28
  end
35
29
 
36
30
  # Update a service
37
31
  #
38
32
  # Docker API: POST /services/{id}/update
39
- #
40
33
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceUpdate
41
34
  #
42
35
  # @param name [String]: The ID or name of the service.
43
- #
44
36
  # @param params [Hash]: Parameters that are appended to the URL.
45
- #
46
37
  # @param body [Hash]: Request body to be sent as json.
47
- #
48
38
  # @param authentication [Hash]: Authentication parameters.
49
39
  def update name, params = {}, body = {}, authentication = {}
50
40
  # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
51
- validate Docker::API::InvalidParameter, [:version, :registryAuthFrom, :rollback], params
52
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
53
41
  headers = {"Content-Type": "application/json"}
54
- headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
42
+ headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
55
43
  @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
56
44
  end
57
45
 
58
46
  # Inspect a service
59
47
  #
60
48
  # Docker API: GET /services/{id}
61
- #
62
49
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
63
50
  #
64
51
  # @param name [String]: The ID or name of the service.
65
- #
66
52
  # @param params [Hash]: Parameters that are appended to the URL.
67
53
  def details name, params = {}
68
- validate Docker::API::InvalidParameter, [:insertDefaults], params
69
54
  @connection.get(build_path("/services/#{name}", params))
70
55
  end
71
56
 
72
57
  # Get stdout and stderr logs from a service.
73
58
  #
74
- # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
75
- #
76
59
  # Docker API: GET /services/{id}/logs
77
- #
78
60
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceLogs
79
61
  #
80
62
  # @param name [String]: The ID or name of the service.
81
- #
82
63
  # @param params [Hash]: Parameters that are appended to the URL.
83
64
  def logs name, params = {}
84
- validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
85
65
  @connection.get(build_path("/services/#{name}/logs", params))
86
66
  end
87
67
 
88
68
  # Delete a service
89
69
  #
90
70
  # Docker API: DELETE /services/{id}
91
- #
92
71
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceDelete
93
72
  #
94
73
  # @param name [String]: The ID or name of the service.