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.
37 lines
759 B
JavaScript
37 lines
759 B
JavaScript
'use strict';
|
|
|
|
const Promise = require("bluebird");
|
|
const uuid = require("uuid");
|
|
const childProcess = Promise.promisifyAll(require("child-process"), {multiArgs: true});
|
|
|
|
module.exports = function(storePath) {
|
|
function getPath(id) {
|
|
return path.join(storePath, `${id}.img`);
|
|
}
|
|
|
|
return {
|
|
getPath: function getDisk(id) {
|
|
return getPath(id);
|
|
},
|
|
create: function createDisk(size, {type} = {type: "qcow2"}) {
|
|
return Promise.try(() => {
|
|
let diskId = uuid.v4();
|
|
|
|
return Promise.try(() => {
|
|
childProcess.execFileAsync("qemu-img", [
|
|
"create",
|
|
"-f", type,
|
|
getPath(diskId),
|
|
size
|
|
]);
|
|
}).then(([stdout, stderr]) => {
|
|
return diskId;
|
|
});
|
|
});
|
|
},
|
|
resize: function resizeDisk(id, size) {
|
|
|
|
}
|
|
}
|
|
}
|