2017-02-10 01:11:36 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('VolumeService', ['$q', 'Volume', function VolumeServiceFactory($q, Volume) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
2017-02-13 05:16:14 +00:00
|
|
|
service.getVolumes = function() {
|
|
|
|
return Volume.query({}).$promise;
|
|
|
|
};
|
|
|
|
|
2017-02-10 01:11:36 +00:00
|
|
|
function prepareVolumeQueries(template, containerConfig) {
|
|
|
|
var volumeQueries = [];
|
|
|
|
if (template.volumes) {
|
|
|
|
template.volumes.forEach(function (vol) {
|
|
|
|
volumeQueries.push(
|
|
|
|
Volume.create({}, function (d) {
|
|
|
|
if (d.message) {
|
|
|
|
Messages.error("Unable to create volume", {}, d.message);
|
|
|
|
} else {
|
|
|
|
Messages.send("Volume created", d.Name);
|
|
|
|
containerConfig.Volumes[vol] = {};
|
|
|
|
containerConfig.HostConfig.Binds.push(d.Name + ':' + vol);
|
|
|
|
}
|
|
|
|
}, function (e) {
|
|
|
|
Messages.error("Failure", e, "Unable to create volume");
|
|
|
|
}).$promise
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return volumeQueries;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.createVolumes = function(volumes) {
|
|
|
|
var createVolumeQueries = volumes.map(function(volume) {
|
|
|
|
return service.createVolume(volume);
|
|
|
|
});
|
|
|
|
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;
|
|
|
|
}]);
|