Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
E.Azer Koçulu
committed
Jan 3, 2012
0 parents
commit a65986a
Showing
10 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# node-virtualbox | ||
A JavaScript library to interact with Virtualbox. | ||
|
||
# Installation | ||
|
||
```bash | ||
$ npm install virtualbox | ||
``` | ||
|
||
# Examples | ||
|
||
## Starting and Running a program | ||
|
||
```javascript | ||
var virtualbox = require('virtualbox'); | ||
|
||
virtualbox.start("Win32", function(error){ | ||
|
||
if(error) throw error; | ||
|
||
console.log('VM "w7" has been successfully started'); | ||
|
||
virtualbox.exec({ vm: "win32", cmd: "C:\Program Files\Internet Explorer\iexplore.exe", params: "http://google.com" }, function(error){ | ||
|
||
if(error) throw error; | ||
|
||
console.log('Running Internet Explorer...'); | ||
|
||
}); | ||
|
||
}); | ||
``` | ||
|
||
# Available Methods | ||
|
||
* start | ||
* stop | ||
* exec | ||
* reset | ||
* pause | ||
* resume | ||
|
||
# Troubleshooting | ||
|
||
* Make sure that Guest account is enabled on the VM. | ||
* This library starts VMs headlessly by default. If you're having with executing a command, start the VM with GUI and run observe the screen after executing same command. | ||
* For the "Concurrent guest process limit is reached" error message, only solution I know is to reset the VM. | ||
|
||
# Example Uses | ||
|
||
* [Lowkick](http://github.com/azer/lowkick) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var log4js = require('log4js'), | ||
logger = log4js.getLogger('VirtualBox'); | ||
|
||
logger.setLevel('INFO'); | ||
|
||
module.exports = logger; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var exec = require('child_process').exec, | ||
logging = require('./logging'), | ||
undefined = function(){}(); | ||
|
||
function pause(vmname, callback){ | ||
logging.info('Pausing VM "%s"', vmname); | ||
exec('vboxmanage controlvm "'+vmname+'" pause', function(error, stdout, stderr){ | ||
callback(error); | ||
}); | ||
} | ||
|
||
function reset(vmname, callback){ | ||
logging.info('Resetting VM "%s"', vmname); | ||
exec('vboxmanage controlvm "'+vmname+'" reset', function(error, stdout, stderr){ | ||
callback(error); | ||
}); | ||
} | ||
|
||
function resume(vmname, callback){ | ||
logging.info('Resuming VM "%s"', vmname); | ||
exec('vboxmanage controlvm "'+vmname+'" resume', function(error, stdout, stderr){ | ||
callback(error); | ||
}); | ||
} | ||
|
||
function start(vmname, callback){ | ||
logging.info('Starting VM "%s"', vmname); | ||
exec('vboxmanage -nologo startvm "'+vmname+'" --type headless', function(error, stdout, stderr){ | ||
|
||
if(error && /VBOX_E_INVALID_OBJECT_STATE/.test(error.message)){ | ||
error = undefined; | ||
} | ||
|
||
callback(error); | ||
}); | ||
} | ||
|
||
function stop(vmname, callback){ | ||
logging.info('Stopping VM "%s"', vmname); | ||
exec('vboxmanage controlvm "'+vmname+'" savestate', function(error, stdout, stderr){ | ||
callback(error); | ||
}); | ||
} | ||
|
||
function vmExec(options, callback){ | ||
var vm = options.vm || options.name || options.vmname || options.title, | ||
path = options.path || options.cmd || options.command || options.exec || options.execute || options.run, | ||
params = options.params || options.parameters || options.args; | ||
|
||
Array.isArray(params) && ( params = params.join(" ") ); | ||
|
||
params == undefined && ( params = "" ); | ||
|
||
path = path.replace(/\\/g, '\\\\'); | ||
|
||
var cmd = 'VBoxManage guestcontrol '+vm+' execute --image "cmd.exe" --username Guest -- "/c" "'+path+'" "'+params+'"'; | ||
|
||
logging.info('Executing command "%s" on VM "%s"', cmd, vm); | ||
|
||
exec(cmd, function(error, stdout, stderr){ | ||
callback(error); | ||
}); | ||
} | ||
|
||
|
||
module.exports = { | ||
'exec': vmExec, | ||
'pause': pause, | ||
'reset': reset, | ||
'resume': resume, | ||
'start': start, | ||
'stop': stop | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name":"virtualbox", | ||
"version":"0.0.1", | ||
"description":"A library to interact with VirtualBox.", | ||
"author":"Azer Koculu <azer@kodfabrik.com>", | ||
"keywords":["virtualbox","vboxmanage"], | ||
"directories":{ "lib": "./lib" }, | ||
"main":"./lib/virtualbox", | ||
"repository": { "type":"git", "url" : "http://github.com/azer/node-virtualbox.git" }, | ||
"dependencies":{ | ||
"log4js": "0.x" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var virtualbox = require('../lib/virtualbox'), | ||
args = process.argv.slice(2), | ||
vm = args[0], | ||
path = "C:\\Program Files\\Internet Explorer\\iexplore.exe"; | ||
|
||
|
||
virtualbox.start(vm, function(){ | ||
|
||
virtualbox.exec({ 'vm': vm, 'path': path, 'params': [args[1] || 'google.com'] }, function(error){ | ||
if(error) throw error; | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var virtualbox = require('../lib/virtualbox'), | ||
args = process.argv.slice(2); | ||
|
||
virtualbox.pause(args[0], function(error){ | ||
if(error) throw error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var virtualbox = require('../lib/virtualbox'), | ||
args = process.argv.slice(2); | ||
|
||
virtualbox.resume(args[0], function(error){ | ||
if(error) throw error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var virtualbox = require('../lib/virtualbox'), | ||
args = process.argv.slice(2); | ||
|
||
virtualbox.start(args[0], function(error){ | ||
if(error) throw error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var virtualbox = require('../lib/virtualbox'), | ||
args = process.argv.slice(2); | ||
|
||
virtualbox.stop(args[0], function(error){ | ||
if(error) throw error; | ||
}); |