Added task limiter to AMT manager

Ylian Saint-Hilaire committed Oct 20, 2020 at 11:28 UTC 09a0409fc3760a816324500341636a6294758569
3 files changed +42 -7
agents/meshcmd.js
+12 -3
@@ -2945,6 +2945,7 @@ function performAmtPowerActionEx2(stack, name, response, status) {
2945 }
2946 }
2947
2948 +
2949 //
2950 // Get MEI state
2951 //
@@ -2964,11 +2965,19 @@ function getMeiState(flags, func) {
2965 amtMei.getEHBCState(function (result) { if ((result != null) && (result.EHBC == true)) { amtMeiTmpState.Flags += 1; } });
2966 amtMei.getControlMode(function (result) { if (result != null) { if (result.controlMode == 1) { amtMeiTmpState.Flags += 2; } if (result.controlMode == 2) { amtMeiTmpState.Flags += 4; } } }); // Flag 2 = CCM, 4 = ACM
2967 //amtMei.getMACAddresses(function (result) { if (result) { amtMeiTmpState.mac = result; } });
2967 - if ((flags & 8) != 0) { amtMei.getLanInterfaceSettings(0, function (result) { if (result) { amtMeiTmpState.net0 = result; } }); }
2968 - if ((flags & 8) != 0) { amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } }); }
2968 + if ((flags & 8) != 0) {
2969 + amtMei.getLanInterfaceSettings(0, function (result) {
2970 + if (result) {
2971 + amtMeiTmpState.net0 = result;
2972 + var fqdn = null, interfaces = require('os').networkInterfaces(); // Look for the DNS suffix for the Intel AMT Ethernet interface
2973 + for (var i in interfaces) { for (var j in interfaces[i]) { if ((interfaces[i][j].mac == amtMeiTmpState.net0.mac) && (interfaces[i][j].fqdn != null) && (interfaces[i][j].fqdn != '')) { amtMeiTmpState.OsDnsSuffix = interfaces[i][j].fqdn; } } }
2974 + }
2975 + });
2976 + amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } });
2977 + }
2978 amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { amtMeiTmpState.UUID = result.uuid; } });
2979 if ((flags & 2) != 0) { amtMei.getLocalSystemAccount(function (x) { if ((x != null) && x.user && x.pass) { amtMeiTmpState.OsAdmin = { user: x.user, pass: x.pass }; } }); }
2971 - amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.DNS = result; } if ((flags & 4) == 0) { if (func != null) { func(amtMeiTmpState); } } });
2980 + amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.DnsSuffix = result; } if ((flags & 4) == 0) { if (func != null) { func(amtMeiTmpState); } } });
2981 if ((flags & 4) != 0) {
2982 amtMei.getHashHandles(function (handles) {
2983 if (handles != null) { amtMeiTmpState.Hashes = []; } else { func(amtMeiTmpState); }
agents/meshcore.js
+11 -3
@@ -3848,11 +3848,19 @@ function createMeshCore(agent) {
3848 amtMei.getEHBCState(function (result) { if ((result != null) && (result.EHBC == true)) { amtMeiTmpState.Flags += 1; } });
3849 amtMei.getControlMode(function (result) { if (result != null) { if (result.controlMode == 1) { amtMeiTmpState.Flags += 2; } if (result.controlMode == 2) { amtMeiTmpState.Flags += 4; } } }); // Flag 2 = CCM, 4 = ACM
3850 //amtMei.getMACAddresses(function (result) { if (result) { amtMeiTmpState.mac = result; } });
3851 - if ((flags & 8) != 0) { amtMei.getLanInterfaceSettings(0, function (result) { if (result) { amtMeiTmpState.net0 = result; } }); }
3852 - if ((flags & 8) != 0) { amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } }); }
3851 + if ((flags & 8) != 0) {
3852 + amtMei.getLanInterfaceSettings(0, function (result) {
3853 + if (result) {
3854 + amtMeiTmpState.net0 = result;
3855 + var fqdn = null, interfaces = require('os').networkInterfaces(); // Look for the DNS suffix for the Intel AMT Ethernet interface
3856 + for (var i in interfaces) { for (var j in interfaces[i]) { if ((interfaces[i][j].mac == mestate.net0.mac) && (interfaces[i][j].fqdn != null) && (interfaces[i][j].fqdn != '')) { amtMeiTmpState.OsDnsSuffix = interfaces[i][j].fqdn; } } }
3857 + }
3858 + });
3859 + amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } });
3860 + }
3861 amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { amtMeiTmpState.UUID = result.uuid; } });
3862 if ((flags & 2) != 0) { amtMei.getLocalSystemAccount(function (x) { if ((x != null) && x.user && x.pass) { amtMeiTmpState.OsAdmin = { user: x.user, pass: x.pass }; } }); }
3855 - amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.DNS = result; } if ((flags & 4) == 0) { if (func != null) { func(amtMeiTmpState); } } });
3863 + amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.DnsSuffix = result; } if ((flags & 4) == 0) { if (func != null) { func(amtMeiTmpState); } } });
3864 if ((flags & 4) != 0) {
3865 amtMei.getHashHandles(function (handles) {
3866 if (handles != null) { amtMeiTmpState.Hashes = []; } else { func(amtMeiTmpState); }
amtmanager.js
+19 -1
@@ -86,6 +86,9 @@ module.exports.CreateAmtManager = function(parent) {
86
87 // Remove all Intel AMT devices for a given nodeid
88 function removeDevice(nodeid) {
89 + // Remove from task limiter if needed
90 + if (dev.taskid != null) { obj.parent.taskLimiter.completed(dev.taskid); delete dev.taskLimiter; }
91 +
92 // Find the devices in the list
93 var devices = obj.amtDevices[nodeid];
94 if (devices == null) return false;
@@ -118,7 +121,18 @@ module.exports.CreateAmtManager = function(parent) {
121 dev.controlMsg.conn = connection;
122 parent.debug('amt', "Start Management", nodeid, connType);
123 addAmtDevice(dev);
121 - fetchIntelAmtInformation(dev);
124 +
125 + // Start the device manager the task limiter so not to flood the server. Low priority task
126 + obj.parent.taskLimiter.launch(function (dev, taskid, taskLimiterQueue) {
127 + if (isAmtDeviceValid(dev)) {
128 + // Start managing this device
129 + dev.taskid = taskid;
130 + fetchIntelAmtInformation(dev);
131 + } else {
132 + // Device is not valid anymore, do nothing
133 + obj.parent.taskLimiter.completed(taskid);
134 + }
135 + }, dev, 2);
136 }
137
138 // Stop Intel AMT management
@@ -355,6 +369,10 @@ module.exports.CreateAmtManager = function(parent) {
369 // See if we need to get hardware inventory
370 attemptFetchHardwareInventory(dev, function () {
371 dev.consoleMsg('Done.');
372 +
373 + // Remove from task limiter if needed
374 + if (dev.taskid != null) { obj.parent.taskLimiter.completed(dev.taskid); delete dev.taskLimiter; }
375 +
376 if (dev.connType != 2) {
377 // Start power polling if not connected to LMS
378 var ppfunc = function powerPoleFunction() { fetchPowerState(powerPoleFunction.dev); }