You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cvm/src/wrappers/lsblk.js

51 lines
1.1 KiB
JavaScript

"use strict";
const Promise = require("bluebird");
const execBinary = require("../exec-binary");
const parseIECBytes = require("../parse/bytes/iec");
const mapValue = require("../map-value");
function parseBoolean(value) {
return mapValue(value, {
0: false,
1: true
});
}
function mapType(value) {
return mapValue(value, {
part: "partition",
disk: "disk",
loop: "loopDevice"
});
}
function mapDeviceList(devices) {
return devices.map((device) => {
return {
name: device.name,
type: mapType(device.type),
mountpoint: device.mountpoint,
deviceNumber: device["maj:min"],
removable: parseBoolean(device.rm),
readOnly: parseBoolean(device.ro),
size: parseIECBytes(device.size),
children: (device.children != null) ? mapDeviceList(device.children) : []
};
})
}
module.exports = function lsblk() {
return Promise.try(() => {
return execBinary("lsblk")
.withFlags({ json: true })
.singleResult()
.expectJsonStdout((result) => {
return mapDeviceList(result.blockdevices);
})
.execute();
}).then((output) => {
return output.result;
});
};