2018-10-07 22:44:08 +00:00
|
|
|
angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
2020-04-10 21:54:53 +00:00
|
|
|
'$q',
|
|
|
|
'$stateParams',
|
|
|
|
'NodeService',
|
|
|
|
'StateManager',
|
|
|
|
'AgentService',
|
|
|
|
'ContainerService',
|
|
|
|
'Authentication',
|
2018-10-28 06:06:50 +00:00
|
|
|
function NodeDetailsViewController($q, $stateParams, NodeService, StateManager, AgentService, ContainerService, Authentication) {
|
2018-10-07 22:44:08 +00:00
|
|
|
var ctrl = this;
|
|
|
|
|
|
|
|
ctrl.$onInit = initView;
|
|
|
|
|
|
|
|
ctrl.state = {
|
2018-10-28 06:06:50 +00:00
|
|
|
isAgent: false,
|
2020-04-10 21:54:53 +00:00
|
|
|
isAdmin: false,
|
2018-10-07 22:44:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function initView() {
|
|
|
|
var applicationState = StateManager.getState();
|
|
|
|
ctrl.state.isAgent = applicationState.endpoint.mode.agentProxy;
|
2019-05-24 06:04:58 +00:00
|
|
|
ctrl.state.isAdmin = Authentication.isAdmin();
|
2021-02-09 08:09:06 +00:00
|
|
|
ctrl.state.enableHostManagementFeatures = ctrl.endpoint.SecuritySettings.enableHostManagementFeatures;
|
2018-10-28 06:06:50 +00:00
|
|
|
|
|
|
|
var fetchJobs = ctrl.state.isAdmin && ctrl.state.isAgent;
|
2018-10-07 22:44:08 +00:00
|
|
|
|
|
|
|
var nodeId = $stateParams.id;
|
2018-10-28 06:06:50 +00:00
|
|
|
$q.all({
|
|
|
|
node: NodeService.node(nodeId),
|
2020-04-10 21:54:53 +00:00
|
|
|
jobs: fetchJobs ? ContainerService.containers(true, { label: ['io.portainer.job.endpoint'] }) : [],
|
|
|
|
}).then(function (data) {
|
2018-10-28 06:06:50 +00:00
|
|
|
var node = data.node;
|
2018-10-07 22:44:08 +00:00
|
|
|
ctrl.originalNode = node;
|
|
|
|
ctrl.hostDetails = buildHostDetails(node);
|
|
|
|
ctrl.engineDetails = buildEngineDetails(node);
|
|
|
|
ctrl.nodeDetails = buildNodeDetails(node);
|
2018-10-28 06:06:50 +00:00
|
|
|
ctrl.jobs = data.jobs;
|
2018-10-07 22:44:08 +00:00
|
|
|
if (ctrl.state.isAgent) {
|
2018-10-26 03:16:29 +00:00
|
|
|
var agentApiVersion = applicationState.endpoint.agentApiVersion;
|
|
|
|
ctrl.state.agentApiVersion = agentApiVersion;
|
2022-07-04 05:13:15 +00:00
|
|
|
if (agentApiVersion < 2 || !ctrl.state.enableHostManagementFeatures) {
|
2018-10-26 03:16:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-28 06:06:50 +00:00
|
|
|
|
2022-11-02 11:29:26 +00:00
|
|
|
AgentService.hostInfo(ctrl.endpoint.Id, node.Hostname).then(function onHostInfoLoad(agentHostInfo) {
|
2018-10-28 06:06:50 +00:00
|
|
|
ctrl.devices = agentHostInfo.PCIDevices;
|
|
|
|
ctrl.disks = agentHostInfo.PhysicalDisks;
|
|
|
|
});
|
2018-10-07 22:44:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildHostDetails(node) {
|
|
|
|
return {
|
|
|
|
os: {
|
|
|
|
arch: node.PlatformArchitecture,
|
2020-04-10 21:54:53 +00:00
|
|
|
type: node.PlatformOS,
|
2018-10-07 22:44:08 +00:00
|
|
|
},
|
|
|
|
name: node.Hostname,
|
|
|
|
totalCPU: node.CPUs / 1e9,
|
2020-04-10 21:54:53 +00:00
|
|
|
totalMemory: node.Memory,
|
2018-10-07 22:44:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildEngineDetails(node) {
|
|
|
|
return {
|
|
|
|
releaseVersion: node.EngineVersion,
|
|
|
|
volumePlugins: transformPlugins(node.Plugins, 'Volume'),
|
2019-06-24 23:22:45 +00:00
|
|
|
networkPlugins: transformPlugins(node.Plugins, 'Network'),
|
|
|
|
engineLabels: node.EngineLabels,
|
2018-10-07 22:44:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildNodeDetails(node) {
|
|
|
|
return {
|
|
|
|
name: node.Name,
|
|
|
|
role: node.Role,
|
|
|
|
managerAddress: node.ManagerAddr,
|
|
|
|
availability: node.Availability,
|
|
|
|
status: node.Status,
|
2020-04-10 21:54:53 +00:00
|
|
|
nodeLabels: node.Labels,
|
2018-10-07 22:44:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function transformPlugins(pluginsList, type) {
|
|
|
|
return pluginsList
|
2020-04-10 21:54:53 +00:00
|
|
|
.filter(function (plugin) {
|
|
|
|
return plugin.Type === type;
|
|
|
|
})
|
|
|
|
.map(function (plugin) {
|
|
|
|
return plugin.Name;
|
|
|
|
});
|
2018-10-07 22:44:08 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
},
|
2018-10-07 22:44:08 +00:00
|
|
|
]);
|