1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | /**
|
4 | * Class representing a volume
|
5 | */
|
6 | class Volume {
|
7 | /**
|
8 | * Create a volume
|
9 | * @param {Modem} modem Modem to connect to the remote service
|
10 | * @param {string} id Id of the volume (optional)
|
11 | */
|
12 | constructor(modem, id) {
|
13 | this.data = {};
|
14 | this.modem = modem;
|
15 | this.id = id;
|
16 | }
|
17 | /**
|
18 | * Get low-level information on a volume
|
19 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/inspect-a-volume
|
20 | * The reason why this module isn't called inspect is because that interferes with the inspect utility of node.
|
21 | * @param {Object} opts Query params in the request (optional)
|
22 | * @param {String} id ID of the volume to inspect, if it's not set, use the id of the object (optional)
|
23 | * @return {Promise} Promise return the volume
|
24 | */
|
25 | status(opts) {
|
26 | const call = {
|
27 | path: `/volumes/${this.id}?`,
|
28 | method: 'GET',
|
29 | options: opts,
|
30 | statusCodes: {
|
31 | 200: true,
|
32 | 404: 'no such volume',
|
33 | 500: 'server error'
|
34 | }
|
35 | };
|
36 | return new Promise((resolve, reject) => {
|
37 | this.modem.dial(call, (err, conf) => {
|
38 | if (err)
|
39 | return reject(err);
|
40 | const volume = new Volume(this.modem, this.id);
|
41 | volume.data = conf;
|
42 | resolve(volume);
|
43 | });
|
44 | });
|
45 | }
|
46 | /**
|
47 | * Remove a volume from the filesystem
|
48 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/remove-a-volume
|
49 | * @param {Object} opts Query params in the request (optional)
|
50 | * @param {String} id ID of the volume to inspect, if it's not set, use the id of the object (optional)
|
51 | * @return {Promise} Promise return the result
|
52 | */
|
53 | remove(opts) {
|
54 | const call = {
|
55 | path: `/volumes/${this.id}?`,
|
56 | method: 'DELETE',
|
57 | options: opts,
|
58 | statusCodes: {
|
59 | 204: true,
|
60 | 404: 'no such volume',
|
61 | 409: 'conflict',
|
62 | 500: 'server error'
|
63 | }
|
64 | };
|
65 | return new Promise((resolve, reject) => {
|
66 | this.modem.dial(call, (err) => {
|
67 | if (err)
|
68 | return reject(err);
|
69 | resolve();
|
70 | });
|
71 | });
|
72 | }
|
73 | }
|
74 | exports.Volume = Volume;
|
75 | class default_1 {
|
76 | /**
|
77 | * Create a volume
|
78 | * @param {Modem} modem Modem to connect to the remote service
|
79 | * @param {string} id Id of the volume (optional)
|
80 | */
|
81 | constructor(modem) {
|
82 | this.modem = modem;
|
83 | }
|
84 | /**
|
85 | * Get a Volume object
|
86 | * @param {id} String ID of the secret
|
87 | * @return {Volume}
|
88 | */
|
89 | get(id) {
|
90 | return new Volume(this.modem, id);
|
91 | }
|
92 | /**
|
93 | * Get the list of volumes
|
94 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-volumes
|
95 | * @param {Object} opts Query params in the request (optional)
|
96 | * @return {Promise} Promise returning the result as a list of volumes
|
97 | */
|
98 | list(opts) {
|
99 | const call = {
|
100 | path: '/volumes',
|
101 | method: 'GET',
|
102 | options: opts,
|
103 | statusCodes: {
|
104 | 200: true,
|
105 | 500: 'server error'
|
106 | }
|
107 | };
|
108 | return new Promise((resolve, reject) => {
|
109 | this.modem.dial(call, (err, result) => {
|
110 | if (err)
|
111 | return reject(err);
|
112 | if (!result.Volumes || !result.Volumes.length)
|
113 | return resolve([]);
|
114 | resolve(result.Volumes.map((conf) => {
|
115 | const volume = new Volume(this.modem, conf.Name);
|
116 | volume.data = conf;
|
117 | return volume;
|
118 | }));
|
119 | });
|
120 | });
|
121 | }
|
122 | /**
|
123 | * Create a volume
|
124 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/create-a-volume
|
125 | * @param {Object} opts Query params in the request (optional)
|
126 | * @return {Promise} Promise return the new volume
|
127 | */
|
128 | create(opts) {
|
129 | const call = {
|
130 | path: '/volumes/create?',
|
131 | method: 'POST',
|
132 | options: opts,
|
133 | statusCodes: {
|
134 | 201: true,
|
135 | 500: 'server error'
|
136 | }
|
137 | };
|
138 | return new Promise((resolve, reject) => {
|
139 | this.modem.dial(call, (err, conf) => {
|
140 | if (err)
|
141 | return reject(err);
|
142 | const volume = new Volume(this.modem, conf.Name);
|
143 | volume.data;
|
144 | resolve(volume);
|
145 | });
|
146 | });
|
147 | }
|
148 | /**
|
149 | * Prune volumes
|
150 | * https://docs.docker.com/engine/api/v1.25/#operation/VolumePrune
|
151 | * @param {Object} opts Query params in the request (optional)
|
152 | * @return {Promise} Promise returning the container
|
153 | */
|
154 | prune(opts) {
|
155 | const call = {
|
156 | path: `/volumes/prune`,
|
157 | method: 'POST',
|
158 | options: opts,
|
159 | statusCodes: {
|
160 | 200: true,
|
161 | 500: 'server error'
|
162 | }
|
163 | };
|
164 | return new Promise((resolve, reject) => {
|
165 | this.modem.dial(call, (err, res) => {
|
166 | if (err)
|
167 | return reject(err);
|
168 | resolve(res);
|
169 | });
|
170 | });
|
171 | }
|
172 | }
|
173 | exports.default = default_1;
|
174 | //# sourceMappingURL=volume.js.map |
\ | No newline at end of file |