2014-11-12 18:31:02 +00:00
|
|
|
angular.module('startContainer', [])
|
|
|
|
.controller('StartContainerController', ['$scope', '$routeParams', '$location', 'Container', 'Messages',
|
|
|
|
function($scope, $routeParams, $location, Container, Messages) {
|
|
|
|
$scope.template = 'app/components/startContainer/startcontainer.html';
|
|
|
|
$scope.config = {
|
|
|
|
name: '',
|
|
|
|
memory: 0,
|
|
|
|
memorySwap: 0,
|
|
|
|
cpuShares: 1024,
|
|
|
|
env: '',
|
|
|
|
commands: '',
|
2015-01-19 05:20:49 +00:00
|
|
|
volumesFrom: '',
|
|
|
|
portBindings: []
|
2014-11-12 18:31:02 +00:00
|
|
|
};
|
|
|
|
$scope.commandPlaceholder = '["/bin/echo", "Hello world"]';
|
|
|
|
|
2014-11-29 06:06:06 +00:00
|
|
|
function failedRequestHandler(e, Messages) {
|
|
|
|
Messages.send({class: 'text-error', data: e.data});
|
|
|
|
}
|
|
|
|
|
2014-11-12 18:31:02 +00:00
|
|
|
$scope.create = function() {
|
|
|
|
var cmds = null;
|
|
|
|
if ($scope.config.commands !== '') {
|
|
|
|
cmds = angular.fromJson($scope.config.commands);
|
|
|
|
}
|
|
|
|
var id = $routeParams.id;
|
|
|
|
var ctor = Container;
|
|
|
|
var loc = $location;
|
|
|
|
var s = $scope;
|
|
|
|
|
2015-01-19 05:20:49 +00:00
|
|
|
var exposedPorts = {};
|
|
|
|
var portBindings = {};
|
|
|
|
// TODO: consider using compatibility library
|
|
|
|
$scope.config.portBindings.forEach(function(portBinding) {
|
|
|
|
var intPort = portBinding.intPort + "/tcp";
|
|
|
|
var binding = {
|
|
|
|
HostIp: portBinding.ip,
|
|
|
|
HostPort: portBinding.extPort
|
|
|
|
};
|
|
|
|
if (portBinding.intPort) {
|
|
|
|
exposedPorts[intPort] = {};
|
|
|
|
if (intPort in portBindings) {
|
|
|
|
portBindings[intPort].push(binding);
|
|
|
|
} else {
|
|
|
|
portBindings[intPort] = [binding];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO: Send warning message? Internal port need to be specified.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-12 18:31:02 +00:00
|
|
|
Container.create({
|
|
|
|
Image: id,
|
|
|
|
name: $scope.config.name,
|
|
|
|
Memory: $scope.config.memory,
|
|
|
|
MemorySwap: $scope.config.memorySwap,
|
|
|
|
CpuShares: $scope.config.cpuShares,
|
|
|
|
Cmd: cmds,
|
2015-01-19 05:20:49 +00:00
|
|
|
VolumesFrom: $scope.config.volumesFrom,
|
|
|
|
ExposedPorts: exposedPorts,
|
|
|
|
HostConfig: {
|
|
|
|
PortBindings: portBindings
|
|
|
|
}
|
2014-11-12 18:31:02 +00:00
|
|
|
}, function(d) {
|
|
|
|
if (d.Id) {
|
2015-01-19 05:20:49 +00:00
|
|
|
ctor.start({
|
|
|
|
id: d.Id,
|
|
|
|
HostConfig: {
|
|
|
|
PortBindings: portBindings
|
|
|
|
}
|
|
|
|
}, function(cd) {
|
2014-11-12 18:31:02 +00:00
|
|
|
$('#create-modal').modal('hide');
|
|
|
|
loc.path('/containers/' + d.Id + '/');
|
|
|
|
}, function(e) {
|
|
|
|
failedRequestHandler(e, Messages);
|
|
|
|
});
|
2014-11-29 06:06:06 +00:00
|
|
|
} else {
|
|
|
|
failedRequestHandler(d, Messages);
|
2014-11-12 18:31:02 +00:00
|
|
|
}
|
|
|
|
}, function(e) {
|
|
|
|
failedRequestHandler(e, Messages);
|
|
|
|
});
|
|
|
|
};
|
2015-01-19 05:20:49 +00:00
|
|
|
|
|
|
|
$scope.addPortBinding = function() {
|
|
|
|
$scope.config.portBindings.push({ip: '', extPort: '', intPort: ''});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removePortBinding = function(portBinding) {
|
|
|
|
var idx = $scope.config.portBindings.indexOf(portBinding);
|
|
|
|
$scope.config.portBindings.splice(idx, 1);
|
|
|
|
};
|
2014-11-12 18:31:02 +00:00
|
|
|
}]);
|