dockerapi 0.8.1 → 0.13.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.
@@ -2,24 +2,15 @@ module Docker
2
2
  module API
3
3
  class Network < Docker::API::Base
4
4
 
5
- def base_path
6
- "/networks"
5
+ def list params = {}
6
+ @connection.get(build_path("/networks", params))
7
7
  end
8
8
 
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
9
+ def details name, params = {}
13
10
  @connection.get(build_path([name], params))
14
11
  end
15
12
 
16
- def list params = {}
17
- validate Docker::API::InvalidParameter, [:filters], params
18
- @connection.get(build_path("/networks", params))
19
- end
20
-
21
13
  def create body = {}
22
- validate Docker::API::InvalidRequestBody, [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels], body
23
14
  @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
24
15
  end
25
16
 
@@ -28,20 +19,32 @@ module Docker
28
19
  end
29
20
 
30
21
  def prune params = {}
31
- validate Docker::API::InvalidParameter, [:filters], params
32
22
  @connection.post(build_path(["prune"], params))
33
23
  end
34
24
 
35
25
  def connect name, body = {}
36
- validate Docker::API::InvalidRequestBody, [:Container, :EndpointConfig], body
37
26
  @connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
38
27
  end
39
28
 
40
29
  def disconnect name, body = {}
41
- validate Docker::API::InvalidRequestBody, [:Container, :Force], body
42
30
  @connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
43
31
  end
44
32
 
33
+ #################################################
34
+ # Items in this area to be removed before 1.0.0 #
35
+ #################################################
36
+ def base_path
37
+ "/networks"
38
+ end
39
+
40
+ def inspect *args
41
+ return super.inspect if args.size == 0
42
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
43
+ name, params = args[0], args[1] || {}
44
+ details(name, params)
45
+ end
46
+ #################################################
47
+
45
48
  end
46
49
  end
47
50
  end
@@ -2,27 +2,33 @@ module Docker
2
2
  module API
3
3
  class Node < Docker::API::Base
4
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
5
  def list params = {}
12
- validate Docker::API::InvalidParameter, [:filters], params
13
6
  @connection.get(build_path("/nodes", params))
14
7
  end
15
8
 
16
9
  def update name, params = {}, body = {}
17
- validate Docker::API::InvalidParameter, [:version], params
18
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
19
10
  @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
20
11
  end
21
12
 
22
13
  def delete name, params = {}
23
- validate Docker::API::InvalidParameter, [:force], params
24
14
  @connection.delete(build_path("/nodes/#{name}", params))
25
15
  end
16
+
17
+ def details name
18
+ @connection.get("/nodes/#{name}")
19
+ end
20
+
21
+ #################################################
22
+ # Items in this area to be removed before 1.0.0 #
23
+ #################################################
24
+ def inspect *args
25
+ return super.inspect if args.size == 0
26
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
27
+ name = args[0]
28
+ details(name)
29
+ end
30
+ #################################################
31
+
26
32
  end
27
33
  end
28
34
  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
@@ -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
@@ -0,0 +1,92 @@
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
7
+
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
18
+
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
33
+
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
53
+
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
66
+
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
81
+
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}")
91
+ end
92
+ end
@@ -3,18 +3,14 @@ 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
 
16
- def inspect
17
- caller.each { | el | return super.inspect if el.match(/inspector/) }
13
+ def details
18
14
  @connection.get("/swarm")
19
15
  end
20
16
 
@@ -23,19 +19,27 @@ module Docker
23
19
  end
24
20
 
25
21
  def unlock body = {}
26
- validate Docker::API::InvalidRequestBody, [:UnlockKey], body
27
22
  @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
28
23
  end
29
24
 
30
25
  def join body = {}
31
- validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken], body
32
26
  @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
33
27
  end
34
28
 
35
29
  def leave params = {}
36
- validate Docker::API::InvalidParameter, [:force], params
37
30
  @connection.post(build_path("/swarm/leave", params))
38
31
  end
32
+
33
+ #################################################
34
+ # Items in this area to be removed before 1.0.0 #
35
+ #################################################
36
+ def inspect
37
+ caller.each { | el | return super.inspect if el.match(/inspector/) }
38
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
39
+ details
40
+ end
41
+ #################################################
42
+
39
43
  end
40
44
  end
41
45
  end