2018-10-07 22:44:08 +00:00
|
|
|
angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
2018-10-28 06:06:50 +00:00
|
|
|
'$q', '$stateParams', 'NodeService', 'StateManager', 'AgentService', 'ContainerService', 'Authentication',
|
|
|
|
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,
|
|
|
|
isAdmin: false
|
2018-10-07 22:44:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function initView() {
|
|
|
|
var applicationState = StateManager.getState();
|
|
|
|
ctrl.state.isAgent = applicationState.endpoint.mode.agentProxy;
|
2018-10-28 06:06:50 +00:00
|
|
|
ctrl.state.isAdmin = Authentication.getUserDetails().role === 1;
|
2018-12-05 22:36:25 +00:00
|
|
|
ctrl.state.enableHostManagementFeatures = applicationState.application.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),
|
|
|
|
jobs: fetchJobs ? ContainerService.containers(true, { label: ['io.portainer.job.endpoint'] }) : []
|
|
|
|
})
|
|
|
|
.then(function (data) {
|
|
|
|
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;
|
|
|
|
if (agentApiVersion < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-28 06:06:50 +00:00
|
|
|
|
2018-10-26 03:16:29 +00:00
|
|
|
AgentService.hostInfo(node.Hostname)
|
2018-10-28 06:06:50 +00:00
|
|
|
.then(function onHostInfoLoad(agentHostInfo) {
|
|
|
|
ctrl.devices = agentHostInfo.PCIDevices;
|
|
|
|
ctrl.disks = agentHostInfo.PhysicalDisks;
|
|
|
|
});
|
2018-10-07 22:44:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildHostDetails(node) {
|
|
|
|
return {
|
|
|
|
os: {
|
|
|
|
arch: node.PlatformArchitecture,
|
|
|
|
type: node.PlatformOS
|
|
|
|
},
|
|
|
|
name: node.Hostname,
|
|
|
|
totalCPU: node.CPUs / 1e9,
|
|
|
|
totalMemory: node.Memory
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildEngineDetails(node) {
|
|
|
|
return {
|
|
|
|
releaseVersion: node.EngineVersion,
|
|
|
|
volumePlugins: transformPlugins(node.Plugins, 'Volume'),
|
|
|
|
networkPlugins: transformPlugins(node.Plugins, 'Network')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildNodeDetails(node) {
|
|
|
|
return {
|
|
|
|
name: node.Name,
|
|
|
|
role: node.Role,
|
|
|
|
managerAddress: node.ManagerAddr,
|
|
|
|
availability: node.Availability,
|
|
|
|
status: node.Status,
|
|
|
|
engineLabels: node.EngineLabels,
|
|
|
|
nodeLabels: node.Labels
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function transformPlugins(pluginsList, type) {
|
|
|
|
return pluginsList
|
2018-10-28 06:06:50 +00:00
|
|
|
.filter(function(plugin) {
|
|
|
|
return plugin.Type === type;
|
|
|
|
})
|
|
|
|
.map(function(plugin) {
|
|
|
|
return plugin.Name;
|
|
|
|
});
|
2018-10-07 22:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|