dockerapi 0.11.0 → 0.16.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -0
- data/Gemfile.lock +3 -3
- data/README.md +97 -20
- data/dockerapi.gemspec +4 -3
- data/lib/docker/api/base.rb +101 -29
- data/lib/docker/api/config.rb +0 -4
- data/lib/docker/api/connection.rb +23 -17
- data/lib/docker/api/container.rb +306 -166
- data/lib/docker/api/error.rb +19 -3
- data/lib/docker/api/exec.rb +49 -40
- data/lib/docker/api/image.rb +201 -148
- data/lib/docker/api/network.rb +84 -54
- data/lib/docker/api/node.rb +47 -32
- data/lib/docker/api/plugin.rb +160 -0
- data/lib/docker/api/response.rb +27 -19
- data/lib/docker/api/secret.rb +1 -13
- data/lib/docker/api/service.rb +3 -24
- data/lib/docker/api/swarm.rb +70 -42
- data/lib/docker/api/system.rb +57 -26
- data/lib/docker/api/task.rb +10 -12
- data/lib/docker/api/version.rb +1 -1
- data/lib/docker/api/volume.rb +56 -41
- data/lib/dockerapi.rb +144 -0
- metadata +10 -6
data/lib/docker/api/network.rb
CHANGED
@@ -1,56 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
data/lib/docker/api/node.rb
CHANGED
@@ -1,38 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
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
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# This class represents the Docker API endpoints regarding plugins.
|
2
|
+
#
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Plugin
|
4
|
+
class Docker::API::Plugin < Docker::API::Base
|
5
|
+
|
6
|
+
# List plugins
|
7
|
+
#
|
8
|
+
# Docker API: GET /plugins
|
9
|
+
#
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginList
|
11
|
+
#
|
12
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
13
|
+
def list params = {}
|
14
|
+
@connection.get(build_path("/plugins", params))
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get plugin privileges
|
18
|
+
#
|
19
|
+
# Docker API: GET /plugins/privileges
|
20
|
+
#
|
21
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/GetPluginPrivileges
|
22
|
+
#
|
23
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
24
|
+
def privileges params = {}
|
25
|
+
@connection.get(build_path("/plugins/privileges", params))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Install a plugin
|
29
|
+
#
|
30
|
+
# Pulls and installs a plugin. After the plugin is installed, it can be enabled using the POST /plugins/{name}/enable endpoint.
|
31
|
+
#
|
32
|
+
# Docker API: POST /plugins/pull
|
33
|
+
#
|
34
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginPull
|
35
|
+
#
|
36
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
37
|
+
#
|
38
|
+
# @param privileges [Array]: Plugin privileges to be sent as json in request body.
|
39
|
+
#
|
40
|
+
# @param authentication [Hash]: Authentication parameters.
|
41
|
+
def install params = {}, privileges = [], authentication = {}
|
42
|
+
headers = {"Content-Type": "application/json"}
|
43
|
+
headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
|
44
|
+
@connection.request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json )
|
45
|
+
end
|
46
|
+
|
47
|
+
# Inspect a plugin
|
48
|
+
#
|
49
|
+
# Docker API: GET /plugins/{name}/json
|
50
|
+
#
|
51
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginInspect
|
52
|
+
#
|
53
|
+
# @param name [String]: The ID or name of the plugin.
|
54
|
+
def details name
|
55
|
+
@connection.get("/plugins/#{name}/json")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Remove a plugin
|
59
|
+
#
|
60
|
+
# Docker API: DELETE /plugins/{name}
|
61
|
+
#
|
62
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginDelete
|
63
|
+
#
|
64
|
+
# @param name [String]: The ID or name of the plugin.
|
65
|
+
#
|
66
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
67
|
+
def remove name, params = {}
|
68
|
+
@connection.delete(build_path("/plugins/#{name}",params))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Enable a plugin
|
72
|
+
#
|
73
|
+
# Docker API: POST /plugins/{name}/enable
|
74
|
+
#
|
75
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginEnable
|
76
|
+
#
|
77
|
+
# @param name [String]: The ID or name of the plugin.
|
78
|
+
#
|
79
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
80
|
+
def enable name, params = {}
|
81
|
+
@connection.post(build_path("/plugins/#{name}/enable", params))
|
82
|
+
end
|
83
|
+
|
84
|
+
# Disable a plugin
|
85
|
+
#
|
86
|
+
# Docker API: POST /plugins/{name}/disable
|
87
|
+
#
|
88
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginDisable
|
89
|
+
#
|
90
|
+
# @param name [String]: The ID or name of the plugin.
|
91
|
+
def disable name
|
92
|
+
@connection.post("/plugins/#{name}/disable")
|
93
|
+
end
|
94
|
+
|
95
|
+
# Upgrade a plugin
|
96
|
+
#
|
97
|
+
# Docker API: POST /plugins/{name}/upgrade
|
98
|
+
#
|
99
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginUpgrade
|
100
|
+
#
|
101
|
+
# @param name [String]: The ID or name of the plugin.
|
102
|
+
#
|
103
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
104
|
+
#
|
105
|
+
# @param privileges [Array]: Plugin privileges to be sent as json in request body.
|
106
|
+
#
|
107
|
+
# @param authentication [Hash]: Authentication parameters.
|
108
|
+
def upgrade name, params = {}, privileges = [], authentication = {}
|
109
|
+
headers = {"Content-Type": "application/json"}
|
110
|
+
headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
|
111
|
+
@connection.request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json )
|
112
|
+
end
|
113
|
+
|
114
|
+
# Create a plugin
|
115
|
+
#
|
116
|
+
# Docker API: POST /plugins/create
|
117
|
+
#
|
118
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginCreate
|
119
|
+
#
|
120
|
+
# @param name [String]: The ID or name of the plugin.
|
121
|
+
#
|
122
|
+
# @param path [String]: Path to tar file that contains rootfs folder and config.json file.
|
123
|
+
def create name, path
|
124
|
+
file = File.open( File.expand_path( path ) , "r")
|
125
|
+
response = @connection.request(method: :post, path: "/plugins/create?name=#{name}", body: file.read.to_s )
|
126
|
+
file.close
|
127
|
+
response
|
128
|
+
end
|
129
|
+
|
130
|
+
# Push a plugin to the registry.
|
131
|
+
#
|
132
|
+
# Docker API: POST /plugins/{name}/push
|
133
|
+
#
|
134
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginPush
|
135
|
+
#
|
136
|
+
# @param name [String]: The ID or name of the plugin.
|
137
|
+
#
|
138
|
+
# @param authentication [Hash]: Authentication parameters.
|
139
|
+
def push name, authentication = {}
|
140
|
+
if authentication.keys.size > 0
|
141
|
+
@connection.request(method: :post, path: "/plugins/#{name}/push", headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)})
|
142
|
+
else
|
143
|
+
@connection.post("/plugins/#{name}/push")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Configure a plugin
|
148
|
+
#
|
149
|
+
# Docker API: POST /plugins/{name}/set
|
150
|
+
#
|
151
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PluginSet
|
152
|
+
#
|
153
|
+
# @param name [String]: The ID or name of the plugin.
|
154
|
+
#
|
155
|
+
# @param config [Array]: Plugin configuration to be sent as json in request body.
|
156
|
+
def configure name, config
|
157
|
+
@connection.request(method: :post, path: "/plugins/#{name}/set", headers: {"Content-Type": "application/json"}, body:config.to_json)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/lib/docker/api/response.rb
CHANGED
@@ -1,25 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
##
|
2
|
+
# Reponse class.
|
3
|
+
class Docker::API::Response < Excon::Response
|
4
|
+
attr_reader(:json, :path)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
22
|
+
private
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
data/lib/docker/api/secret.rb
CHANGED
@@ -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.
|