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.
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const execBinary = require("../../exec-binary");
|
|
const { errorResult } = require("../../text-parser");
|
|
const createRegexParser = require("../../text-parser-regex");
|
|
|
|
const handleDeviceNotFound = require("../modifiers/handle-device-not-found");
|
|
const handlePhysicalVolumeInUse = require("../modifiers/handle-physical-volume-in-use");
|
|
const errors = require("../errors");
|
|
|
|
module.exports = function ({ devicePath }) {
|
|
return Promise.try(() => {
|
|
return execBinary("pvremove", [devicePath])
|
|
.asRoot()
|
|
.requireResult()
|
|
.withModifier(handleDeviceNotFound(devicePath))
|
|
.withModifier(handlePhysicalVolumeInUse(devicePath))
|
|
.expectOnStdout(createRegexParser(/Labels on physical volume "[^"]+" successfully wiped\./, () => undefined))
|
|
.expectOnStderr(createRegexParser(/No PV( label)? found on .+\./, () => {
|
|
return errorResult(new errors.InvalidPath(`Specified device '${devicePath}' is not a Physical Volume`, {
|
|
path: devicePath
|
|
}));
|
|
}))
|
|
.execute();
|
|
}).then((_output) => {
|
|
return true;
|
|
});
|
|
};
|