|
|
@ -7,6 +7,9 @@ const mapObj = require("map-obj");
|
|
|
|
|
|
|
|
|
|
|
|
const lvm = require("../../packages/exec-lvm");
|
|
|
|
const lvm = require("../../packages/exec-lvm");
|
|
|
|
const All = require("../../packages/graphql-interface/symbols/all");
|
|
|
|
const All = require("../../packages/graphql-interface/symbols/all");
|
|
|
|
|
|
|
|
const nvmeCLI = require("../../packages/exec-nvme-cli");
|
|
|
|
|
|
|
|
const smartctl = require("../../packages/exec-smartctl");
|
|
|
|
|
|
|
|
const dlayerWrap = require("../../packages/dlayer-wrap");
|
|
|
|
|
|
|
|
|
|
|
|
// This generates a (memoized) source function for commands that always produce an entire list, that needs to be filtered for the desired item(s)
|
|
|
|
// This generates a (memoized) source function for commands that always produce an entire list, that needs to be filtered for the desired item(s)
|
|
|
|
function makeListCommand({ command, selectResult, selectID }) {
|
|
|
|
function makeListCommand({ command, selectResult, selectID }) {
|
|
|
@ -26,43 +29,77 @@ function makeListCommand({ command, selectResult, selectID }) {
|
|
|
|
if (id === All) {
|
|
|
|
if (id === All) {
|
|
|
|
return items;
|
|
|
|
return items;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return items.find((item) => selectID(item, id));
|
|
|
|
return items.find((item) => selectID(item) === id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function makeSingleCommand({ command, selectResult }) {
|
|
|
|
|
|
|
|
return function (ids) {
|
|
|
|
|
|
|
|
return Promise.map(ids, (id) => {
|
|
|
|
|
|
|
|
if (id === All) {
|
|
|
|
|
|
|
|
// FIXME: Have some sort of mechanism for making this possible?
|
|
|
|
|
|
|
|
throw new Error(`This data source does not support fetching all entries`);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return command(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}).map((result) => {
|
|
|
|
|
|
|
|
if (selectResult != null) {
|
|
|
|
|
|
|
|
return selectResult(result);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function createSources() {
|
|
|
|
module.exports = function createSources() {
|
|
|
|
let sources = {
|
|
|
|
let sources = {
|
|
|
|
lvmLogicalVolumes: makeListCommand({
|
|
|
|
lvmLogicalVolumes: makeListCommand({
|
|
|
|
command: lvm.getLogicalVolumes,
|
|
|
|
command: lvm.getLogicalVolumes,
|
|
|
|
selectResult: (result) => result.volumes,
|
|
|
|
selectResult: (result) => result.volumes,
|
|
|
|
selectID: (volume, path) => (volume.path === path)
|
|
|
|
selectID: (volume) => volume.path
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
lvmPhysicalVolumes: makeListCommand({
|
|
|
|
lvmPhysicalVolumes: makeListCommand({
|
|
|
|
command: lvm.getPhysicalVolumes,
|
|
|
|
command: lvm.getPhysicalVolumes,
|
|
|
|
selectResult: (result) => result.volumes,
|
|
|
|
selectResult: (result) => result.volumes,
|
|
|
|
selectID: (device, path) => (device.path === path)
|
|
|
|
selectID: (device) => device.path
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
lvmVolumeGroups: makeListCommand({
|
|
|
|
lvmVolumeGroups: makeListCommand({
|
|
|
|
command: lvm.getVolumeGroups,
|
|
|
|
command: lvm.getVolumeGroups,
|
|
|
|
selectResult: (result) => result.groups,
|
|
|
|
selectResult: (result) => result.groups,
|
|
|
|
selectID: (group, name) => (group.name === name)
|
|
|
|
selectID: (group) => group.name
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
nvmeIdentifyController: makeSingleCommand({
|
|
|
|
|
|
|
|
command: (path) => nvmeCLI.identifyController({ devicePath: path })
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
nvmeListNamespaces: makeSingleCommand({
|
|
|
|
|
|
|
|
command: (path) => nvmeCLI.listNamespaces({ devicePath: path })
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
smartctlScan: makeListCommand({
|
|
|
|
|
|
|
|
command: smartctl.scan,
|
|
|
|
|
|
|
|
selectID: (device) => device.path
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
smartctlInfo: makeSingleCommand({
|
|
|
|
|
|
|
|
command: (path) => dlayerWrap(() => smartctl.info({ devicePath: path }), {
|
|
|
|
|
|
|
|
allowedErrors: [ smartctl.InfoError ]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
smartctlAttributes: makeSingleCommand({
|
|
|
|
|
|
|
|
command: (path) => dlayerWrap(() => smartctl.attributes({ devicePath: path }), {
|
|
|
|
|
|
|
|
allowedErrors: [ smartctl.AttributesError ]
|
|
|
|
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let factoryModules = {
|
|
|
|
let factoryModules = {
|
|
|
|
lsblk: require("./lsblk")(),
|
|
|
|
lsblk: require("./lsblk")(),
|
|
|
|
findmnt: require("./findmnt")(),
|
|
|
|
findmnt: require("./findmnt")()
|
|
|
|
smartctlInfo: require("./smartctl/info")(),
|
|
|
|
|
|
|
|
smartctlScan: require("./smartctl/scan")(),
|
|
|
|
|
|
|
|
smartctlAttributes: require("./smartctl/attributes")(),
|
|
|
|
|
|
|
|
nvmeListNamespaces: require("./nvme/list-namespaces")(),
|
|
|
|
|
|
|
|
nvmeIdentifyController: require("./nvme/identify-controller")(),
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return mapObj({ ... sources, ... factoryModules }, (name, factory) => {
|
|
|
|
return mapObj({ ... factoryModules, ... sources }, (name, factory) => {
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
new DataLoader(factory)
|
|
|
|
new DataLoader(factory)
|
|
|
|