1 | var util = require('./util');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var Volume = function(modem, name) {
|
9 | this.modem = modem;
|
10 | this.name = name;
|
11 | };
|
12 |
|
13 | Volume.prototype[require('util').inspect.custom] = function() { return this; };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | Volume.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 |
|
51 |
|
52 |
|
53 |
|
54 | Volume.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 |
|
86 | module.exports = Volume;
|