1- var _ = require ( 'underscore' ) ;
1+ var _ = require ( 'underscore' ) ,
2+ Exec = require ( './exec' ) ;
23
34/**
45 * Represents a Container
@@ -10,17 +11,17 @@ var Container = function(modem, id) {
1011 this . id = id ;
1112
1213 this . defaultOptions = {
13- top : { } ,
14- start : { } ,
15- commit : { } ,
16- stop : { } ,
14+ top : { } ,
15+ start : { } ,
16+ commit : { } ,
17+ stop : { } ,
1718 restart : { } ,
18- resize : { } ,
19- attach : { } ,
20- remove : { } ,
21- copy : { } ,
22- kill : { } ,
23- exec : { }
19+ resize : { } ,
20+ attach : { } ,
21+ remove : { } ,
22+ copy : { } ,
23+ kill : { } ,
24+ exec : { }
2425 } ;
2526} ;
2627
@@ -45,7 +46,9 @@ Container.prototype.inspect = function(callback) {
4546 callback ( err , data ) ;
4647 } ) ;
4748 } else {
48- return JSON . stringify ( { id : this . id } ) ;
49+ return JSON . stringify ( {
50+ id : this . id
51+ } ) ;
4952 }
5053} ;
5154
@@ -147,7 +150,6 @@ Container.prototype.start = function(opts, callback) {
147150
148151/**
149152 * Pause
150- * Warning: Uses an undocumented Docker endpoint. :)
151153 * @param {Object } opts Pause options (optional)
152154 * @param {Function } callback Callback
153155 */
@@ -174,7 +176,6 @@ Container.prototype.pause = function(opts, callback) {
174176
175177/**
176178 * Unpause
177- * Warning: Uses an undocumented Docker endpoint. :)
178179 * @param {Object } opts Unpause options (optional)
179180 * @param {Function } callback Callback
180181 */
@@ -206,53 +207,28 @@ Container.prototype.unpause = function(opts, callback) {
206207 * @param {function } callback
207208 */
208209Container . prototype . exec = function ( opts , callback ) {
209- if ( ! callback && typeof ( opts ) === 'function' ) {
210- callback = opts ;
211- opts = null ;
212- }
210+ var self = this ;
213211
214- var optsf = {
215- path : '/containers/' + this . id + '/exec' ,
216- method : 'POST' ,
217- statusCodes : {
218- 201 : true ,
219- 404 : "no such container" ,
220- 500 : "server error"
221- } ,
222- options : _ . extend ( { } , this . defaultOptions . exec , opts )
223- } ;
224-
225- this . modem . dial ( optsf , function ( err , data ) {
226- callback ( err , data ) ;
227- } ) ;
228- } ;
212+ if ( ! callback && typeof ( opts ) === 'function' ) {
213+ callback = opts ;
214+ opts = { } ;
215+ }
229216
230- /**
231- * Run the exec call that was setup.
232- *
233- * @param {object } opts should be passed from exec call return {Id:xxxxxx}
234- * @param {function } callback
235- */
236- Container . prototype . execstart = function ( id , opts , callback ) {
237- if ( ! callback && typeof ( opts ) === 'function' ) {
238- callback = opts ;
239- opts = null ;
240- }
241- var optsf = {
242- path : '/exec/' + id + '/start' ,
243- method : 'POST' ,
244- isStream : true ,
245- statusCodes : {
246- 200 : true ,
247- 404 : "no such container" ,
248- 500 : "Container not running"
249- } ,
250- options : _ . extend ( { } , this . defaultOptions . exec , opts )
251- } ;
217+ var optsf = {
218+ path : '/containers/' + this . id + '/exec' ,
219+ method : 'POST' ,
220+ statusCodes : {
221+ 201 : true ,
222+ 404 : "no such container" ,
223+ 500 : "server error"
224+ } ,
225+ options : _ . extend ( { } , this . defaultOptions . exec , opts )
226+ } ;
252227
253- this . modem . dial ( optsf , function ( err , data ) {
254- callback ( err , data ) ;
255- } ) ;
228+ this . modem . dial ( optsf , function ( err , data ) {
229+ if ( err ) return callback ( err , data ) ;
230+ callback ( err , new Exec ( self . modem , data . Id ) ) ;
231+ } ) ;
256232} ;
257233
258234/**
0 commit comments