summaryrefslogtreecommitdiff
path: root/openstack_dashboard/static/app/core/openstack-service-api/cinder.service.js
blob: f5d3107f9434268fae741402d24b2d077b21ee2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/**
 * Copyright 2015 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
(function () {
  'use strict';

  angular
    .module('horizon.app.core.openstack-service-api')
    .factory('horizon.app.core.openstack-service-api.cinder', cinderAPI);

  cinderAPI.$inject = [
    'horizon.framework.util.http.service',
    'horizon.framework.widgets.toast.service'
  ];

  /**
   * @ngdoc service
   * @param {Object} apiService
   * @param {Object} toastService
   * @name cinder
   * @description Provides direct access to Cinder APIs.
   * @returns {Object} The service
   */
  function cinderAPI(apiService, toastService) {
    var service = {
      getVolumes: getVolumes,
      getVolume: getVolume,
      getVolumeTypes: getVolumeTypes,
      getVolumeMetadata: getVolumeMetadata,
      getVolumeSnapshotMetadata: getVolumeSnapshotMetadata,
      getVolumeTypeMetadata: getVolumeTypeMetadata,
      getVolumeType: getVolumeType,
      getDefaultVolumeType: getDefaultVolumeType,
      getVolumeSnapshots: getVolumeSnapshots,
      getExtensions: getExtensions,
      getQoSSpecs: getQoSSpecs,
      getAvailabilityZones:getAvailabilityZones,
      createVolume: createVolume,
      getAbsoluteLimits: getAbsoluteLimits,
      getServices: getServices,
      getDefaultQuotaSets: getDefaultQuotaSets,
      setDefaultQuotaSets: setDefaultQuotaSets,
      updateProjectQuota: updateProjectQuota,
      editVolumeMetadata: editVolumeMetadata,
      editVolumeSnapshotMetadata: editVolumeSnapshotMetadata,
      editVolumeTypeMetadata:editVolumeTypeMetadata
    };

    return service;

    ///////////////

    // Volumes

    /**
     * @name getVolumes
     * @description
     * Get a list of volumes.
     *
     * The listing result is an object with property "items." Each item is
     * a volume.
     *
     * @param {Object} params
     * Query parameters. Optional.
     *
     * @param {boolean} params.paginate
     * True to paginate automatically.
     *
     * @param {string} params.marker
     * Specifies the image of the last-seen image.
     *
     * The typical pattern of limit and marker is to make an
     * initial limited request and then to use the last
     * image from the response as the marker parameter
     * in a subsequent limited request. With paginate, limit
     * is automatically set.
     *
     * @param {string} params.sort_dir
     * The sort direction ('asc' or 'desc').
     *
     * @param {string} param.search_opts
     * Filters to pass through the API.
     * For example, "status": "available" will show all available volumes.
     * @returns {Object} The result of the API call
     */
    function getVolumes(params) {
      var config = params ? {'params': params} : {};
      return apiService.get('/api/cinder/volumes/', config)
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volumes.'));
        });
    }

    /**
     * @name getVolume
     * @description
     * Get a single Volume by ID.
     *
     * @param {string} id
     * Specifies the id of the Volume to request.
     *
     * @returns {Object} The result of the API call
     */
    function getVolume(id) {
      return apiService.get('/api/cinder/volumes/' + id)
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volume.'));
        });
    }

    /**
     * @name createVolume
     * @param {Object} newVolume - The new volume object
     * @description
     * Create a volume.
     * @returns {Object} The result of the API call
     */
    function createVolume(newVolume) {
      return apiService.post('/api/cinder/volumes/', newVolume)
        .error(function () {
          toastService.add('error', gettext('Unable to create the volume.'));
        });
    }

    // Volume Types

    /**
     * @name getVolumeTypes
     * @description
     * Get a list of volume types.
     *
     * The listing result is an object with property "items." Each item is
     * a volume type.
     *
     * @returns {Object} The result of the API call
     */
    function getVolumeTypes() {
      return apiService.get('/api/cinder/volumetypes/')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volume types.'));
        });
    }

    function getVolumeMetadata(id) {
      return apiService.get('/api/cinder/volumes/' + id + '/metadata')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volume metadata.'));
        });
    }

    function getVolumeSnapshotMetadata(id) {
      return apiService.get('/api/cinder/volumesnapshots/' + id + '/metadata')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the snapshot metadata.'));
        });
    }

    function getVolumeTypeMetadata(id) {
      return apiService.get('/api/cinder/volumetypes/' + id + '/metadata')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volume type metadata.'));
        });
    }

    function editVolumeMetadata(id, updated, removed) {
      return apiService.patch(
        '/api/cinder/volumes/' + id + '/metadata',
        {
          updated: updated,
          removed: removed
        }
      ).error(function () {
        toastService.add('error', gettext('Unable to edit volume metadata.'));
      });
    }

    function editVolumeSnapshotMetadata(id, updated, removed) {
      return apiService.patch(
        '/api/cinder/volumesnapshots/' + id + '/metadata',
        {
          updated: updated,
          removed: removed
        }
      ).error(function () {
        toastService.add('error', gettext('Unable to edit snapshot metadata.'));
      });
    }

    function editVolumeTypeMetadata(id, updated, removed) {
      return apiService.patch(
        '/api/cinder/volumetypes/' + id + '/metadata',
        {
          updated: updated,
          removed: removed
        }
      ).error(function () {
        toastService.add('error', gettext('Unable to edit volume type metadata.'));
      });
    }

    /**
     * @name getVolumeType
     * @description
     * Get a single Volume Type by ID.
     *
     * @param {string} id
     * Specifies the id of the Volume Type to request.
     *
     * @returns {Object} The result of the API call
     */
    function getVolumeType(id) {
      return apiService.get('/api/cinder/volumetypes/' + id)
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volume type.'));
        });
    }

    /**
     * @name getDefaultVolumeType
     * @description
     * Get the default Volume Type
     *
     * @returns {Object} The result of the API call
     */
    function getDefaultVolumeType() {
      return apiService.get('/api/cinder/volumetypes/default')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the default volume type.'));
        });
    }

    // Volume Snapshots

    /**
     * @name getVolumeSnapshots
     * @description
     * Get a list of volume snapshots.
     *
     * The listing result is an object with property "items." Each item is
     * a volume snapshot.
     *
     * @param {Object} params
     * Query parameters. Optional.
     *
     * @param {string} param.search_opts
     * Filters to pass through the API.
     * For example, "status": "available" will show all available volume
     * snapshots.
     * @returns {Object} The result of the API call
     */
    function getVolumeSnapshots(params) {
      var config = params ? {'params': params} : {};
      return apiService.get('/api/cinder/volumesnapshots/', config)
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the volume snapshots.'));
        });
    }

    // Cinder Extensions

    /**
     * @name getExtensions
     * @param {Object} config - The configuration for retrieving the extensions
     * @description
     * Returns a list of enabled extensions.
     *
     * The listing result is an object with property "items". Each item is
     * an extension.
     * @example
     * The following is an example response:
     *
     *  {
     *    "items": [
     *      {
     *        "alias": "NMN",
     *        "description": "Multiple network support.",
     *        "links": [],
     *        "name": "Multinic",
     *        "namespace": "http://docs.openstack.org/compute/ext/multinic/api/v1.1",
     *        "updated": "2011-06-09T00:00:00Z"
     *      }
     *    ]
     *  }
     * @returns {Object} The result of the API call
     */
    function getExtensions(config) {
      return apiService.get('/api/cinder/extensions/', config)
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the extensions.'));
        });
    }

    // Cinder Services

    /**
    * @name getServices
    * @description Get the list of Cinder services.
    *
    * @returns {Object} An object with property "services." Each item is
    * a service.
    */
    function getServices() {
      return apiService.get('/api/cinder/services/')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the cinder services.'));
        });
    }

    /**
     * @name getQoSSpecs
     * @description
     * Get a list of Quality of Service.
     *
     * The listing result is an object with property "items." Each item is
     * a Quality of Service Spec.
     *
     * @param {Object} params
     * Query parameters. Optional.
     * @returns {Object} The result of the API call
     *
     */
    function getQoSSpecs(params) {
      var config = params ? {'params': params} : {};
      return apiService.get('/api/cinder/qosspecs/', config)
        .error(function () {
          toastService.add('error',
            gettext('Unable to retrieve the QoS Specs.'));
        });
    }

    /**
     * @name getAbsoluteLimits
     * @description
     * Get the limits for the current tenant.
     *
     * @returns {Object} The result of the API call
     */
    function getAbsoluteLimits() {
      return apiService.get('/api/cinder/tenantabsolutelimits/')
        .error(function () {
          toastService.add('error',
            gettext('Unable to retrieve the Absolute Limits.'));
        });
    }

    // Default Quota Sets

    /**
     * @name horizon.app.core.openstack-service-api.cinder.getDefaultQuotaSets
     * @description
     * Get default quotasets
     *
     * The listing result is an object with property "items." Each item is
     * a quota.
     *
     */
    function getDefaultQuotaSets() {
      return apiService.get('/api/cinder/quota-sets/defaults/')
        .error(function () {
          toastService.add('error', gettext('Unable to retrieve the default quotas.'));
        });
    }

    /**
     * @name horizon.app.core.openstack-service-api.cinder.setDefaultQuotaSets
     * @description
     * Set default quota sets
     *
     */
    function setDefaultQuotaSets(quotas) {
      return apiService.patch('/api/cinder/quota-sets/defaults/', quotas)
        .error(function () {
          toastService.add('error', gettext('Unable to set the default quotas.'));
        });
    }

    // Quota Sets

    /**
     * @name updateProjectQuota
     * @description
     * Update a single project quota data.
     * @param {application/json} quota
     * A JSON object with the attributes to set to new quota values.
     * @param {string} projectId
     * Specifies the id of the project that'll have the quota data updated.
     */
    function updateProjectQuota(quota, projectId) {
      var url = '/api/cinder/quota-sets/' + projectId;
      return apiService.patch(url, quota)
        .error(function() {
          toastService.add('error', gettext('Unable to update project quota data.'));
        });
    }

    // Availability Zones

    /**
     * @name getAvailabilityZones
     * @description
     * Get a list of Availability Zones.
     *
     * The listing result is an object with property "items". Each item is
     * an availability zone.
     * @returns {Object} The result of the API call
     */
    function getAvailabilityZones() {
      return apiService.get('/api/cinder/availzones/')
        .error(function () {
          toastService.add('error',
                        gettext('Unable to retrieve the volume availability zones.'));
        });
    }
  }

}());