dockerapi 0.10.0 → 0.15.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.
@@ -3,18 +3,14 @@ module Docker
3
3
  class Node < Docker::API::Base
4
4
 
5
5
  def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
6
  @connection.get(build_path("/nodes", params))
8
7
  end
9
8
 
10
9
  def update name, params = {}, body = {}
11
- validate Docker::API::InvalidParameter, [:version], params
12
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
13
10
  @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
11
  end
15
12
 
16
13
  def delete name, params = {}
17
- validate Docker::API::InvalidParameter, [:force], params
18
14
  @connection.delete(build_path("/nodes/#{name}", params))
19
15
  end
20
16
 
@@ -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
@@ -0,0 +1,66 @@
1
+ # This class represents the Docker API endpoints regarding secrets.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
4
+ #
5
+ # Secrets are sensitive data that can be used by services. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Secret < Docker::API::Base
7
+
8
+ # List secrets
9
+ #
10
+ # Docker API: GET /secrets
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ @connection.get(build_path("/secrets",params))
17
+ end
18
+
19
+ # Create a secret
20
+ #
21
+ # Docker API: POST /secrets/create
22
+ #
23
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretCreate
24
+ #
25
+ # @param body [Hash]: Request body to be sent as json.
26
+ def create body = {}
27
+ @connection.request(method: :post, path: "/secrets/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
28
+ end
29
+
30
+ # Inspect a secret
31
+ #
32
+ # Docker API: GET /secrets/{id}
33
+ #
34
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretInspect
35
+ #
36
+ # @param name [String]: The ID or name of the secret.
37
+ def details name
38
+ @connection.get("/secrets/#{name}")
39
+ end
40
+
41
+ # Update a secret
42
+ #
43
+ # Docker API: POST /secrets/{id}/update
44
+ #
45
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretUpdate
46
+ #
47
+ # @param name [String]: The ID or name of the secret.
48
+ #
49
+ # @param params [Hash]: Parameters that are appended to the URL.
50
+ #
51
+ # @param body [Hash]: Request body to be sent as json.
52
+ def update name, params = {}, body = {}
53
+ @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
54
+ end
55
+
56
+ # Delete a secret
57
+ #
58
+ # Docker API: DELETE /secrets/{id}
59
+ #
60
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretDelete
61
+ #
62
+ # @param name [String]: The ID or name of the secret.
63
+ def delete name
64
+ @connection.delete("/secrets/#{name}")
65
+ end
66
+ end
@@ -1,42 +1,92 @@
1
- module Docker
2
- module API
3
- class Service < Docker::API::Base
1
+ # This class represents the Docker API endpoints regarding services.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
4
+ #
5
+ # Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Service < Docker::API::Base
4
7
 
5
- def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
- @connection.get(build_path("/services", params))
8
- end
9
-
10
- def create body = {}, authentication = {}
11
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
12
- headers = {"Content-Type": "application/json"}
13
- headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
14
- @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
15
- end
8
+ # List services
9
+ #
10
+ # Docker API: GET /services
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ @connection.get(build_path("/services", params))
17
+ end
16
18
 
17
- def update name, params = {}, body = {}, authentication = {}
18
- # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
19
- validate Docker::API::InvalidParameter, [:version, :registryAuthFrom, :rollback], params
20
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
21
- headers = {"Content-Type": "application/json"}
22
- headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
23
- @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
24
- end
19
+ # Create a service
20
+ #
21
+ # Docker API: POST /services/create
22
+ #
23
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceCreate
24
+ #
25
+ # @param body [Hash]: Request body to be sent as json.
26
+ #
27
+ # @param authentication [Hash]: Authentication parameters.
28
+ def create body = {}, authentication = {}
29
+ headers = {"Content-Type": "application/json"}
30
+ headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
31
+ @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
32
+ end
25
33
 
26
- def details name, params = {}
27
- validate Docker::API::InvalidParameter, [:insertDefaults], params
28
- @connection.get(build_path("/services/#{name}", params))
29
- end
34
+ # Update a service
35
+ #
36
+ # Docker API: POST /services/{id}/update
37
+ #
38
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceUpdate
39
+ #
40
+ # @param name [String]: The ID or name of the service.
41
+ #
42
+ # @param params [Hash]: Parameters that are appended to the URL.
43
+ #
44
+ # @param body [Hash]: Request body to be sent as json.
45
+ #
46
+ # @param authentication [Hash]: Authentication parameters.
47
+ def update name, params = {}, body = {}, authentication = {}
48
+ # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
49
+ headers = {"Content-Type": "application/json"}
50
+ headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
51
+ @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
52
+ end
30
53
 
31
- def logs name, params = {}
32
- validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
33
- @connection.get(build_path("/services/#{name}/logs", params))
34
- end
54
+ # Inspect a service
55
+ #
56
+ # Docker API: GET /services/{id}
57
+ #
58
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
59
+ #
60
+ # @param name [String]: The ID or name of the service.
61
+ #
62
+ # @param params [Hash]: Parameters that are appended to the URL.
63
+ def details name, params = {}
64
+ @connection.get(build_path("/services/#{name}", params))
65
+ end
35
66
 
36
- def delete name
37
- @connection.delete("/services/#{name}")
38
- end
67
+ # Get stdout and stderr logs from a service.
68
+ #
69
+ # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
70
+ #
71
+ # Docker API: GET /services/{id}/logs
72
+ #
73
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceLogs
74
+ #
75
+ # @param name [String]: The ID or name of the service.
76
+ #
77
+ # @param params [Hash]: Parameters that are appended to the URL.
78
+ def logs name, params = {}
79
+ @connection.get(build_path("/services/#{name}/logs", params))
80
+ end
39
81
 
40
- end
82
+ # Delete a service
83
+ #
84
+ # Docker API: DELETE /services/{id}
85
+ #
86
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceDelete
87
+ #
88
+ # @param name [String]: The ID or name of the service.
89
+ def delete name
90
+ @connection.delete("/services/#{name}")
41
91
  end
42
- end
92
+ end
@@ -3,13 +3,10 @@ module Docker
3
3
  class Swarm < Docker::API::Base
4
4
 
5
5
  def init body = {}
6
- validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec], body
7
6
  @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
