2016-08-17 05:25:42 +00:00
|
|
|
angular.module('createNetwork', [])
|
2017-07-10 07:33:09 +00:00
|
|
|
.controller('CreateNetworkController', ['$scope', '$state', 'Notifications', 'Network', 'LabelHelper',
|
|
|
|
function ($scope, $state, Notifications, Network, LabelHelper) {
|
2016-08-17 05:25:42 +00:00
|
|
|
$scope.formValues = {
|
|
|
|
DriverOptions: [],
|
|
|
|
Subnet: '',
|
2016-12-25 20:32:17 +00:00
|
|
|
Gateway: '',
|
|
|
|
Labels: []
|
2016-08-17 05:25:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.config = {
|
|
|
|
Driver: 'bridge',
|
|
|
|
CheckDuplicate: true,
|
|
|
|
Internal: false,
|
2016-09-23 04:54:58 +00:00
|
|
|
// Force IPAM Driver to 'default', should not be required.
|
|
|
|
// See: https://github.com/docker/docker/issues/25735
|
2016-08-17 05:25:42 +00:00
|
|
|
IPAM: {
|
2016-09-23 04:54:58 +00:00
|
|
|
Driver: 'default',
|
2016-08-17 05:25:42 +00:00
|
|
|
Config: []
|
2016-12-25 20:32:17 +00:00
|
|
|
},
|
|
|
|
Labels: {}
|
2016-08-17 05:25:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addDriverOption = function() {
|
|
|
|
$scope.formValues.DriverOptions.push({ name: '', value: '' });
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeDriverOption = function(index) {
|
|
|
|
$scope.formValues.DriverOptions.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2016-12-25 20:32:17 +00:00
|
|
|
$scope.addLabel = function() {
|
2017-07-10 07:33:09 +00:00
|
|
|
$scope.formValues.Labels.push({ key: '', value: ''});
|
2016-12-25 20:32:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeLabel = function(index) {
|
|
|
|
$scope.formValues.Labels.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2016-08-17 05:25:42 +00:00
|
|
|
function createNetwork(config) {
|
|
|
|
$('#createNetworkSpinner').show();
|
|
|
|
Network.create(config, function (d) {
|
2016-09-02 03:25:20 +00:00
|
|
|
if (d.message) {
|
2016-08-17 05:25:42 +00:00
|
|
|
$('#createNetworkSpinner').hide();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error('Unable to create network', {}, d.message);
|
2016-08-17 05:25:42 +00:00
|
|
|
} else {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Network created', d.Id);
|
2016-08-17 05:25:42 +00:00
|
|
|
$('#createNetworkSpinner').hide();
|
2016-09-02 03:25:20 +00:00
|
|
|
$state.go('networks', {}, {reload: true});
|
2016-08-17 05:25:42 +00:00
|
|
|
}
|
|
|
|
}, function (e) {
|
|
|
|
$('#createNetworkSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', e, 'Unable to create network');
|
2016-08-17 05:25:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareIPAMConfiguration(config) {
|
|
|
|
if ($scope.formValues.Subnet) {
|
|
|
|
var ipamConfig = {};
|
|
|
|
ipamConfig.Subnet = $scope.formValues.Subnet;
|
|
|
|
if ($scope.formValues.Gateway) {
|
|
|
|
ipamConfig.Gateway = $scope.formValues.Gateway ;
|
|
|
|
}
|
|
|
|
config.IPAM.Config.push(ipamConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareDriverOptions(config) {
|
|
|
|
var options = {};
|
|
|
|
$scope.formValues.DriverOptions.forEach(function (option) {
|
|
|
|
options[option.name] = option.value;
|
|
|
|
});
|
|
|
|
config.Options = options;
|
|
|
|
}
|
|
|
|
|
2016-12-25 20:32:17 +00:00
|
|
|
function prepareLabelsConfig(config) {
|
2017-07-10 07:33:09 +00:00
|
|
|
config.Labels = LabelHelper.fromKeyValueToLabelHash($scope.formValues.Labels);
|
2016-12-25 20:32:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 05:25:42 +00:00
|
|
|
function prepareConfiguration() {
|
|
|
|
var config = angular.copy($scope.config);
|
|
|
|
prepareIPAMConfiguration(config);
|
|
|
|
prepareDriverOptions(config);
|
2016-12-25 20:32:17 +00:00
|
|
|
prepareLabelsConfig(config);
|
2016-08-17 05:25:42 +00:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.create = function () {
|
|
|
|
var config = prepareConfiguration();
|
|
|
|
createNetwork(config);
|
|
|
|
};
|
|
|
|
}]);
|