feat(container-creation): add the ability to use container as a network

pull/345/merge
Rob Brazier 8 years ago committed by Anthony Lapenna
parent 2c49d3b5d9
commit 643769d4a6

@ -1,12 +1,13 @@
angular.module('createContainer', [])
.controller('CreateContainerController', ['$scope', '$state', '$stateParams', 'Config', 'Info', 'Container', 'Image', 'Volume', 'Network', 'Messages',
function ($scope, $state, $stateParams, Config, Info, Container, Image, Volume, Network, Messages) {
.controller('CreateContainerController', ['$scope', '$state', '$stateParams', '$filter', 'Config', 'Info', 'Container', 'ContainerHelper', 'Image', 'Volume', 'Network', 'Messages',
function ($scope, $state, $stateParams, $filter, Config, Info, Container, ContainerHelper, Image, Volume, Network, Messages) {
$scope.formValues = {
alwaysPull: true,
Console: 'none',
Volumes: [],
Registry: ''
Registry: '',
NetworkContainer: ''
};
$scope.imageConfig = {};
@ -51,12 +52,13 @@ function ($scope, $state, $stateParams, Config, Info, Container, Image, Volume,
};
Config.$promise.then(function (c) {
var swarm = c.swarm;
$scope.swarm = c.swarm;
Info.get({}, function(info) {
if (swarm && !_.startsWith(info.ServerVersion, 'swarm')) {
if ($scope.swarm && !_.startsWith(info.ServerVersion, 'swarm')) {
$scope.swarm_mode = true;
}
});
var containersToHideLabels = c.hiddenLabels;
Volume.query({}, function (d) {
$scope.availableVolumes = d.Volumes;
@ -66,7 +68,7 @@ function ($scope, $state, $stateParams, Config, Info, Container, Image, Volume,
Network.query({}, function (d) {
var networks = d;
if (swarm) {
if ($scope.swarm) {
networks = d.filter(function (network) {
if (network.Scope === 'global') {
return network;
@ -77,6 +79,7 @@ function ($scope, $state, $stateParams, Config, Info, Container, Image, Volume,
networks.push({Name: "host"});
networks.push({Name: "none"});
}
networks.push({Name: "container"});
$scope.availableNetworks = networks;
if (!_.find(networks, {'Name': 'bridge'})) {
$scope.config.HostConfig.NetworkMode = 'nat';
@ -84,6 +87,16 @@ function ($scope, $state, $stateParams, Config, Info, Container, Image, Volume,
}, function (e) {
Messages.error("Failure", e, "Unable to retrieve networks");
});
Container.query({}, function (d) {
var containers = d;
if (containersToHideLabels) {
containers = ContainerHelper.hideContainers(d, containersToHideLabels);
}
$scope.runningContainers = containers;
}, function(e) {
Messages.error("Failure", e, "Unable to retrieve running containers");
});
});
// TODO: centralize, already present in templatesController
@ -217,8 +230,26 @@ function ($scope, $state, $stateParams, Config, Info, Container, Image, Volume,
config.Volumes = volumes;
}
function prepareNetworkConfig(config) {
var mode = config.HostConfig.NetworkMode;
var container = $scope.formValues.NetworkContainer;
var containerName = container;
if (container && typeof container === 'object') {
containerName = $filter('trimcontainername')(container.Names[0]);
if ($scope.swarm && !$scope.swarm_mode) {
containerName = $filter('swarmcontainername')(container);
}
}
var networkMode = mode;
if (containerName) {
networkMode += ':' + containerName;
}
config.HostConfig.NetworkMode = networkMode;
}
function prepareConfiguration() {
var config = angular.copy($scope.config);
prepareNetworkConfig(config);
prepareImageConfig(config);
preparePortBindings(config);
prepareConsole(config);

@ -267,13 +267,26 @@
<div class="form-group">
<label for="container_network" class="col-sm-1 control-label text-left">Network</label>
<div class="col-sm-9">
<select class="selectpicker form-control" ng-model="config.HostConfig.NetworkMode">
<select class="selectpicker form-control" ng-model="config.HostConfig.NetworkMode" id="container_network">
<option selected disabled hidden value="">Select a network</option>
<option ng-repeat="net in availableNetworks" ng-value="net.Name">{{ net.Name }}</option>
</select>
</div>
</div>
<!-- !network-input -->
<!-- container-name-input -->
<div class="form-group" ng-if="config.HostConfig.NetworkMode == 'container'">
<label for="container_network_container" class="col-sm-1 control-label text-left">Container</label>
<div class="col-sm-9">
<select ng-if="(!swarm || swarm && swarm_mode)" ng-options="container|containername for container in runningContainers" class="selectpicker form-control" ng-model="formValues.NetworkContainer">
<option selected disabled hidden value="">Select a container</option>
</select>
<select ng-if="swarm && !swarm_mode" ng-options="container|swarmcontainername for container in runningContainers" class="selectpicker form-control" ng-model="formValues.NetworkContainer">
<option selected disabled hidden value="">Select a container</option>
</select>
</div>
</div>
<!-- !container-name-input -->
<!-- hostname-input -->
<div class="form-group">
<label for="container_hostname" class="col-sm-1 control-label text-left">Hostname</label>

Loading…
Cancel
Save