dockerapi 0.12.0 → 0.17.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.
@@ -1,51 +1,79 @@
1
- module Docker
2
- module API
3
- class Swarm < Docker::API::Base
1
+ ##
2
+ # This class represents the Docker API endpoints regarding swamrs.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Swarm
4
+ class Docker::API::Swarm < Docker::API::Base
4
5
 
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
6
+ ##
7
+ # Initialize a new swarm.
8
+ #
9
+ # Docker API: POST /swarm/init
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInit
11
+ #
12
+ # @param body [Hash]: Request body to be sent as json.
13
+ def init body = {}
14
+ @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
15
+ end
15
16
 
16
- def details
17
- @connection.get("/swarm")
18
- end
17
+ ##
18
+ # Update a swarm.
19
+ #
20
+ # Docker API: POST /swarm/update
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUpdate
22
+ #
23
+ # @param params [Hash]: Parameters that are appended to the URL.
24
+ # @param body [Hash]: Request body to be sent as json.
25
+ def update params = {}, body = {}
26
+ @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
+ end
19
28
 
20
- def unlock_key
21
- @connection.get(build_path("/swarm/unlockkey"))
22
- end
29
+ ##
30
+ # Inspect swarm.
31
+ #
32
+ # Docker API: GET /swarm
33
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInspect
34
+ def details
35
+ @connection.get("/swarm")
36
+ end
23
37
 
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
38
+ ##
39
+ # Get the unlock key.
40
+ #
41
+ # Docker API: GET /swarm/unlockkey
42
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlockkey
43
+ def unlock_key
44
+ @connection.get("/swarm/unlockkey")
45
+ end
28
46
 
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
47
+ ##
48
+ # Unlock a locked manager.
49
+ #
50
+ # Docker API: POST /swarm/unlock
51
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlock
52
+ #
53
+ # @param body [Hash]: Request body to be sent as json.
54
+ def unlock body = {}
55
+ @connection.request(method: :post, path: "/swarm/unlock", headers: {"Content-Type": "application/json"}, body: body.to_json)
56
+ end
33
57
 
34
- def leave params = {}
35
- validate Docker::API::InvalidParameter, [:force], params
36
- @connection.post(build_path("/swarm/leave", params))
37
- end
58
+ ##
59
+ # Join an existing swarm.
60
+ #
61
+ # Docker API: POST /swarm/join
62
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmJoin
63
+ #
64
+ # @param body [Hash]: Request body to be sent as json.
65
+ def join body = {}
66
+ @connection.request(method: :post, path: "/swarm/join", headers: {"Content-Type": "application/json"}, body: body.to_json)
67
+ end
38
68
 
39
- #################################################
40
- # Items in this area to be removed before 1.0.0 #
41
- #################################################
42
- def inspect
43
- caller.each { | el | return super.inspect if el.match(/inspector/) }
44
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
45
- details
46
- end
47
- #################################################
48
-
49
- end
69
+ ##
70
+ # Leave a swarm.
71
+ #
72
+ # Docker API: POST /swarm/leave
73
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmLeave
74
+ #
75
+ # @param params [Hash]: Parameters that are appended to the URL.
76
+ def leave params = {}
77
+ @connection.post(build_path("/swarm/leave", params))
50
78
  end
51
79
  end
@@ -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 : 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
@@ -1,26 +1,22 @@
1
1
  # This class represents the Docker API endpoints regarding tasks.
2
2
  #
3
- # @see https://docs.docker.com/engine/api/v1.40/#tag/Task
4
- #
5
3
  # A task is a container running on a swarm. It is the atomic scheduling unit of swarm. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Task
6
5
  class Docker::API::Task < Docker::API::Base
7
6
 
8
7
  # List tasks
9
8
  #
10
9
  # Docker API: GET /tasks
11
- #
12
10
  # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskList
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("/tasks",params))
18
15
  end
19
16
 
20
17
  # Inspect a task
21
18
  #
22
19
  # Docker API: GET /tasks/{id}
