Temporary removal of VirtualBox

This commit is contained in:
Jeffrey Morgan 2015-02-11 15:24:29 -08:00
parent a8a490ea70
commit e6ea5024b7
1 changed files with 0 additions and 66 deletions

View File

@ -1,66 +0,0 @@
var fs = require('fs');
var util = require('./Util');
var Promise = require('bluebird');
var VirtualBox = {
command: function () {
return '/usr/bin/VBoxManage';
},
installed: function () {
return fs.existsSync('/usr/bin/VBoxManage') && fs.existsSync('/Applications/VirtualBox.app');
},
version: function () {
return new Promise((resolve, reject) => {
util.exec([this.command(), '-v']).then(stdout => {
var match = stdout.match(/(\d+\.\d+\.\d+).*/);
if (!match || match.length < 2) {
reject('VBoxManage -v output format not recognized.');
}
resolve(match[1]);
}).catch(reject);
});
},
poweroffall: function () {
if (!this.installed()) {
return Promise.reject('VirtualBox not installed.');
}
return util.exec(this.command() + ' list runningvms | sed -E \'s/.*\\{(.*)\\}/\\1/\' | xargs -L1 -I {} ' + this.command() + ' controlvm {} poweroff');
},
killall: function () {
if (!this.installed()) {
return Promise.reject('VirtualBox not installed.');
}
return this.poweroffall().then(() => {
return util.exec(['pkill', 'VirtualBox']);
}).then(() => {
return util.exec(['pkill', 'VBox']);
});
},
vmstate: function (name) {
return new Promise((resolve, reject) => {
util.exec([this.command(), 'showvminfo', name, '--machinereadable']).then(stdout => {
var match = stdout.match(/VMState="(\w+)"/);
if (!match) {
reject('Could not parse VMState');
}
resolve(match[1]);
}).catch(reject);
});
},
vmdestroy: function (name) {
return Promise.coroutine(function* () {
if (!this.installed()) {
return Promise.reject('VirtualBox not installed.');
}
try {
var state = yield this.vmstate(name);
if (state === 'running') {
yield util.exec([this.command(), 'controlvm', name, 'poweroff']);
}
yield util.exec([this.command(), 'unregistervm', name, '--delete']);
} catch (err) {}
}.bind(this))();
}
};
module.exports = VirtualBox;