UNPKG

1.91 kBJavaScriptView Raw
1var util = require('./util');
2
3/**
4 * Represents a volume
5 * @param {Object} modem docker-modem
6 * @param {String} name Volume's name
7 */
8var Volume = function(modem, name) {
9 this.modem = modem;
10 this.name = name;
11};
12
13Volume.prototype[require('util').inspect.custom] = function() { return this; };
14
15/**
16 * Inspect
17 * @param {Function} callback Callback, if specified Docker will be queried.
18 * @return {Object} Name only if callback isn't specified.
19 */
20Volume.prototype.inspect = function(callback) {
21 var self = this;
22
23 var optsf = {
24 path: '/volumes/' + this.name,
25 method: 'GET',
26 statusCodes: {
27 200: true,
28 404: 'no such volume',
29 500: 'server error'
30 }
31 };
32
33 if(callback === undefined) {
34 return new this.modem.Promise(function(resolve, reject) {
35 self.modem.dial(optsf, function(err, data) {
36 if (err) {
37 return reject(err);
38 }
39 resolve(data);
40 });
41 });
42 } else {
43 this.modem.dial(optsf, function(err, data) {
44 callback(err, data);
45 });
46 }
47};
48
49/**
50 * Removes the volume
51 * @param {[Object]} opts Remove options (optional)
52 * @param {Function} callback Callback
53 */
54Volume.prototype.remove = function(opts, callback) {
55 var self = this;
56 var args = util.processArgs(opts, callback);
57
58 var optsf = {
59 path: '/volumes/' + this.name,
60 method: 'DELETE',
61 statusCodes: {
62 204: true,
63 404: 'no such volume',
64 409: 'conflict',
65 500: 'server error'
66 },
67 options: args.opts
68 };
69
70 if(args.callback === undefined) {
71 return new this.modem.Promise(function(resolve, reject) {
72 self.modem.dial(optsf, function(err, data) {
73 if (err) {
74 return reject(err);
75 }
76 resolve(data);
77 });
78 });
79 } else {
80 this.modem.dial(optsf, function(err, data) {
81 args.callback(err, data);
82 });
83 }
84};
85
86module.exports = Volume;