"use strict"; const Promise = require("bluebird"); const execBinary = require("../../exec-binary"); const parseIECBytes = require("../../parse-bytes-iec"); const asJson = require("../modifiers/as-json"); const mapFlag = require("../map-flag"); module.exports = function () { return Promise.try(() => { return execBinary("pvs") .asRoot() .withFlags({ options: "pv_all,vg_name" }) .withModifier(asJson((result) => { return { volumes: result.report[0].pv.map((volume) => { return { path: volume.pv_name, volumeGroup: (volume.vg_name === "") ? null : volume.vg_name, format: volume.pv_fmt, // FIXME: These amounts can contain commas depending on locale (eg. https://serverfault.com/a/648302) totalSpace: parseIECBytes(volume.pv_size), freeSpace: parseIECBytes(volume.pv_free), isAllocatable: (volume.pv_allocatable === "allocatable"), isDuplicate: (volume.pv_duplicate === "duplicate"), isUsed: (volume.pv_in_use === "used"), isExported: mapFlag(volume.pv_attr, 1, { x: true, "-": false }), isMissing: mapFlag(volume.pv_attr, 2, { m: true, "-": false }), }; }) }; })) .execute(); }).then((output) => { return output.result; }); };