2016-06-14 02:13:52 +00:00
|
|
|
angular.module('network', [])
|
2017-06-01 08:14:55 +00:00
|
|
|
.controller('NetworkController', ['$scope', '$state', '$stateParams', '$filter', 'Network', 'Container', 'ContainerHelper', 'Notifications',
|
|
|
|
function ($scope, $state, $stateParams, $filter, Network, Container, ContainerHelper, Notifications) {
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2016-09-14 05:48:20 +00:00
|
|
|
$scope.removeNetwork = function removeNetwork(networkId) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Network.remove({id: $stateParams.id}, function (d) {
|
2016-09-01 00:20:19 +00:00
|
|
|
if (d.message) {
|
2016-08-31 23:31:25 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Error', d, 'Unable to remove network');
|
2016-08-31 23:31:25 +00:00
|
|
|
} else {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Network removed', $stateParams.id);
|
2016-08-31 23:31:25 +00:00
|
|
|
$state.go('networks', {});
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', e, 'Unable to remove network');
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
2015-12-21 01:13:53 +00:00
|
|
|
|
2016-12-25 20:28:54 +00:00
|
|
|
$scope.containerLeaveNetwork = function containerLeaveNetwork(network, containerId) {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
Network.disconnect({id: $stateParams.id}, { Container: containerId, Force: false }, function (d) {
|
|
|
|
if (d.message) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Error', d, 'Unable to disconnect container from network');
|
2016-12-25 20:28:54 +00:00
|
|
|
} else {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Container left network', $stateParams.id);
|
2016-12-25 20:28:54 +00:00
|
|
|
$state.go('network', {id: network.Id}, {reload: true});
|
|
|
|
}
|
|
|
|
}, function (e) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', e, 'Unable to disconnect container from network');
|
2016-12-25 20:28:54 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-23 03:06:51 +00:00
|
|
|
function filterContainersInNetwork(network, containers) {
|
|
|
|
var containersInNetwork = [];
|
|
|
|
containers.forEach(function(container) {
|
|
|
|
var containerInNetwork = network.Containers[container.Id];
|
|
|
|
containerInNetwork.Id = container.Id;
|
|
|
|
// Name is not available in Docker 1.9
|
|
|
|
if (!containerInNetwork.Name) {
|
|
|
|
containerInNetwork.Name = $filter('trimcontainername')(container.Names[0]);
|
|
|
|
}
|
|
|
|
containersInNetwork.push(containerInNetwork);
|
2016-12-25 20:28:54 +00:00
|
|
|
});
|
2017-01-23 03:06:51 +00:00
|
|
|
$scope.containersInNetwork = containersInNetwork;
|
2016-12-25 20:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getContainersInNetwork(network) {
|
2017-08-13 11:31:50 +00:00
|
|
|
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
2016-12-25 20:28:54 +00:00
|
|
|
if (network.Containers) {
|
2017-08-13 11:31:50 +00:00
|
|
|
if (apiVersion < 1.24) {
|
2017-01-23 03:06:51 +00:00
|
|
|
Container.query({}, function success(data) {
|
|
|
|
var containersInNetwork = data.filter(function filter(container) {
|
|
|
|
if (container.HostConfig.NetworkMode === network.Name) {
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
filterContainersInNetwork(network, containersInNetwork);
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
}, function error(err) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve containers in network');
|
2016-12-25 20:28:54 +00:00
|
|
|
});
|
2017-01-23 03:06:51 +00:00
|
|
|
} else {
|
|
|
|
Container.query({
|
|
|
|
filters: {network: [$stateParams.id]}
|
|
|
|
}, function success(data) {
|
|
|
|
filterContainersInNetwork(network, data);
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
}, function error(err) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve containers in network');
|
2017-01-23 03:06:51 +00:00
|
|
|
});
|
|
|
|
}
|
2016-12-25 20:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
function initView() {
|
|
|
|
$('#loadingViewSpinner').show();
|
2017-08-13 11:31:50 +00:00
|
|
|
Network.get({id: $stateParams.id}).$promise
|
|
|
|
.then(function success(data) {
|
2017-06-01 08:14:55 +00:00
|
|
|
$scope.network = data;
|
2017-08-13 11:31:50 +00:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
|
|
|
if (endpointProvider !== 'VMWARE_VIC') {
|
|
|
|
getContainersInNetwork(data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-06-01 08:14:55 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve network info');
|
2017-08-13 11:31:50 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-06-01 08:14:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|