blockDevices() added groups for raid (linux)

This commit is contained in:
Sebastian Hildebrandt 2022-11-18 17:44:59 +01:00
parent c544e80c20
commit b1b017a95f

View File

@ -369,16 +369,18 @@ function decodeMdabmData(lines) {
function raidMatchLunix(data) { function raidMatchLunix(data) {
// for all block devices of type "raid%" // for all block devices of type "raid%"
let result = data;
try { try {
data.forEach(element => { data.forEach(element => {
if (element.type.startsWith('raid')) { if (element.type.startsWith('raid')) {
const lines = execSync(`mdadm --export --detail /dev/${element.name}`).toString().split('\n'); const lines = execSync(`mdadm --export --detail /dev/${element.name}`).toString().split('\n');
const mdData = decodeMdabmData(lines); const mdData = decodeMdabmData(lines);
if (mdData && mdData.members && mdData.members.length && mdData.raid === element.type) { if (mdData && mdData.members && mdData.members.length && mdData.raid === element.type) {
data.forEach(blockdevice => { result = result.map(blockdevice => {
if (blockDevices.fsType === 'linux_raid_member' && mdData.members.indexOf(blockdevice.name) >= 0) { if (blockdevice.fsType === 'linux_raid_member' && mdData.members.indexOf(blockdevice.name) >= 0) {
blockdevice.group = element.name; blockdevice.group = element.name;
} }
return blockdevice;
}); });
} }
} }
@ -386,6 +388,7 @@ function raidMatchLunix(data) {
} catch (e) { } catch (e) {
util.noop(); util.noop();
} }
return result;
} }
function blkStdoutToObject(stdout) { function blkStdoutToObject(stdout) {
@ -420,7 +423,7 @@ function blockDevices(callback) {
if (!error) { if (!error) {
let lines = blkStdoutToObject(stdout).split('\n'); let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines); data = parseBlk(lines);
raidMatchLunix(data); data = raidMatchLunix(data);
if (callback) { if (callback) {
callback(data); callback(data);
} }
@ -430,7 +433,7 @@ function blockDevices(callback) {
if (!error) { if (!error) {
let lines = blkStdoutToObject(stdout).split('\n'); let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines); data = parseBlk(lines);
raidMatchLunix(data); data = raidMatchLunix(data);
} }
if (callback) { if (callback) {
callback(data); callback(data);