mirror of https://github.com/portainer/portainer
feat(volumes): check if volumes are used in service definitions (#1601)
parent
672819f3af
commit
f31f29fa2f
|
@ -1,6 +1,6 @@
|
|||
angular.module('volumes', [])
|
||||
.controller('VolumesController', ['$q', '$scope', '$state', 'VolumeService', 'Notifications',
|
||||
function ($q, $scope, $state, VolumeService, Notifications) {
|
||||
.controller('VolumesController', ['$q', '$scope', '$state', 'VolumeService', 'ServiceService', 'VolumeHelper', 'Notifications',
|
||||
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications) {
|
||||
|
||||
$scope.removeAction = function (selectedItems) {
|
||||
var actionCount = selectedItems.length;
|
||||
|
@ -24,16 +24,24 @@ function ($q, $scope, $state, VolumeService, Notifications) {
|
|||
};
|
||||
|
||||
function initView() {
|
||||
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
||||
var endpointRole = $scope.applicationState.endpoint.mode.role;
|
||||
|
||||
$q.all({
|
||||
attached: VolumeService.volumes({ filters: { 'dangling': ['false'] } }),
|
||||
dangling: VolumeService.volumes({ filters: { 'dangling': ['true'] } })
|
||||
dangling: VolumeService.volumes({ filters: { 'dangling': ['true'] } }),
|
||||
services: endpointProvider === 'DOCKER_SWARM_MODE' && endpointRole === 'MANAGER' ? ServiceService.services() : []
|
||||
})
|
||||
.then(function success(data) {
|
||||
var services = data.services;
|
||||
$scope.volumes = data.attached.map(function(volume) {
|
||||
volume.dangling = false;
|
||||
return volume;
|
||||
}).concat(data.dangling.map(function(volume) {
|
||||
volume.dangling = true;
|
||||
if (VolumeHelper.isVolumeUsedByAService(volume, services)) {
|
||||
volume.dangling = false;
|
||||
}
|
||||
return volume;
|
||||
}));
|
||||
}).catch(function error(err) {
|
||||
|
|
|
@ -11,5 +11,20 @@ angular.module('portainer.helpers')
|
|||
return options;
|
||||
};
|
||||
|
||||
helper.isVolumeUsedByAService = function(volume, services) {
|
||||
for (var i = 0; i < services.length; i++) {
|
||||
var service = services[i];
|
||||
var mounts = service.Mounts;
|
||||
for (var j = 0; j < mounts.length; j++) {
|
||||
var mount = mounts[j];
|
||||
if (mount.Source === volume.Id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
return helper;
|
||||
}]);
|
||||
|
|
Loading…
Reference in New Issue