1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Docker\API\Resource; |
4
|
|
|
|
5
|
|
|
use Joli\Jane\Swagger\Client\QueryParam; |
6
|
|
|
use Joli\Jane\Swagger\Client\Resource; |
7
|
|
|
|
8
|
|
|
class ContainerResource extends Resource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* List containers. |
12
|
|
|
* |
13
|
|
|
* @param array $parameters List of parameters |
14
|
|
|
* @param string $fetch Fetch mode (object or response) |
15
|
|
|
* |
16
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function findAll($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$queryParam = new QueryParam(); |
21
|
|
|
$queryParam->setDefault('all', false); |
22
|
|
|
$queryParam->setDefault('limit', null); |
23
|
|
|
$queryParam->setDefault('since', null); |
24
|
|
|
$queryParam->setDefault('before', null); |
25
|
|
|
$queryParam->setDefault('size', null); |
26
|
|
|
$queryParam->setDefault('filters', null); |
27
|
|
|
$url = sprintf('/v1.21/containers/json?%s', $queryParam->buildQueryString($parameters)); |
28
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
29
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
30
|
|
|
$response = $this->httpClient->sendRequest($request); |
31
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
32
|
|
|
return $response; |
33
|
|
|
} |
34
|
|
|
if ('200' == $response->getStatusCode()) { |
35
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ContainerConfig[]', 'json'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $response; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a container. |
43
|
|
|
* |
44
|
|
|
* @param mixed $container Container to create |
45
|
|
|
* @param array $parameters List of parameters |
46
|
|
|
* @param string $fetch Fetch mode (object or response) |
47
|
|
|
* |
48
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
49
|
|
|
*/ |
50
|
|
|
public function create($container, $parameters = [], $fetch = self::FETCH_OBJECT) |
51
|
|
|
{ |
52
|
|
|
$queryParam = new QueryParam(); |
53
|
|
|
$queryParam->setDefault('name', null); |
54
|
|
|
$url = sprintf('/v1.21/containers/create?%s', $queryParam->buildQueryString($parameters)); |
55
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), $container); |
56
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
57
|
|
|
$response = $this->httpClient->sendRequest($request); |
58
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
59
|
|
|
return $response; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $response; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Return low-level information on the container id. |
67
|
|
|
* |
68
|
|
|
* @param mixed $id The container id or name |
69
|
|
|
* @param array $parameters List of parameters |
70
|
|
|
* @param string $fetch Fetch mode (object or response) |
71
|
|
|
* |
72
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
73
|
|
|
*/ |
74
|
|
|
public function find($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
75
|
|
|
{ |
76
|
|
|
$queryParam = new QueryParam(); |
77
|
|
|
$url = sprintf('/v1.21/containers/%s/json?%s', $id, $queryParam->buildQueryString($parameters)); |
78
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
79
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
80
|
|
|
$response = $this->httpClient->sendRequest($request); |
81
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
82
|
|
|
return $response; |
83
|
|
|
} |
84
|
|
|
if ('200' == $response->getStatusCode()) { |
85
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\Container', 'json'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $response; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* List processes running inside the container id. |
93
|
|
|
* |
94
|
|
|
* @param mixed $id The container id or name |
95
|
|
|
* @param array $parameters List of parameters |
96
|
|
|
* @param string $fetch Fetch mode (object or response) |
97
|
|
|
* |
98
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function listProcesses($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$queryParam = new QueryParam(); |
103
|
|
|
$queryParam->setDefault('ps_args', null); |
104
|
|
|
$url = sprintf('/v1.21/containers/%s/top?%s', $id, $queryParam->buildQueryString($parameters)); |
105
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
106
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
107
|
|
|
$response = $this->httpClient->sendRequest($request); |
108
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
109
|
|
|
return $response; |
110
|
|
|
} |
111
|
|
|
if ('200' == $response->getStatusCode()) { |
112
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ContainerTop', 'json'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $response; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get stdout and stderr logs from the container id. Note: This endpoint works only for containers with json-file logging driver. |
120
|
|
|
* |
121
|
|
|
* @param mixed $id The container id or name |
122
|
|
|
* @param array $parameters List of parameters |
123
|
|
|
* @param string $fetch Fetch mode (object or response) |
124
|
|
|
* |
125
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
126
|
|
|
*/ |
127
|
|
View Code Duplication |
public function logs($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
$queryParam = new QueryParam(); |
130
|
|
|
$queryParam->setDefault('follow', false); |
131
|
|
|
$queryParam->setDefault('stdout', false); |
132
|
|
|
$queryParam->setDefault('stderr', false); |
133
|
|
|
$queryParam->setDefault('since', 0); |
134
|
|
|
$queryParam->setDefault('timestamps', false); |
135
|
|
|
$queryParam->setDefault('tail', null); |
136
|
|
|
$url = sprintf('/v1.21/containers/%s/logs?%s', $id, $queryParam->buildQueryString($parameters)); |
137
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
138
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
139
|
|
|
$response = $this->httpClient->sendRequest($request); |
140
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
141
|
|
|
return $response; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $response; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Inspect changes on a container’s filesystem. |
149
|
|
|
* |
150
|
|
|
* @param mixed $id The container id or name |
151
|
|
|
* @param array $parameters List of parameters |
152
|
|
|
* @param string $fetch Fetch mode (object or response) |
153
|
|
|
* |
154
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
155
|
|
|
*/ |
156
|
|
View Code Duplication |
public function changes($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$queryParam = new QueryParam(); |
159
|
|
|
$queryParam->setDefault('kind', null); |
160
|
|
|
$url = sprintf('/v1.21/containers/%s/changes?%s', $id, $queryParam->buildQueryString($parameters)); |
161
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
162
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
163
|
|
|
$response = $this->httpClient->sendRequest($request); |
164
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
165
|
|
|
return $response; |
166
|
|
|
} |
167
|
|
|
if ('200' == $response->getStatusCode()) { |
168
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ContainerChange[]', 'json'); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
return $response; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Export the contents of container id. |
176
|
|
|
* |
177
|
|
|
* @param mixed $id The container id or name |
178
|
|
|
* @param array $parameters List of parameters |
179
|
|
|
* @param string $fetch Fetch mode (object or response) |
180
|
|
|
* |
181
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
182
|
|
|
*/ |
183
|
|
|
public function export($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
184
|
|
|
{ |
185
|
|
|
$queryParam = new QueryParam(); |
186
|
|
|
$url = sprintf('/v1.21/containers/%s/export?%s', $id, $queryParam->buildQueryString($parameters)); |
187
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
188
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
189
|
|
|
$response = $this->httpClient->sendRequest($request); |
190
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
191
|
|
|
return $response; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
return $response; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* This endpoint returns a live stream of a container’s resource usage statistics. |
199
|
|
|
* |
200
|
|
|
* @param mixed $id The container id or name |
201
|
|
|
* @param array $parameters List of parameters |
202
|
|
|
* @param string $fetch Fetch mode (object or response) |
203
|
|
|
* |
204
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
205
|
|
|
*/ |
206
|
|
View Code Duplication |
public function stats($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
207
|
|
|
{ |
208
|
|
|
$queryParam = new QueryParam(); |
209
|
|
|
$queryParam->setDefault('stream', null); |
210
|
|
|
$url = sprintf('/v1.21/containers/%s/stats?%s', $id, $queryParam->buildQueryString($parameters)); |
211
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
212
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
213
|
|
|
$response = $this->httpClient->sendRequest($request); |
214
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
215
|
|
|
return $response; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
return $response; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Resize the TTY for container with id. The unit is number of characters. You must restart the container for the resize to take effect. |
223
|
|
|
* |
224
|
|
|
* @param mixed $id The container id or name |
225
|
|
|
* @param array $parameters List of parameters |
226
|
|
|
* @param string $fetch Fetch mode (object or response) |
227
|
|
|
* |
228
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
229
|
|
|
*/ |
230
|
|
View Code Duplication |
public function resize($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
231
|
|
|
{ |
232
|
|
|
$queryParam = new QueryParam(); |
233
|
|
|
$queryParam->setDefault('h', null); |
234
|
|
|
$queryParam->setDefault('w', null); |
235
|
|
|
$url = sprintf('/v1.21/containers/%s/resize?%s', $id, $queryParam->buildQueryString($parameters)); |
236
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
237
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
238
|
|
|
$response = $this->httpClient->sendRequest($request); |
239
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
240
|
|
|
return $response; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
return $response; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Start the container id. |
248
|
|
|
* |
249
|
|
|
* @param mixed $id The container id or name |
250
|
|
|
* @param array $parameters List of parameters |
251
|
|
|
* @param string $fetch Fetch mode (object or response) |
252
|
|
|
* |
253
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
254
|
|
|
*/ |
255
|
|
|
public function start($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
256
|
|
|
{ |
257
|
|
|
$queryParam = new QueryParam(); |
258
|
|
|
$url = sprintf('/v1.21/containers/%s/start?%s', $id, $queryParam->buildQueryString($parameters)); |
259
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
260
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
261
|
|
|
$response = $this->httpClient->sendRequest($request); |
262
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
263
|
|
|
return $response; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
return $response; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Stop the container id. |
271
|
|
|
* |
272
|
|
|
* @param mixed $id The container id or name |
273
|
|
|
* @param array $parameters List of parameters |
274
|
|
|
* @param string $fetch Fetch mode (object or response) |
275
|
|
|
* |
276
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
277
|
|
|
*/ |
278
|
|
View Code Duplication |
public function stop($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
279
|
|
|
{ |
280
|
|
|
$queryParam = new QueryParam(); |
281
|
|
|
$queryParam->setDefault('t', null); |
282
|
|
|
$url = sprintf('/v1.21/containers/%s/stop?%s', $id, $queryParam->buildQueryString($parameters)); |
283
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
284
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
285
|
|
|
$response = $this->httpClient->sendRequest($request); |
286
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
287
|
|
|
return $response; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
return $response; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Restart the container id. |
295
|
|
|
* |
296
|
|
|
* @param mixed $id The container id or name |
297
|
|
|
* @param array $parameters List of parameters |
298
|
|
|
* @param string $fetch Fetch mode (object or response) |
299
|
|
|
* |
300
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
301
|
|
|
*/ |
302
|
|
View Code Duplication |
public function restart($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
303
|
|
|
{ |
304
|
|
|
$queryParam = new QueryParam(); |
305
|
|
|
$queryParam->setDefault('t', null); |
306
|
|
|
$url = sprintf('/v1.21/containers/%s/restart?%s', $id, $queryParam->buildQueryString($parameters)); |
307
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
308
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
309
|
|
|
$response = $this->httpClient->sendRequest($request); |
310
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
311
|
|
|
return $response; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
return $response; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Send a posix signal to a container. |
319
|
|
|
* |
320
|
|
|
* @param mixed $id The container id or name |
321
|
|
|
* @param array $parameters List of parameters |
322
|
|
|
* @param string $fetch Fetch mode (object or response) |
323
|
|
|
* |
324
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
325
|
|
|
*/ |
326
|
|
|
public function kill($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
327
|
|
|
{ |
328
|
|
|
$queryParam = new QueryParam(); |
329
|
|
|
$url = sprintf('/v1.21/containers/%s/kill?%s', $id, $queryParam->buildQueryString($parameters)); |
330
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
331
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
332
|
|
|
$response = $this->httpClient->sendRequest($request); |
333
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
334
|
|
|
return $response; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
return $response; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Rename the container id to a new_name. |
342
|
|
|
* |
343
|
|
|
* @param mixed $id The container id or name |
344
|
|
|
* @param array $parameters List of parameters |
345
|
|
|
* @param string $fetch Fetch mode (object or response) |
346
|
|
|
* |
347
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
348
|
|
|
*/ |
349
|
|
|
public function rename($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
350
|
|
|
{ |
351
|
|
|
$queryParam = new QueryParam(); |
352
|
|
|
$queryParam->setRequired('name'); |
353
|
|
|
$url = sprintf('/v1.21/containers/%s/rename?%s', $id, $queryParam->buildQueryString($parameters)); |
354
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
355
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
356
|
|
|
$response = $this->httpClient->sendRequest($request); |
357
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
358
|
|
|
return $response; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
return $response; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Pause the container id. |
366
|
|
|
* |
367
|
|
|
* @param mixed $id The container id or name |
368
|
|
|
* @param array $parameters List of parameters |
369
|
|
|
* @param string $fetch Fetch mode (object or response) |
370
|
|
|
* |
371
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
372
|
|
|
*/ |
373
|
|
|
public function pause($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
374
|
|
|
{ |
375
|
|
|
$queryParam = new QueryParam(); |
376
|
|
|
$url = sprintf('/v1.21/containers/%s/pause?%s', $id, $queryParam->buildQueryString($parameters)); |
377
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
378
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
379
|
|
|
$response = $this->httpClient->sendRequest($request); |
380
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
381
|
|
|
return $response; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
return $response; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Unpause the container id. |
389
|
|
|
* |
390
|
|
|
* @param mixed $id The container id or name |
391
|
|
|
* @param array $parameters List of parameters |
392
|
|
|
* @param string $fetch Fetch mode (object or response) |
393
|
|
|
* |
394
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
395
|
|
|
*/ |
396
|
|
|
public function unpause($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
397
|
|
|
{ |
398
|
|
|
$queryParam = new QueryParam(); |
399
|
|
|
$url = sprintf('/v1.21/containers/%s/unpause?%s', $id, $queryParam->buildQueryString($parameters)); |
400
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
401
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
402
|
|
|
$response = $this->httpClient->sendRequest($request); |
403
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
404
|
|
|
return $response; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
return $response; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Attach to the container id. |
412
|
|
|
* |
413
|
|
|
* @param mixed $id The container id or name |
414
|
|
|
* @param array $parameters List of parameters |
415
|
|
|
* @param string $fetch Fetch mode (object or response) |
416
|
|
|
* |
417
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
418
|
|
|
*/ |
419
|
|
View Code Duplication |
public function attach($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
420
|
|
|
{ |
421
|
|
|
$queryParam = new QueryParam(); |
422
|
|
|
$queryParam->setDefault('logs', null); |
423
|
|
|
$queryParam->setDefault('stream', null); |
424
|
|
|
$queryParam->setDefault('stdin', null); |
425
|
|
|
$queryParam->setDefault('stdout', null); |
426
|
|
|
$queryParam->setDefault('stderr', null); |
427
|
|
|
$url = sprintf('/v1.21/containers/%s/attach?%s', $id, $queryParam->buildQueryString($parameters)); |
428
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
429
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
430
|
|
|
$response = $this->httpClient->sendRequest($request); |
431
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
432
|
|
|
return $response; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
return $response; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Block until container id stops, then returns the exit code. |
440
|
|
|
* |
441
|
|
|
* @param mixed $id The container id or name |
442
|
|
|
* @param array $parameters List of parameters |
443
|
|
|
* @param string $fetch Fetch mode (object or response) |
444
|
|
|
* |
445
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
446
|
|
|
*/ |
447
|
|
|
public function wait($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
448
|
|
|
{ |
449
|
|
|
$queryParam = new QueryParam(); |
450
|
|
|
$url = sprintf('/v1.21/containers/%s/wait?%s', $id, $queryParam->buildQueryString($parameters)); |
451
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
452
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
453
|
|
|
$response = $this->httpClient->sendRequest($request); |
454
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
455
|
|
|
return $response; |
456
|
|
|
} |
457
|
|
|
if ('200' == $response->getStatusCode()) { |
458
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ContainerWait', 'json'); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
return $response; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Remove the container id from the filesystem. |
466
|
|
|
* |
467
|
|
|
* @param mixed $id The container id or name |
468
|
|
|
* @param array $parameters List of parameters |
469
|
|
|
* @param string $fetch Fetch mode (object or response) |
470
|
|
|
* |
471
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
472
|
|
|
*/ |
473
|
|
View Code Duplication |
public function remove($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
474
|
|
|
{ |
475
|
|
|
$queryParam = new QueryParam(); |
476
|
|
|
$queryParam->setDefault('v', null); |
477
|
|
|
$queryParam->setDefault('force', null); |
478
|
|
|
$url = sprintf('/v1.21/containers/%s?%s', $id, $queryParam->buildQueryString($parameters)); |
479
|
|
|
$request = $this->messageFactory->createRequest('DELETE', $url, $queryParam->buildHeaders($parameters), null); |
480
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
481
|
|
|
$response = $this->httpClient->sendRequest($request); |
482
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
483
|
|
|
return $response; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
return $response; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* Get an tar archive of a resource in the filesystem of container id. |
491
|
|
|
* |
492
|
|
|
* @param mixed $id The container id or name |
493
|
|
|
* @param array $parameters List of parameters |
494
|
|
|
* @param string $fetch Fetch mode (object or response) |
495
|
|
|
* |
496
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
497
|
|
|
*/ |
498
|
|
|
public function getArchive($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
499
|
|
|
{ |
500
|
|
|
$queryParam = new QueryParam(); |
501
|
|
|
$queryParam->setRequired('path'); |
502
|
|
|
$url = sprintf('/v1.21/containers/%s/archive?%s', $id, $queryParam->buildQueryString($parameters)); |
503
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null); |
504
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
505
|
|
|
$response = $this->httpClient->sendRequest($request); |
506
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
507
|
|
|
return $response; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
return $response; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* Retrieving information about files and folders in a container. |
515
|
|
|
* |
516
|
|
|
* @param mixed $id The container id or name |
517
|
|
|
* @param array $parameters List of parameters |
518
|
|
|
* @param string $fetch Fetch mode (object or response) |
519
|
|
|
* |
520
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
521
|
|
|
*/ |
522
|
|
|
public function getArchiveInformation($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
523
|
|
|
{ |
524
|
|
|
$queryParam = new QueryParam(); |
525
|
|
|
$queryParam->setRequired('path'); |
526
|
|
|
$url = sprintf('/v1.21/containers/%s/archive?%s', $id, $queryParam->buildQueryString($parameters)); |
527
|
|
|
$request = $this->messageFactory->createRequest('HEAD', $url, $queryParam->buildHeaders($parameters), null); |
528
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
529
|
|
|
$response = $this->httpClient->sendRequest($request); |
530
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
531
|
|
|
return $response; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
return $response; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* Upload a tar archive to be extracted to a path in the filesystem of container id. |
539
|
|
|
* |
540
|
|
|
* @param mixed $id The container id or name |
541
|
|
|
* @param mixed $inputStream The input stream must be a tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz. |
542
|
|
|
* @param array $parameters List of parameters |
543
|
|
|
* @param string $fetch Fetch mode (object or response) |
544
|
|
|
* |
545
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
546
|
|
|
*/ |
547
|
|
View Code Duplication |
public function putArchive($id, $inputStream, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
548
|
|
|
{ |
549
|
|
|
$queryParam = new QueryParam(); |
550
|
|
|
$queryParam->setRequired('path'); |
551
|
|
|
$queryParam->setDefault('noOverwriteDirNonDir', null); |
552
|
|
|
$url = sprintf('/v1.21/containers/%s/archive?%s', $id, $queryParam->buildQueryString($parameters)); |
553
|
|
|
$request = $this->messageFactory->createRequest('PUT', $url, $queryParam->buildHeaders($parameters), $inputStream); |
554
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
555
|
|
|
$response = $this->httpClient->sendRequest($request); |
556
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
557
|
|
|
return $response; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
return $response; |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.