|
|
|
@ -16,25 +16,25 @@ import { formatLogs } from '../helpers/logHelper';
|
|
|
|
|
angular.module('portainer.docker').factory('ContainerService', ContainerServiceFactory);
|
|
|
|
|
|
|
|
|
|
/* @ngInject */
|
|
|
|
|
function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
function ContainerServiceFactory($q, Container, $timeout) {
|
|
|
|
|
const service = {
|
|
|
|
|
killContainer: withEndpointId(killContainer),
|
|
|
|
|
pauseContainer: withEndpointId(pauseContainer),
|
|
|
|
|
renameContainer: withEndpointId(renameContainer),
|
|
|
|
|
restartContainer: withEndpointId(restartContainer),
|
|
|
|
|
resumeContainer: withEndpointId(resumeContainer),
|
|
|
|
|
startContainer: withEndpointId(startContainer),
|
|
|
|
|
stopContainer: withEndpointId(stopContainer),
|
|
|
|
|
recreateContainer: withEndpointId(recreateContainer),
|
|
|
|
|
remove: withEndpointId(removeContainer),
|
|
|
|
|
killContainer,
|
|
|
|
|
pauseContainer,
|
|
|
|
|
renameContainer,
|
|
|
|
|
restartContainer,
|
|
|
|
|
resumeContainer,
|
|
|
|
|
startContainer,
|
|
|
|
|
stopContainer,
|
|
|
|
|
recreateContainer,
|
|
|
|
|
remove: removeContainer,
|
|
|
|
|
updateRestartPolicy,
|
|
|
|
|
updateLimits,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.container = function (id) {
|
|
|
|
|
service.container = function (environmentId, id) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
Container.get({ id: id })
|
|
|
|
|
Container.get({ environmentId, id })
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
var container = new ContainerDetailsViewModel(data);
|
|
|
|
|
deferred.resolve(container);
|
|
|
|
@ -46,9 +46,9 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.containers = function (all, filters) {
|
|
|
|
|
service.containers = function (environmentId, all, filters) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
Container.query({ all: all, filters: filters })
|
|
|
|
|
Container.query({ environmentId, all, filters })
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
var containers = data.map(function (item) {
|
|
|
|
|
return new ContainerViewModel(item);
|
|
|
|
@ -62,11 +62,11 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.resizeTTY = function (id, width, height, timeout) {
|
|
|
|
|
service.resizeTTY = function (environmentId, id, width, height, timeout) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
$timeout(function () {
|
|
|
|
|
Container.resize({}, { id: id, height: height, width: width })
|
|
|
|
|
Container.resize({}, { environmentId, id, width, height })
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
if (data.message) {
|
|
|
|
|
deferred.reject({ msg: 'Unable to resize tty of container ' + id, err: data.message });
|
|
|
|
@ -82,13 +82,13 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function updateRestartPolicy(id, restartPolicy, maximumRetryCounts) {
|
|
|
|
|
return Container.update({ id: id }, { RestartPolicy: { Name: restartPolicy, MaximumRetryCount: maximumRetryCounts } }).$promise;
|
|
|
|
|
function updateRestartPolicy(environmentId, id, restartPolicy, maximumRetryCounts) {
|
|
|
|
|
return Container.update({ environmentId, id }, { RestartPolicy: { Name: restartPolicy, MaximumRetryCount: maximumRetryCounts } }).$promise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateLimits(id, config) {
|
|
|
|
|
function updateLimits(environmentId, id, config) {
|
|
|
|
|
return Container.update(
|
|
|
|
|
{ id: id },
|
|
|
|
|
{ environmentId, id },
|
|
|
|
|
{
|
|
|
|
|
// MemorySwap: must be set
|
|
|
|
|
// -1: non limits, 0: treated as unset(cause update error).
|
|
|
|
@ -100,9 +100,9 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
).$promise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
service.createContainer = function (configuration) {
|
|
|
|
|
service.createContainer = function (environmentId, configuration) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
Container.create(configuration)
|
|
|
|
|
Container.create({ environmentId }, configuration)
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
deferred.resolve(data);
|
|
|
|
|
})
|
|
|
|
@ -112,14 +112,14 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.createAndStartContainer = function (configuration) {
|
|
|
|
|
service.createAndStartContainer = function (environmentId, configuration) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
var container;
|
|
|
|
|
service
|
|
|
|
|
.createContainer(configuration)
|
|
|
|
|
.createContainer(environmentId, configuration)
|
|
|
|
|
.then(function success(data) {
|
|
|
|
|
container = data;
|
|
|
|
|
return service.startContainer(container.Id);
|
|
|
|
|
return service.startContainer(environmentId, container.Id);
|
|
|
|
|
})
|
|
|
|
|
.then(function success() {
|
|
|
|
|
deferred.resolve(container);
|
|
|
|
@ -130,10 +130,10 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.createExec = function (execConfig) {
|
|
|
|
|
service.createExec = function (environmentId, execConfig) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
Container.exec({}, execConfig)
|
|
|
|
|
Container.exec({ environmentId }, execConfig)
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
if (data.message) {
|
|
|
|
|
deferred.reject({ msg: data.message, err: data.message });
|
|
|
|
@ -148,7 +148,7 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.logs = function (id, stdout, stderr, timestamps, since, tail, stripHeaders) {
|
|
|
|
|
service.logs = function (environmentId, id, stdout, stderr, timestamps, since, tail, stripHeaders) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
var parameters = {
|
|
|
|
@ -160,7 +160,7 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
tail: tail || 'all',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Container.logs(parameters)
|
|
|
|
|
Container.logs(environmentId, parameters)
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
var logs = formatLogs(data.logs, { stripHeaders, withTimestamps: !!timestamps });
|
|
|
|
|
deferred.resolve(logs);
|
|
|
|
@ -172,10 +172,10 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.containerStats = function (id) {
|
|
|
|
|
service.containerStats = function (environmentId, id) {
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
Container.stats({ id: id })
|
|
|
|
|
Container.stats({ environmentId, id })
|
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
|
var containerStats = new ContainerStatsViewModel(data);
|
|
|
|
|
deferred.resolve(containerStats);
|
|
|
|
@ -187,25 +187,17 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) {
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.containerTop = function (id) {
|
|
|
|
|
return Container.top({ id: id }).$promise;
|
|
|
|
|
service.containerTop = function (environmentId, id) {
|
|
|
|
|
return Container.top({ environmentId, id }).$promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.inspect = function (id) {
|
|
|
|
|
return Container.inspect({ id: id }).$promise;
|
|
|
|
|
service.inspect = function (environmentId, id) {
|
|
|
|
|
return Container.inspect({ environmentId, id }).$promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
service.prune = function (filters) {
|
|
|
|
|
return Container.prune({ filters: filters }).$promise;
|
|
|
|
|
service.prune = function (environmentId, filters) {
|
|
|
|
|
return Container.prune({ environmentId, filters }).$promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return service;
|
|
|
|
|
|
|
|
|
|
function withEndpointId(func) {
|
|
|
|
|
return function (...args) {
|
|
|
|
|
const endpointId = EndpointProvider.endpointID();
|
|
|
|
|
|
|
|
|
|
return func(endpointId, ...args);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|