8
7
  end
9
8
 
10
9
  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
10
  @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
11
  end
15
12
 
@@ -22,17 +19,14 @@ module Docker
22
19
  end
23
20
 
24
21
  def unlock body = {}
25
- validate Docker::API::InvalidRequestBody, [:UnlockKey], body
26
22
  @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
23
  end
28
24
 
29
25
  def join body = {}
30
- validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken], body
31
26
  @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
32
27
  end
33
28
 
34
29
  def leave params = {}
35
- validate Docker::API::InvalidParameter, [:force], params
36
30
  @connection.post(build_path("/swarm/leave", params))
37
31
  end
38
32
 
@@ -1,34 +1,65 @@
1
- require "json"
2
- module Docker
3
- module API
4
- class System < Docker::API::Base
1
+ ##
2
+ # This class represents the Docker API system related endpoints.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/System
4
+ class Docker::API::System < Docker::API::Base
5
5
 
6
- def auth body = {}
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)
9
- end
6
+ ##
7
+ # Validate credentials for a registry and, if available, get an identity token for accessing the registry without password.
8
+ #
9
+ # Docker API: POST /auth
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemAuth
11
+ #
12
+ # @param body [Hash]: Request body to be sent as json.
13
+ def auth body = {}
14
+ @connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
15
+ end
10
16
 
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
17
+ ##
18
+ # Stream real-time events from the server.
19
+ #
20
+ # Docker API: GET /events
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents
22
+ #
23
+ # @param params [Hash]: Parameters that are appended to the URL.
24
+ # @param &block: Replace the default output to stdout behavior.
25
+ def events params = {}, &block
26
+ @connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block.call : default_streamer )
27
+ end
15
28
 
16
- def ping
17
- @connection.get("/_ping")
18
- end
29
+ ##
30
+ # This is a dummy endpoint you can use to test if the server is accessible.
31
+ #
32
+ # Docker API: GET /_ping
33
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemPing
34
+ def ping
35
+ @connection.get("/_ping")
36
+ end
19
37
 
20
- def info
21
- @connection.get("/info")
22
- end
38
+ ##
39
+ # Get system information.
40
+ #
41
+ # Docker API: GET /info
42
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemInfo
43
+ def info
44
+ @connection.get("/info")
45
+ end
23
46
 
24
- def version
25
- @connection.get("/version")
26
- end
47
+ ##
48
+ # Returns the version of Docker that is running and various information about the system that Docker is running on.
49
+ #
50
+ # Docker API: GET /version
51
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemVersion
52
+ def version
53
+ @connection.get("/version")
54
+ end
27
55
 
28
- def df
29
- @connection.get("/system/df")
30
- end
31
-
32
- end
56
+ ##
57
+ # Get data usage information.
58
+ #
59
+ # Docker API: GET /system/df
60
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemDataUsage
61
+ def df
62
+ @connection.get("/system/df")
33
63
  end
64
+
34
65
  end