Skip to content

Commit

Permalink
Merge pull request #61 from srijs/feature/container-default-options
Browse files Browse the repository at this point in the history
container: introduce per-instance default options
  • Loading branch information
apocas committed Apr 29, 2014
2 parents ba862f3 + f7a30ae commit 230a00a
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
var _ = require('underscore');

var Container = function(modem, id) {
this.modem = modem;
this.id = id;

this.defaultOptions = {
top: {},
start: {},
commit: {},
stop: {},
restart: {},
resize: {},
attach: {},
remove: {},
copy: {}
};

};

Container.prototype.inspect = function(callback) {
Expand Down Expand Up @@ -37,7 +52,7 @@ Container.prototype.top = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.top, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand Down Expand Up @@ -92,7 +107,7 @@ Container.prototype.start = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.start, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand All @@ -116,7 +131,7 @@ Container.prototype.commit = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.commit, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand All @@ -138,7 +153,7 @@ Container.prototype.stop = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.stop, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand All @@ -160,7 +175,7 @@ Container.prototype.restart = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.restart, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand Down Expand Up @@ -188,7 +203,7 @@ Container.prototype.resize = function(opts, callback) {
var optsf = {
path: '/containers/' + this.id + '/resize?',
method: 'POST',
options: opts,
options: _.extend({}, this.defaultOptions.resize, opts),
statusCodes: {
200: true,
400: 'bad parameter',
Expand All @@ -206,7 +221,7 @@ Container.prototype.attach = function(opts, callback) {
var optsf = {
path: '/containers/' + this.id + '/attach?',
method: 'POST',
options: opts,
options: _.extend({}, this.defaultOptions.attach, opts),
isStream: true,
openStdin: opts.stdin,
statusCodes: {
Expand Down Expand Up @@ -253,7 +268,7 @@ Container.prototype.remove = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.remove, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand All @@ -271,7 +286,7 @@ Container.prototype.copy = function(opts, callback) {
404: "no such container",
500: "server error"
},
options: opts
options: _.extend({}, this.defaultOptions.copy, opts)
};

this.modem.dial(optsf, function(err, data) {
Expand Down

0 comments on commit 230a00a

Please sign in to comment.