2017-02-10 01:11:36 +00:00
|
|
|
angular.module('portainer.services')
|
2017-04-01 10:18:46 +00:00
|
|
|
.factory('VolumeService', ['$q', 'Volume', 'VolumeHelper', function VolumeServiceFactory($q, Volume, VolumeHelper) {
|
2017-02-10 01:11:36 +00:00
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
2017-02-13 05:16:14 +00:00
|
|
|
service.getVolumes = function() {
|
|
|
|
return Volume.query({}).$promise;
|
|
|
|
};
|
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
service.createVolumeConfiguration = function(name, driver, driverOptions) {
|
|
|
|
var volumeConfiguration = {
|
|
|
|
Name: name,
|
|
|
|
Driver: driver,
|
|
|
|
DriverOpts: VolumeHelper.createDriverOptions(driverOptions)
|
|
|
|
};
|
|
|
|
return volumeConfiguration;
|
|
|
|
};
|
2017-02-10 01:11:36 +00:00
|
|
|
|
|
|
|
service.createVolume = function(volumeConfiguration) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
Volume.create(volumeConfiguration).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
if (data.message) {
|
|
|
|
deferred.reject({ msg: data.message });
|
|
|
|
} else {
|
|
|
|
deferred.resolve(data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to create volume', err: err });
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
service.createVolumes = function(volumeConfigurations) {
|
|
|
|
var createVolumeQueries = volumeConfigurations.map(function(volumeConfiguration) {
|
|
|
|
return service.createVolume(volumeConfiguration);
|
2017-02-10 01:11:36 +00:00
|
|
|
});
|
|
|
|
return $q.all(createVolumeQueries);
|
|
|
|
};
|
|
|
|
|
2017-02-13 05:16:14 +00:00
|
|
|
service.createXAutoGeneratedLocalVolumes = function (x) {
|
|
|
|
var createVolumeQueries = [];
|
|
|
|
for (var i = 0; i < x; i++) {
|
|
|
|
createVolumeQueries.push(service.createVolume({}));
|
|
|
|
}
|
2017-02-10 01:11:36 +00:00
|
|
|
return $q.all(createVolumeQueries);
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}]);
|