2021-12-14 07:34:54 +00:00
|
|
|
angular.module('portainer.docker').controller('ContainersController', ContainersController);
|
2022-07-17 23:02:14 +00:00
|
|
|
import _ from 'lodash';
|
2018-10-28 09:27:06 +00:00
|
|
|
|
2021-12-14 07:34:54 +00:00
|
|
|
/* @ngInject */
|
|
|
|
function ContainersController($scope, ContainerService, Notifications, endpoint) {
|
|
|
|
$scope.offlineMode = endpoint.Status !== 1;
|
|
|
|
$scope.endpoint = endpoint;
|
2017-12-06 11:04:02 +00:00
|
|
|
|
2021-12-14 07:34:54 +00:00
|
|
|
$scope.getContainers = getContainers;
|
2019-07-22 10:54:59 +00:00
|
|
|
|
2021-12-14 07:34:54 +00:00
|
|
|
function getContainers() {
|
2022-07-17 23:02:14 +00:00
|
|
|
$scope.containers = null;
|
|
|
|
$scope.containers_t = null;
|
2021-12-14 07:34:54 +00:00
|
|
|
ContainerService.containers(1)
|
|
|
|
.then(function success(data) {
|
2022-07-17 23:02:14 +00:00
|
|
|
$scope.containers_t = data;
|
|
|
|
if ($scope.containers_t.length === 0) {
|
|
|
|
$scope.containers = $scope.containers_t;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let item of $scope.containers_t) {
|
|
|
|
ContainerService.container(item.Id).then(function success(data) {
|
|
|
|
var Id = data.Id;
|
|
|
|
for (var i = 0; i < $scope.containers_t.length; i++) {
|
|
|
|
if (Id == $scope.containers_t[i].Id) {
|
|
|
|
const gpuOptions = _.find(data.HostConfig.DeviceRequests, function (o) {
|
|
|
|
return o.Driver === 'nvidia' || o.Capabilities[0][0] === 'gpu';
|
|
|
|
});
|
|
|
|
if (!gpuOptions) {
|
|
|
|
$scope.containers_t[i]['Gpus'] = 'none';
|
|
|
|
} else {
|
|
|
|
let gpuStr = 'all';
|
|
|
|
if (gpuOptions.Count !== -1) {
|
|
|
|
gpuStr = `id:${_.join(gpuOptions.DeviceIDs, ',')}`;
|
|
|
|
}
|
|
|
|
$scope.containers_t[i]['Gpus'] = `${gpuStr}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let item of $scope.containers_t) {
|
|
|
|
if (!Object.keys(item).includes('Gpus')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$scope.containers = $scope.containers_t;
|
|
|
|
});
|
|
|
|
}
|
2021-12-14 07:34:54 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve containers');
|
|
|
|
$scope.containers = [];
|
|
|
|
});
|
|
|
|
}
|
2017-06-01 08:14:55 +00:00
|
|
|
|
2021-12-14 07:34:54 +00:00
|
|
|
function initView() {
|
|
|
|
getContainers();
|
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
|
|
|
}
|