23
- #
24
20
  # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskInspect
25
21
  #
26
22
  # @param name [String]: The ID or name of the task.
@@ -30,17 +26,19 @@ class Docker::API::Task < Docker::API::Base
30
26
 
31
27
  # Get stdout and stderr logs from a task.
32
28
  #
33
- # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
34
- #
35
29
  # Docker API: GET /tasks/{id}/logs
36
- #
37
30
  # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskLogs
38
31
  #
39
32
  # @param name (String) : The ID or name of the task.
40
- #
41
33
  # @param params (Hash) : Parameters that are appended to the URL.
42
- def logs name, params = {}
43
- validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
44
- @connection.get(build_path("/tasks/#{name}/logs", params))
34
+ # @param &block: Replace the default output to stdout behavior.
35
+ def logs name, params = {}, &block
36
+ path = build_path("/tasks/#{name}/logs", params)
37
+
38
+ if [true, 1 ].include? params[:follow]
39
+ @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
40
+ else
41
+ @connection.get(path)
42
+ end
45
43
  end
46
44
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.12.0"
3
+ GEM_VERSION = "0.17.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -1,46 +1,61 @@
1
- module Docker
2
- module API
3
- class Volume < Docker::API::Base
4
-
5
- def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
- @connection.get(build_path("/volumes", params))
8
- end
9
-
10
- def details name
11
- @connection.get(build_path([name]))
12
- end
13
-
14
- def create body = {}
15
- validate Docker::API::InvalidRequestBody, [:Name, :Driver, :DriverOpts, :Labels], body
16
- @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
17
- end
18
-
19
- def remove name, params = {}
20
- validate Docker::API::InvalidParameter, [:force], params
21
- @connection.delete(build_path([name]))
22
- end
1
+ ##
2
+ # This class represents the Docker API endpoints regarding volumes.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Volume
4
+ class Docker::API::Volume < Docker::API::Base
5
+
6
+ ##
7
+ # List volumes.
8
+ #
9
+ # Docker API: GET
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeList
11
+ #
12
+ # @param params [Hash]: Parameters that are appended to the URL.
13
+ def list params = {}
14
+ @connection.get(build_path("/volumes", params))
15
+ end
23
16
 
24
- def prune params = {}
25
- validate Docker::API::InvalidParameter, [:filters], params
26
- @connection.post(build_path(["prune"], params))
27
- end
17
+ ##
18
+ # Inspect a volume.
19
+ #
20
+ # Docker API: GET /volumes/{name}
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeInspect
22
+ #
23
+ # @param name [String]: The ID or name of the volume.
24
+ def details name
25
+ @connection.get("/volumes/#{name}")
26
+ end
28
27
 
