|
|
@ -1,6 +1,6 @@
|
|
|
|
angular.module('startContainer', ['ui.bootstrap'])
|
|
|
|
angular.module('startContainer', ['ui.bootstrap'])
|
|
|
|
.controller('StartContainerController', ['$scope', '$state', 'Container', 'Messages', 'containernameFilter', 'errorMsgFilter', 'ViewSpinner',
|
|
|
|
.controller('StartContainerController', ['$scope', '$state', 'Container', 'Image', 'Messages', 'containernameFilter', 'errorMsgFilter', 'ViewSpinner',
|
|
|
|
function ($scope, $state, Container, Messages, containernameFilter, errorMsgFilter, ViewSpinner) {
|
|
|
|
function ($scope, $state, Container, Image, Messages, containernameFilter, errorMsgFilter, ViewSpinner) {
|
|
|
|
$scope.template = 'app/components/startContainer/startcontainer.html';
|
|
|
|
$scope.template = 'app/components/startContainer/startcontainer.html';
|
|
|
|
|
|
|
|
|
|
|
|
Container.query({all: 1}, function (d) {
|
|
|
|
Container.query({all: 1}, function (d) {
|
|
|
@ -52,8 +52,38 @@ function ($scope, $state, Container, Messages, containernameFilter, errorMsgFilt
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createContainer(config) {
|
|
|
|
|
|
|
|
Container.create(config, function (d) {
|
|
|
|
|
|
|
|
if (d.Id) {
|
|
|
|
|
|
|
|
var reqBody = config.HostConfig || {};
|
|
|
|
|
|
|
|
reqBody.id = d.Id;
|
|
|
|
|
|
|
|
Container.start(reqBody, function (cd) {
|
|
|
|
|
|
|
|
if (cd.id) {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
|
|
|
|
Messages.send('Container Started', d.Id);
|
|
|
|
|
|
|
|
$state.go('container', {id: d.Id}, {reload: true});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
|
|
|
|
failedRequestHandler(cd, Messages);
|
|
|
|
|
|
|
|
Container.remove({id: d.Id}, function () {
|
|
|
|
|
|
|
|
Messages.send('Container Removed', d.Id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function (e) {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
|
|
|
|
failedRequestHandler(e, Messages);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
|
|
|
|
failedRequestHandler(d, Messages);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function (e) {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
|
|
|
|
failedRequestHandler(e, Messages);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$scope.create = function () {
|
|
|
|
$scope.create = function () {
|
|
|
|
// Copy the config before transforming fields to the remote API format
|
|
|
|
|
|
|
|
$('#create-modal').modal('hide');
|
|
|
|
$('#create-modal').modal('hide');
|
|
|
|
ViewSpinner.spin();
|
|
|
|
ViewSpinner.spin();
|
|
|
|
|
|
|
|
|
|
|
@ -121,35 +151,26 @@ function ($scope, $state, Container, Messages, containernameFilter, errorMsgFilt
|
|
|
|
rmEmptyKeys(config.HostConfig);
|
|
|
|
rmEmptyKeys(config.HostConfig);
|
|
|
|
rmEmptyKeys(config);
|
|
|
|
rmEmptyKeys(config);
|
|
|
|
|
|
|
|
|
|
|
|
var ctor = Container;
|
|
|
|
var image = _.toLower(config.Image);
|
|
|
|
var s = $scope;
|
|
|
|
var imageNameAndTag = image.split(':');
|
|
|
|
Container.create(config, function (d) {
|
|
|
|
var imageConfig = {
|
|
|
|
if (d.Id) {
|
|
|
|
fromImage: imageNameAndTag[0],
|
|
|
|
var reqBody = config.HostConfig || {};
|
|
|
|
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest',
|
|
|
|
reqBody.id = d.Id;
|
|
|
|
};
|
|
|
|
ctor.start(reqBody, function (cd) {
|
|
|
|
|
|
|
|
if (cd.id) {
|
|
|
|
Image.create(imageConfig, function (data) {
|
|
|
|
ViewSpinner.stop();
|
|
|
|
var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error');
|
|
|
|
Messages.send('Container Started', d.Id);
|
|
|
|
if (err) {
|
|
|
|
$state.go('container', {id: d.Id}, {reload: true});
|
|
|
|
var detail = data[data.length - 1];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
|
|
|
|
failedRequestHandler(cd, Messages);
|
|
|
|
|
|
|
|
ctor.remove({id: d.Id}, function () {
|
|
|
|
|
|
|
|
Messages.send('Container Removed', d.Id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function (e) {
|
|
|
|
|
|
|
|
ViewSpinner.stop();
|
|
|
|
ViewSpinner.stop();
|
|
|
|
failedRequestHandler(e, Messages);
|
|
|
|
Messages.error('Error', detail.error);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Messages.send("Image successfully pulled", image);
|
|
|
|
ViewSpinner.stop();
|
|
|
|
createContainer(config);
|
|
|
|
failedRequestHandler(d, Messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function (e) {
|
|
|
|
}, function (e) {
|
|
|
|
ViewSpinner.stop();
|
|
|
|
ViewSpinner.stop();
|
|
|
|
failedRequestHandler(e, Messages);
|
|
|
|
Messages.error('Error', 'Unable to pull image ' + image);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|