2016-06-02 05:34:03 +00:00
|
|
|
angular.module('container', [])
|
2017-04-25 08:20:57 +00:00
|
|
|
.controller('ContainerController', ['$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ImageHelper', 'Network', 'Notifications', 'Pagination', 'ModalService',
|
|
|
|
function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, ImageHelper, Network, Notifications, Pagination, ModalService) {
|
2016-08-19 06:41:45 +00:00
|
|
|
$scope.activityTime = 0;
|
|
|
|
$scope.portBindings = [];
|
|
|
|
$scope.config = {
|
|
|
|
Image: '',
|
|
|
|
Registry: ''
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.pagination_count = Pagination.getPaginationCount('container_networks');
|
|
|
|
|
|
|
|
$scope.changePaginationCount = function() {
|
|
|
|
Pagination.setPaginationCount('container_networks', $scope.state.pagination_count);
|
|
|
|
};
|
2016-06-02 05:34:03 +00:00
|
|
|
|
|
|
|
var update = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.get({id: $stateParams.id}, function (d) {
|
|
|
|
$scope.container = d;
|
|
|
|
$scope.container.edit = false;
|
|
|
|
$scope.container.newContainerName = $filter('trimcontainername')(d.Name);
|
|
|
|
|
2016-08-19 06:41:45 +00:00
|
|
|
if (d.State.Running) {
|
|
|
|
$scope.activityTime = moment.duration(moment(d.State.StartedAt).utc().diff(moment().utc())).humanize();
|
2017-04-27 18:40:37 +00:00
|
|
|
} else if (d.State.Status === "created") {
|
|
|
|
$scope.activityTime = moment.duration(moment(d.Created).utc().diff(moment().utc())).humanize();
|
2016-08-19 06:41:45 +00:00
|
|
|
} else {
|
|
|
|
$scope.activityTime = moment.duration(moment().utc().diff(moment(d.State.FinishedAt).utc())).humanize();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 06:41:45 +00:00
|
|
|
$scope.portBindings = [];
|
|
|
|
if (d.NetworkSettings.Ports) {
|
|
|
|
angular.forEach(Object.keys(d.NetworkSettings.Ports), function(portMapping) {
|
|
|
|
if (d.NetworkSettings.Ports[portMapping]) {
|
|
|
|
var mapping = {};
|
|
|
|
mapping.container = portMapping;
|
|
|
|
mapping.host = d.NetworkSettings.Ports[portMapping][0].HostIp + ':' + d.NetworkSettings.Ports[portMapping][0].HostPort;
|
|
|
|
$scope.portBindings.push(mapping);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to retrieve container info");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.start = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-09-02 01:51:49 +00:00
|
|
|
Container.start({id: $scope.container.Id}, {}, function (d) {
|
2016-06-02 05:34:03 +00:00
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container started", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to start container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.stop = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.stop({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container stopped", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to stop container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.kill = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.kill({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container killed", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to kill container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.commit = function () {
|
2016-08-19 06:41:45 +00:00
|
|
|
$('#createImageSpinner').show();
|
2016-12-31 00:25:42 +00:00
|
|
|
var image = $scope.config.Image;
|
|
|
|
var registry = $scope.config.Registry;
|
2016-12-13 20:33:24 +00:00
|
|
|
var imageConfig = ImageHelper.createImageConfigForCommit(image, registry);
|
2016-08-19 06:41:45 +00:00
|
|
|
ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) {
|
|
|
|
$('#createImageSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container commited", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-08-19 06:41:45 +00:00
|
|
|
$('#createImageSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to commit container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
2016-08-19 06:41:45 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.pause = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.pause({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container paused", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to pause container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.unpause = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.unpause({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container unpaused", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to unpause container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-04-25 08:20:57 +00:00
|
|
|
$scope.confirmRemove = function () {
|
|
|
|
if ($scope.container.State.Running) {
|
|
|
|
ModalService.confirmDeletion(
|
|
|
|
'You are about to remove a running container.',
|
|
|
|
function (confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
$scope.remove();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$scope.remove();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.remove = function() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2017-04-25 08:20:57 +00:00
|
|
|
Container.remove({id: $stateParams.id, force: true}, function (d) {
|
2016-09-01 03:07:31 +00:00
|
|
|
if (d.message) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", d, "Unable to remove container");
|
2016-09-01 03:07:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$state.go('containers', {}, {reload: true});
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container removed", $stateParams.id);
|
2016-09-01 03:07:31 +00:00
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to remove container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.restart = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.restart({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container restarted", $stateParams.id);
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
update();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to restart container");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.renameContainer = function () {
|
2016-08-19 06:41:45 +00:00
|
|
|
Container.rename({id: $stateParams.id, 'name': $scope.container.newContainerName}, function (d) {
|
2016-09-02 03:25:20 +00:00
|
|
|
if (d.message) {
|
|
|
|
$scope.container.newContainerName = $scope.container.Name;
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Unable to rename container", {}, d.message);
|
2016-09-02 03:25:20 +00:00
|
|
|
} else {
|
|
|
|
$scope.container.Name = $scope.container.newContainerName;
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container successfully renamed", d.name);
|
2016-09-02 03:25:20 +00:00
|
|
|
}
|
|
|
|
}, function (e) {
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, 'Unable to rename container');
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
$scope.container.edit = false;
|
|
|
|
};
|
|
|
|
|
2016-11-07 04:36:00 +00:00
|
|
|
$scope.containerLeaveNetwork = function containerLeaveNetwork(container, networkId) {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
Network.disconnect({id: networkId}, { Container: $stateParams.id, Force: false }, function (d) {
|
|
|
|
if (d.message) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Error", d, "Unable to disconnect container from network");
|
2016-11-07 04:36:00 +00:00
|
|
|
} else {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Container left network", $stateParams.id);
|
2016-11-10 02:25:31 +00:00
|
|
|
$state.go('container', {id: $stateParams.id}, {reload: true});
|
2016-11-07 04:36:00 +00:00
|
|
|
}
|
|
|
|
}, function (e) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.error("Failure", e, "Unable to disconnect container from network");
|
2016-11-07 04:36:00 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
update();
|
|
|
|
}]);
|