29
- #################################################
30
- # Items in this area to be removed before 1.0.0 #
31
- #################################################
32
- def base_path
33
- "/volumes"
34
- end
28
+ ##
29
+ # Create a volume.
30
+ #
31
+ # Docker API: POST /volumes/create
32
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate
33
+ #
34
+ # @param body [Hash]: Request body to be sent as json.
35
+ def create body = {}
36
+ @connection.request(method: :post, path: "/volumes/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
37
+ end
35
38
 
36
- def inspect *args
37
- return super.inspect if args.size == 0
38
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
39
- name = args[0]
40
- @connection.get(build_path([name]))
41
- end
42
- #################################################
39
+ ##
40
+ # Remove a volume.
41
+ #
42
+ # Docker API: DELETE /volumes/{name}
43
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeDelete
44
+ #
45
+ # @param name [String]: The ID or name of the volume.
46
+ # @param params [Hash]: Parameters that are appended to the URL.
47
+ def remove name, params = {}
48
+ @connection.delete(build_path("/volumes/#{name}",params))
49
+ end
43
50
 
44
- end
51
+ ##
52
+ # Delete unused volumes.
53
+ #
54
+ # Docker API: POST /volumes/prune
55
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumePrune
56
+ #
57
+ # @param params [Hash]: Parameters that are appended to the URL.
58
+ def prune params = {}
59
+ @connection.post(build_path("/volumes/prune", params))
45
60
  end
46
- end
61
+ end
@@ -1,5 +1,7 @@
1
1
  require "excon"
2
2
  require "json"
3
+ require "base64"
4
+ require "fileutils"
3
5
 
4
6
  require "docker/api/version"
5
7
  require "docker/api/error"
@@ -22,6 +24,147 @@ require "docker/api/plugin"
22
24
 
23
25
  module Docker
24
26
  module API
27
+
28
+ ##
29
+ # This variable controls output verbosity.
30
+ PRINT_TO_STDOUT = true
31
+
32
+ ##
33
+ # Valid values for parameter validations.
34
+ VALID_PARAMS = {
35
+ "Docker::API::Image" => {
36
+ "build" => [:dockerfile, :t, :extrahosts, :remote, :q, :nocache, :cachefrom, :pull, :rm, :forcerm, :memory, :memswap, :cpushares, :cpusetcpus, :cpuperiod, :cpuquota, :buildargs, :shmsize, :squash, :labels, :networkmode, :platform, :target, :outputs],
37
+ "prune" => [:filters],
38
+ "list" => [:all, :filters, :digests],
39
+ "search" => [:term, :limit, :filters],
40
+ "tag" => [:repo, :tag],
41
+ "remove" => [:force, :noprune],
42
+ "import" => [:quiet],
43
+ "push" => [:tag],
44
+ "commit" => [:container, :repo, :tag, :comment, :author, :pause, :changes],
45
+ "create" => [:fromImage, :fromSrc, :repo, :tag, :message, :platform],
46
+ "delete_cache" => [:all, "keep-storage", :filters]
47
+ },
48
+ "Docker::API::Container" => {
49
+ "list" => [:all, :limit, :size, :filters],
50
+ "details" => [:size],
51
+ "top" => [:ps_args],
52
+ "start" => [:detachKeys],
53
+ "stop" => [:t],
54
+ "restart" => [:t],
55
+ "kill" => [:signal],
56
+ "wait" => [:condition],
57
+ "rename" => [:name],
58
+ "resize" => [:w, :h],
59
+ "prune" => [:filters],
60
+ "remove" => [:v, :force, :link],
61
+ "logs" => [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail],
62
+ "attach" => [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr],
63
+ "stats" => [:stream],
64
+ "get_archive" => [:path],
65
+ "put_archive" => [:path, :noOverwriteDirNonDir, :copyUIDGID],
66
+ "create" => [:name]
67
+ },
68
+ "Docker::API::Volume" => {
69
+ "list" => [:filters],
70
+ "remove" => [:force],
71
+ "prune" => [:filters]
72
+ },
73
+ "Docker::API::Network" => {
74
+ "list" => [:filters],
75
+ "details" => [:verbose, :scope],
76
+ "prune" => [:filters]
77
+ },
78
+ "Docker::API::System" => {
79
+ "events" => [:since, :until, :filters]
80
+ },
81
+ "Docker::API::Exec" => {
82
+ "resize" => [:w, :h]
83
+ },
84
+ "Docker::API::Swarm" => {
85
+ "leave" => [:force],
86
+ "update" => [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey]
87
+ },
88
+ "Docker::API::Node" => {
89
+ "list" => [:filters],
90
+ "update" => [:version],
91
+ "delete" => [:force]
92
+ },
93
+ "Docker::API::Service" => {
94
+ "list" => [:filters],
95
+ "update" => [:version, :registryAuthFrom, :rollback],
96
+ "details" => [:insertDefaults],
97
+ "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail]
98
+ },
99
+ "Docker::API::Secret" => {
100
+ "list" => [:filters],
101
+ "update" => [:version]
102
+ },
103
+ "Docker::API::Task" => {
104
+ "list" => [:filters],
105
+ "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail]
106
+ },
107
+ "Docker::API::Plugin" => {
108
+ "list" => [:filters],
109
+ "privileges" => [:remote],
110
+ "install" => [:remote, :name],
111
+ "remove" => [:force],
112
+ "enable" => [:timeout],
113
+ "upgrade" => [:remote]
114
+ },
115
+ "Docker::API::Config" => {
116
+ "list" => [:filters],
117
+ "update" => [:version]
118
+ }
119
+ }
120
+
121
+ ##
122
+ # Valid values for request body validations.
123
+ VALID_BODY = {
124
+ "Docker::API::Image" => {
125
+ "commit" => [:Hostname, :Domainname, :User, :AttachStdin, :AttachStdout, :AttachStderr, :ExposedPorts, :Tty, :OpenStdin, :StdinOnce, :Env, :Cmd, :HealthCheck, :ArgsEscaped, :Image, :Volumes, :WorkingDir, :Entrypoint, :NetworkDisabled, :MacAddress, :OnBuild, :Labels, :StopSignal, :StopTimeout, :Shell]
126
+ },
127
+ "Docker::API::Container" => {
128
+ "create" => [:Hostname,:Domainname,:User,:AttachStdin,:AttachStdout,:AttachStderr,:ExposedPorts,:Tty,:OpenStdin,:StdinOnce,:Env,:Cmd,:HealthCheck,:ArgsEscaped,:Image,:Volumes,:WorkingDir,:Entrypoint,:NetworkDisabled,:MacAddress,:OnBuild,:Labels,:StopSignal,:StopTimeout,:Shell,:HostConfig,:NetworkingConfig],
129
+ "update" => [:CpuShares, :Memory, :CgroupParent, :BlkioWeight, :BlkioWeightDevice, :BlkioWeightReadBps, :BlkioWeightWriteBps, :BlkioWeightReadOps, :BlkioWeightWriteOps, :CpuPeriod, :CpuQuota, :CpuRealtimePeriod, :CpuRealtimeRuntime, :CpusetCpus, :CpusetMems, :Devices, :DeviceCgroupRules, :DeviceRequest, :Kernel, :Memory, :KernelMemoryTCP, :MemoryReservation, :MemorySwap, :MemorySwappiness, :NanoCPUs, :OomKillDisable, :Init, :PidsLimit, :ULimits, :CpuCount, :CpuPercent, :IOMaximumIOps, :IOMaximumBandwidth, :RestartPolicy]
130
+ },
131
+ "Docker::API::Volume" => {
132
+ "create" => [:Name, :Driver, :DriverOpts, :Labels]
133
+ },
134
+ "Docker::API::Network" => {
135
+ "create" => [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels],
136
+ "connect" => [:Container, :EndpointConfig],
137
+ "disconnect" => [:Container, :Force]
138
+ },
139
+ "Docker::API::System" => {
140
+ "auth" => [:username, :password, :email, :serveraddress, :identitytoken]
141
+ },
142
+ "Docker::API::Exec" => {
143
+ "create" => [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir],
144
+ "start" => [:Detach, :Tty]
145
+ },
146
+ "Docker::API::Swarm" => {
147
+ "init" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec],
148
+ "update" => [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults],
149
+ "unlock" => [:UnlockKey],
150
+ "join" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken]
151
+ },
152
+ "Docker::API::Node" => {
153
+ "update" => [:Name, :Labels, :Role, :Availability]
154
+ },
155
+ "Docker::API::Service" => {
156
+ "create" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec],
157
+ "update" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec]
158
+ },
159
+ "Docker::API::Secret" => {
160
+ "create" => [:Name, :Labels, :Data, :Driver, :Templating],
161
+ "update" => [:Name, :Labels, :Data, :Driver, :Templating]
162
+ },
163
+ "Docker::API::Config" => {
164
+ "create" => [:Name, :Labels, :Data, :Templating],
165
+ "update" => [:Name, :Labels, :Data, :Driver, :Templating]
166
+ }
167
+ }
25
168
 
26
169
  end
27
170
  end