1 | 'use strict'
|
2 |
|
3 | import Modem = require('docker-modem')
|
4 | import { Image } from './image'
|
5 | import fs = require('fs')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export class Exec {
|
12 | modem: Modem
|
13 | container: Container
|
14 | id: String
|
15 | data: Object = {}
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | constructor (modem: Modem, container: Container, id: String) {
|
25 | this.modem = modem
|
26 | this.container = container
|
27 | this.id = id
|
28 | }
|
29 |
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | create (opts?: Object): Promise<Exec> {
|
37 | const call = {
|
38 | path: `/containers/${this.container.id}/exec?`,
|
39 | method: 'POST',
|
40 | options: opts,
|
41 | statusCodes: {
|
42 | 200: true,
|
43 | 201: true,
|
44 | 404: 'no such container',
|
45 | 409: 'container is paused',
|
46 | 500: 'server error'
|
47 | }
|
48 | }
|
49 |
|
50 | return new Promise((resolve, reject) => {
|
51 | this.modem.dial(call, (err, conf) => {
|
52 | if (err) return reject(err)
|
53 | const exec = new Exec(this.modem, this.container, conf.Id)
|
54 | exec.data = conf
|
55 | resolve(exec)
|
56 | })
|
57 | })
|
58 | }
|
59 |
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | start (opts: any = {}): Promise<Object> {
|
67 | const call = {
|
68 | path: `/exec/${this.id}/start?`,
|
69 | method: 'POST',
|
70 | options: opts,
|
71 | isStream: true,
|
72 | hijack: opts.hijack,
|
73 | openStdin: opts.stdin,
|
74 | statusCodes: {
|
75 | 200: true,
|
76 | 404: 'no such exec instance',
|
77 | 409: 'container is paused'
|
78 | }
|
79 | }
|
80 |
|
81 | return new Promise((resolve, reject) => {
|
82 | this.modem.dial(call, (err, stream: Object) => {
|
83 | if (err) return reject(err)
|
84 | resolve(stream)
|
85 | })
|
86 | })
|
87 | }
|
88 |
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | resize (opts?: Object): Promise<{}> {
|
96 | const call = {
|
97 | path: `/exec/${this.id}/resize?`,
|
98 | method: 'POST',
|
99 | options: opts,
|
100 | statusCodes: {
|
101 | 201: true,
|
102 | 404: 'no such exec instance'
|
103 | }
|
104 | }
|
105 |
|
106 | return new Promise((resolve, reject) => {
|
107 | this.modem.dial(call, (err) => {
|
108 | if (err) return reject(err)
|
109 | resolve()
|
110 | })
|
111 | })
|
112 | }
|
113 |
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | status (opts?: Object): Promise<Exec> {
|
122 | const call = {
|
123 | path: `/exec/${this.id}/json?`,
|
124 | method: 'GET',
|
125 | options: opts,
|
126 | statusCodes: {
|
127 | 200: true,
|
128 | 404: 'no such exec instance',
|
129 | 500: 'server error'
|
130 | }
|
131 | }
|
132 |
|
133 | return new Promise((resolve, reject) => {
|
134 | this.modem.dial(call, (err, conf) => {
|
135 | if (err) return reject(err)
|
136 | const exec = new Exec(this.modem, this.container, conf.Id)
|
137 | exec.data = conf
|
138 | resolve(exec)
|
139 | })
|
140 | })
|
141 | }
|
142 | }
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | export class ExecManager {
|
148 | modem: Modem
|
149 | container: Container
|
150 |
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | constructor (modem: Modem, container: Container) {
|
159 | this.modem = modem
|
160 | this.container = container
|
161 | }
|
162 |
|
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 | get (id: String): Exec {
|
169 | return new Exec(this.modem, this.container, id)
|
170 | }
|
171 |
|
172 | |
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | create (opts?: Object): Promise<Exec> {
|
179 | const call = {
|
180 | path: `/containers/${this.container.id}/exec?`,
|
181 | method: 'POST',
|
182 | options: opts,
|
183 | statusCodes: {
|
184 | 200: true,
|
185 | 201: true,
|
186 | 404: 'no such container',
|
187 | 409: 'container is paused',
|
188 | 500: 'server error'
|
189 | }
|
190 | }
|
191 |
|
192 | return new Promise((resolve, reject) => {
|
193 | this.modem.dial(call, (err, conf) => {
|
194 | if (err) return reject(err)
|
195 | const exec = new Exec(this.modem, this.container, conf.Id)
|
196 | exec.data = conf
|
197 | resolve(exec)
|
198 | })
|
199 | })
|
200 | }
|
201 | }
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | export class ContainerFs {
|
207 | modem: Modem
|
208 | container: Container
|
209 |
|
210 | |
211 |
|
212 |
|
213 |
|
214 |
|
215 | constructor (modem: Modem, container: Container) {
|
216 | this.modem = modem
|
217 | this.container = container
|
218 | }
|
219 |
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | info (opts?: Object): Promise<String> {
|
227 | const call = {
|
228 | path: `/containers/${this.container.id}/archive?`,
|
229 | method: 'HEAD',
|
230 | isStream: true,
|
231 | options: opts,
|
232 | statusCodes: {
|
233 | 200: true,
|
234 | 404: 'bad request',
|
235 | 500: 'server error'
|
236 | }
|
237 | }
|
238 |
|
239 | return new Promise((resolve, reject) => {
|
240 | this.modem.dial(call, (err, info: String) => {
|
241 | if (err) return reject(err)
|
242 | resolve(info)
|
243 | })
|
244 | })
|
245 | }
|
246 |
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | get (opts: any = {}): Promise<Object> {
|
254 | const call = {
|
255 | path: `/containers/${this.container.id}/archive?path=${opts.path}&`,
|
256 | method: 'GET',
|
257 | isStream: true,
|
258 | options: opts,
|
259 | statusCodes: {
|
260 | 200: true,
|
261 | 400: 'bad request',
|
262 | 404: 'no such container',
|
263 | 500: 'server error'
|
264 | }
|
265 | }
|
266 |
|
267 | return new Promise((resolve, reject) => {
|
268 | this.modem.dial(call, (err, stream: Object) => {
|
269 | if (err) return reject(err)
|
270 | resolve(stream)
|
271 | })
|
272 | })
|
273 | }
|
274 |
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | put (file: fs.ReadStream, opts?: Object): Promise<Object> {
|
282 | const call = {
|
283 | path: `/containers/${this.container.id}/archive?`,
|
284 | method: 'PUT',
|
285 | options: opts,
|
286 | isStream: true,
|
287 | file: file,
|
288 | statusCodes: {
|
289 | 200: true,
|
290 | 400: 'bad request',
|
291 | 403: 'permission denied',
|
292 | 404: 'no such container',
|
293 | 500: 'server error'
|
294 | }
|
295 | }
|
296 |
|
297 | return new Promise((resolve, reject) => {
|
298 | this.modem.dial(call, (err, res: Object) => {
|
299 | if (err) return reject(err)
|
300 | resolve(res)
|
301 | })
|
302 | })
|
303 | }
|
304 | }
|
305 |
|
306 |
|
307 |
|
308 |
|
309 | export class Container {
|
310 | modem: Modem
|
311 | id: String
|
312 | fs: ContainerFs
|
313 | exec: ExecManager
|
314 | Warnings: Array<String> = []
|
315 | data: Object = {}
|
316 |
|
317 | |
318 |
|
319 |
|
320 |
|
321 |
|
322 | constructor (modem: Modem, id: String) {
|
323 | this.modem = modem
|
324 | this.id = id
|
325 | this.fs = new ContainerFs(this.modem, this)
|
326 | this.exec = new ExecManager(this.modem, this)
|
327 | }
|
328 |
|
329 | |
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 | status (opts?: Object): Promise<Container> {
|
337 | const call = {
|
338 | path: `/containers/${this.id}/json?`,
|
339 | method: 'GET',
|
340 | options: opts,
|
341 | statusCodes: {
|
342 | 200: true,
|
343 | 404: 'no such container',
|
344 | 500: 'server error'
|
345 | }
|
346 | }
|
347 |
|
348 | return new Promise((resolve, reject) => {
|
349 | this.modem.dial(call, (err, conf) => {
|
350 | if (err) return reject(err)
|
351 | const container = new Container(this.modem, this.id)
|
352 | container.data = conf
|
353 | resolve(container)
|
354 | })
|
355 | })
|
356 | }
|
357 |
|
358 | |
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 | top (opts?: Object): Promise<Array<Object>> {
|
365 | const call = {
|
366 | path: `/containers/${this.id}/top?`,
|
367 | method: 'GET',
|
368 | options: opts,
|
369 | statusCodes: {
|
370 | 200: true,
|
371 | 404: 'no such container',
|
372 | 500: 'server error'
|
373 | }
|
374 | }
|
375 |
|
376 | return new Promise((resolve, reject) => {
|
377 | this.modem.dial(call, (err, processes: Array<Object>) => {
|
378 | if (err) return reject(err)
|
379 | resolve(processes)
|
380 | })
|
381 | })
|
382 | }
|
383 |
|
384 | |
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 | logs (opts?: Object): Promise<Object> {
|
391 | const call = {
|
392 | path: `/containers/${this.id}/logs?`,
|
393 | method: 'GET',
|
394 | options: opts,
|
395 | isStream: true,
|
396 | statusCodes: {
|
397 | 101: true,
|
398 | 200: true,
|
399 | 404: 'no such container',
|
400 | 500: 'server error'
|
401 | }
|
402 | }
|
403 |
|
404 | return new Promise((resolve, reject) => {
|
405 | this.modem.dial(call, (err, logs: Object) => {
|
406 | if (err) return reject(err)
|
407 | resolve(logs)
|
408 | })
|
409 | })
|
410 | }
|
411 |
|
412 | |
413 |
|
414 |
|
415 |
|
416 |
|
417 | changes (): Promise<Array<Object>> {
|
418 | const call = {
|
419 | path: `/containers/${this.id}/changes?`,
|
420 | method: 'GET',
|
421 | options: {},
|
422 | statusCodes: {
|
423 | 200: true,
|
424 | 404: 'no such container',
|
425 | 500: 'server error'
|
426 | }
|
427 | }
|
428 |
|
429 | return new Promise((resolve, reject) => {
|
430 | this.modem.dial(call, (err, changes: Array<Object>) => {
|
431 | if (err) return reject(err)
|
432 | resolve(changes)
|
433 | })
|
434 | })
|
435 | }
|
436 |
|
437 | |
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 | export (opts: any = {}): Promise<Object> {
|
444 | const call = {
|
445 | path: `/containers/${this.id}/export?`,
|
446 | method: 'GET',
|
447 | options: opts,
|
448 | isStream: !!opts.stream,
|
449 | statusCodes: {
|
450 | 200: true,
|
451 | 404: 'no such container',
|
452 | 500: 'server error'
|
453 | }
|
454 | }
|
455 |
|
456 | return new Promise((resolve, reject) => {
|
457 | this.modem.dial(call, (err, tarStream: any) => {
|
458 | if (err) return reject(err)
|
459 | if (!opts.stream) return resolve(tarStream)
|
460 |
|
461 | const res = []
|
462 | tarStream.on('data', (chunk) => {
|
463 | res.push(chunk.toString())
|
464 | })
|
465 |
|
466 | tarStream.on('end', () => {
|
467 | resolve(res.join(''))
|
468 | })
|
469 | })
|
470 | })
|
471 | }
|
472 |
|
473 | |
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | stats (opts?: Object): Promise<Object> {
|
480 | const call = {
|
481 | path: `/containers/${this.id}/stats?`,
|
482 | method: 'GET',
|
483 | options: opts,
|
484 | isStream: true,
|
485 | statusCodes: {
|
486 | 200: true,
|
487 | 404: 'no such container',
|
488 | 500: 'server error'
|
489 | }
|
490 | }
|
491 |
|
492 | return new Promise((resolve, reject) => {
|
493 | this.modem.dial(call, (err, stats: Object) => {
|
494 | if (err) return reject(err)
|
495 | resolve(stats)
|
496 | })
|
497 | })
|
498 | }
|
499 |
|
500 | |
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | resize (opts?: Object): Promise<Object> {
|
507 | const call = {
|
508 | path: `/containers/${this.id}/resize?`,
|
509 | method: 'GET',
|
510 | options: opts,
|
511 | statusCodes: {
|
512 | 200: true,
|
513 | 404: 'no such container',
|
514 | 500: 'server error'
|
515 | }
|
516 | }
|
517 |
|
518 | return new Promise((resolve, reject) => {
|
519 | this.modem.dial(call, (err, res: Object) => {
|
520 | if (err) return reject(err)
|
521 | resolve(res)
|
522 | })
|
523 | })
|
524 | }
|
525 |
|
526 | |
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 | start (opts: Object = {}): Promise<Container> {
|
533 | const call = {
|
534 | path: `/containers/${this.id}/start?`,
|
535 | method: 'POST',
|
536 | options: opts,
|
537 | statusCodes: {
|
538 | 204: true,
|
539 | 304: true,
|
540 | 404: 'no such container',
|
541 | 500: 'server error'
|
542 | }
|
543 | }
|
544 |
|
545 | return new Promise((resolve, reject) => {
|
546 | this.modem.dial(call, (err) => {
|
547 | if (err) return reject(err)
|
548 | resolve(this)
|
549 | })
|
550 | })
|
551 | }
|
552 |
|
553 | |
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 | stop (opts?: Object): Promise<Container> {
|
560 | const call = {
|
561 | path: `/containers/${this.id}/stop?`,
|
562 | method: 'POST',
|
563 | options: opts,
|
564 | statusCodes: {
|
565 | 204: true,
|
566 | 304: true,
|
567 | 404: 'no such container',
|
568 | 500: 'server error'
|
569 | }
|
570 | }
|
571 |
|
572 | return new Promise((resolve, reject) => {
|
573 | this.modem.dial(call, (err) => {
|
574 | if (err) return reject(err)
|
575 | resolve(this)
|
576 | })
|
577 | })
|
578 | }
|
579 |
|
580 | |
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 | restart (opts?: Object): Promise<Container> {
|
587 | const call = {
|
588 | path: `/containers/${this.id}/restart?`,
|
589 | method: 'POST',
|
590 | options: opts,
|
591 | statusCodes: {
|
592 | 204: true,
|
593 | 404: 'no such container',
|
594 | 500: 'server error'
|
595 | }
|
596 | }
|
597 |
|
598 | return new Promise((resolve, reject) => {
|
599 | this.modem.dial(call, (err) => {
|
600 | if (err) return reject(err)
|
601 | resolve(this)
|
602 | })
|
603 | })
|
604 | }
|
605 |
|
606 | |
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 | kill (opts?: Object): Promise<Container> {
|
613 | const call = {
|
614 | path: `/containers/${this.id}/kill?`,
|
615 | method: 'POST',
|
616 | options: opts,
|
617 | statusCodes: {
|
618 | 204: true,
|
619 | 404: 'no such container',
|
620 | 500: 'server error'
|
621 | }
|
622 | }
|
623 |
|
624 | return new Promise((resolve, reject) => {
|
625 | this.modem.dial(call, (err) => {
|
626 | if (err) return reject(err)
|
627 | resolve(this)
|
628 | })
|
629 | })
|
630 | }
|
631 |
|
632 | |
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 | update (opts?: Object): Promise<Container> {
|
640 | const call = {
|
641 | path: `/containers/${this.id}/update?`,
|
642 | method: 'POST',
|
643 | options: opts,
|
644 | statusCodes: {
|
645 | 200: true,
|
646 | 400: 'bad request',
|
647 | 404: 'no such container',
|
648 | 500: 'server error'
|
649 | }
|
650 | }
|
651 |
|
652 | return new Promise((resolve, reject) => {
|
653 | this.modem.dial(call, (err, warnings: Array<String>) => {
|
654 | const container = new Container(this.modem, this.id)
|
655 | container.Warnings = warnings
|
656 | if (err) return reject(err)
|
657 | resolve(container)
|
658 | })
|
659 | })
|
660 | }
|
661 |
|
662 | |
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 | rename (opts: Object): Promise<Container> {
|
669 | const call = {
|
670 | path: `/containers/${this.id}/rename?`,
|
671 | method: 'POST',
|
672 | options: opts,
|
673 | statusCodes: {
|
674 | 204: true,
|
675 | 404: 'no such container',
|
676 | 409: 'name already taken',
|
677 | 500: 'server error'
|
678 | }
|
679 | }
|
680 |
|
681 | return new Promise((resolve, reject) => {
|
682 | this.modem.dial(call, (err) => {
|
683 | if (err) return reject(err)
|
684 | resolve(this)
|
685 | })
|
686 | })
|
687 | }
|
688 |
|
689 | |
690 |
|
691 |
|
692 |
|
693 |
|
694 | pause (): Promise<Container> {
|
695 | const call = {
|
696 | path: `/containers/${this.id}/pause?`,
|
697 | method: 'POST',
|
698 | options: {},
|
699 | statusCodes: {
|
700 | 204: true,
|
701 | 404: 'no such container',
|
702 | 500: 'server error'
|
703 | }
|
704 | }
|
705 |
|
706 | return new Promise((resolve, reject) => {
|
707 | this.modem.dial(call, (err) => {
|
708 | if (err) return reject(err)
|
709 | resolve(this)
|
710 | })
|
711 | })
|
712 | }
|
713 |
|
714 | |
715 |
|
716 |
|
717 |
|
718 |
|
719 | unpause (): Promise<Container> {
|
720 | const call = {
|
721 | path: `/containers/${this.id}/unpause?`,
|
722 | method: 'POST',
|
723 | options: {},
|
724 | statusCodes: {
|
725 | 204: true,
|
726 | 404: 'no such container',
|
727 | 500: 'server error'
|
728 | }
|
729 | }
|
730 |
|
731 | return new Promise((resolve, reject) => {
|
732 | this.modem.dial(call, (err) => {
|
733 | if (err) return reject(err)
|
734 | resolve(this)
|
735 | })
|
736 | })
|
737 | }
|
738 |
|
739 | |
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 | attach (opts: any = {}): Promise<Array<Object>> {
|
746 | const call = {
|
747 | path: `/containers/${this.id}/attach?`,
|
748 | method: 'POST',
|
749 | isStream: true,
|
750 | openStdin: opts.stdin,
|
751 | options: opts,
|
752 | statusCodes: {
|
753 | 101: true,
|
754 | 200: true,
|
755 | 400: 'bad request',
|
756 | 404: 'no such container',
|
757 | 500: 'server error'
|
758 | }
|
759 | }
|
760 |
|
761 | return new Promise((resolve, reject) => {
|
762 | this.modem.dial(call, (err, stream) => {
|
763 | if (err) return reject(err)
|
764 | resolve([ stream, this ])
|
765 | })
|
766 | })
|
767 | }
|
768 |
|
769 | |
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 | wsattach (opts?: Object): Promise<Array<Object>> {
|
776 | const call = {
|
777 | path: `/containers/${this.id}/attach/ws?`,
|
778 | method: 'GET',
|
779 | options: opts,
|
780 | statusCodes: {
|
781 | 200: true,
|
782 | 400: 'bad request',
|
783 | 404: 'no such container',
|
784 | 500: 'server error'
|
785 | }
|
786 | }
|
787 |
|
788 | return new Promise((resolve, reject) => {
|
789 | this.modem.dial(call, (err, stream) => {
|
790 | if (err) return reject(err)
|
791 | resolve([ stream, this ])
|
792 | })
|
793 | })
|
794 | }
|
795 |
|
796 | |
797 |
|
798 |
|
799 |
|
800 |
|
801 | wait (): Promise<Number> {
|
802 | const call = {
|
803 | path: `/containers/${this.id}/wait?`,
|
804 | method: 'POST',
|
805 | options: {},
|
806 | statusCodes: {
|
807 | 200: true,
|
808 | 404: 'no such container',
|
809 | 500: 'server error'
|
810 | }
|
811 | }
|
812 |
|
813 | return new Promise((resolve, reject) => {
|
814 | this.modem.dial(call, (err, code: Number) => {
|
815 | if (err) return reject(err)
|
816 | resolve(code)
|
817 | })
|
818 | })
|
819 | }
|
820 |
|
821 | |
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 | delete (opts?: Object): Promise<{}> {
|
828 | const call = {
|
829 | path: `/containers/${this.id}?`,
|
830 | method: 'DELETE',
|
831 | options: opts,
|
832 | statusCodes: {
|
833 | 204: true,
|
834 | 400: 'bad request',
|
835 | 404: 'no such container',
|
836 | 500: 'server error'
|
837 | }
|
838 | }
|
839 |
|
840 | return new Promise((resolve, reject) => {
|
841 | this.modem.dial(call, (err) => {
|
842 | if (err) return reject(err)
|
843 | resolve()
|
844 | })
|
845 | })
|
846 | }
|
847 |
|
848 | |
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 | commit (opts: any = {}): Promise<Image> {
|
855 | opts.container = this.id
|
856 |
|
857 | const call = {
|
858 | path: `/commit?`,
|
859 | method: 'POST',
|
860 | options: opts,
|
861 | statusCodes: {
|
862 | 201: true,
|
863 | 404: 'no such container',
|
864 | 500: 'server error'
|
865 | }
|
866 | }
|
867 |
|
868 | return new Promise((resolve, reject) => {
|
869 | this.modem.dial(call, (err, res) => {
|
870 | if (err) return reject(err)
|
871 | resolve(new Image(this.modem, res.Id.replace('sha256:', '')))
|
872 | })
|
873 | })
|
874 | }
|
875 | }
|
876 |
|
877 | export default class {
|
878 | modem: Modem
|
879 |
|
880 | constructor(modem: Modem) {
|
881 | this.modem = modem
|
882 | }
|
883 |
|
884 | |
885 |
|
886 |
|
887 |
|
888 |
|
889 | get (id: String): Container {
|
890 | return new Container(this.modem, id)
|
891 | }
|
892 |
|
893 | |
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 | list (opts?: Object): Promise<Array<Container>> {
|
900 | const call = {
|
901 | path: '/containers/json?',
|
902 | method: 'GET',
|
903 | options: opts,
|
904 | statusCodes: {
|
905 | 200: true,
|
906 | 400: 'bad request',
|
907 | 500: 'server error'
|
908 | }
|
909 | }
|
910 |
|
911 | return new Promise((resolve, reject) => {
|
912 | this.modem.dial(call, (err, containers) => {
|
913 | if (err) return reject(err)
|
914 | resolve(containers.map((conf) => {
|
915 | const container = new Container(this.modem, conf.Id)
|
916 | container.data = conf
|
917 | return container
|
918 | }))
|
919 | })
|
920 | })
|
921 | }
|
922 |
|
923 | |
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 | create (opts?: Object): Promise<Container> {
|
930 | const call = {
|
931 | path: '/containers/create?',
|
932 | method: 'POST',
|
933 | options: opts,
|
934 | statusCodes: {
|
935 | 200: true,
|
936 | 201: true,
|
937 | 400: 'bad request',
|
938 | 404: 'no such image',
|
939 | 406: 'impossible to attach',
|
940 | 500: 'server error'
|
941 | }
|
942 | }
|
943 |
|
944 | return new Promise((resolve, reject) => {
|
945 | this.modem.dial(call, (err, conf) => {
|
946 | if (err) return reject(err)
|
947 | const container = new Container(this.modem, conf.Id)
|
948 | container.data = conf
|
949 | resolve(container)
|
950 | })
|
951 | })
|
952 | }
|
953 |
|
954 | |
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 | prune (opts?: Object): Promise<Object> {
|
961 | const call = {
|
962 | path: `/containers/prune`,
|
963 | method: 'POST',
|
964 | options: opts,
|
965 | statusCodes: {
|
966 | 200: true,
|
967 | 500: 'server error'
|
968 | }
|
969 | }
|
970 |
|
971 | return new Promise((resolve, reject) => {
|
972 | this.modem.dial(call, (err, res: Object) => {
|
973 | if (err) return reject(err)
|
974 | resolve(res)
|
975 | })
|
976 | })
|
977 | }
|
978 | }
|