Wednesday, January 25, 2012

GNS3 VirtualBox Edition installation gotchas

Trying to run VirtualBox in GNS3 VirtualBox Edition 0.8.1 threw up the following error when I clicked "Test" in the GNS3 -> Edit -> Preferences -> VirtualBox

"Failed to load vboxapi module; Please check VirtualBox installation."

Attempting to google this problem got me to a few different forums/posts, but surprisingly no clear solution/workaround. What worked for me was to manually run (as Adminstrator) the VirtualBox vboxapi installation script:

C:\Program Files\Oracle\VirtualBox\sdk\install>"c:\Program Files\Python26\python.exe" vboxapisetup.py install

Cleaning COM cache at c:\Program Files\Python26\Lib\site-packages\win32com\gen_py and C:\Users\jim\AppData\Local\Temp\gen_py
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\vboxapi
copying vboxapi\VirtualBox_constants.py -> build\lib\vboxapi
copying vboxapi\__init__.py -> build\lib\vboxapi
running install_lib
creating c:\Program Files\Python26\Lib\site-packages\vboxapi
copying build\lib\vboxapi\VirtualBox_constants.py -> c:\Program Files\Python26\Lib\site-packages\vboxapi
copying build\lib\vboxapi\__init__.py -> c:\Program Files\Python26\Lib\site-packages\vboxapi
byte-compiling c:\Program Files\Python26\Lib\site-packages\vboxapi\VirtualBox_constants.py to VirtualBox_constants.pyc
byte-compiling c:\Program Files\Python26\Lib\site-packages\vboxapi\__init__.py to __init__.pyc
running install_egg_info
Writing c:\Program Files\Python26\Lib\site-packages\vboxapi-1.0-py2.6.egg-info


C:\Program Files\Oracle\VirtualBox\sdk\install>



(Note: The default GNS3 0.8.1 VBE Python installation defaults to "c:\Python26". which I changed to "c:\Program Files\Python26\". You should adjust the command accordingly to your own installation path.)


The full gory details follows:

This particular error is supposed to be already fixed in GNS3 0.8.1 (which was the version I installed), as listed in the release notes:

0.8.1:
a. Fixed the problem, where importing topology with a different Cisco IOS version failed.
b. Fixed the problem, where installing GNS3 after VirtualBox resulted in "failed to load vboxapi module" error. (Windows hosts only)
c. Changed default vNICs to 1 for new VBox VMs (those are expected to be mostly used as desktops)


However, after I installed GNS3 0.8.1 VBE, as you can see from the screen, the error still occurred on my particular installation (on Windows 7 64-bit, VirtualBox 4.1.8).





The supposed cause is when VirtualBox is installed before GNS3 VBE, which I suppose is the case for most people likely to want to use VirtualBox in GNS3.

I then tried uninstalling VirtualBox 4.1.8 and GNS3 VBE, reinstalling GNS3 VBE with it's full complement of addons, and installing VirtualBox 4.1.8 (carefully checking to ensure that I installed the necessary python api). Didn't help.

After yet more googl'ing, I cam across a link How to install/setup VirtualBox Web Console that hinted that vboxapi needs to be installed.

python vboxapisetup.py install

I found the necessary path and file on my installation, but my first attempt didn't succeed, probably due to not running Command Prompt as Administrator. (In fairness, the above URL did mention to run the command as Administrator, which I missed.)

C:\Program Files\Oracle\VirtualBox\sdk\install>"c:\Program Files\Python26\python.exe" vboxapisetup.py
Cleaning COM cache at c:\Program Files\Python26\Lib\site-packages\win32com\gen_py and C:\Users\jim\AppData\Local\Temp\ge
n_py
Traceback (most recent call last):
  File "vboxapisetup.py", line 76, in <module>
    main(sys.argv)
  File "vboxapisetup.py", line 64, in main
    patchWith(os.path.join(os.path.dirname(sys.argv[0]), 'vboxapi', '__init__.py'), vboxDest, vboxSdkDest)
  File "vboxapisetup.py", line 33, in patchWith
    newF = open(newFile, 'w')
IOError: [Errno 13] Permission denied: 'vboxapi\\__init__.py.new'


I re-attempted running the "vboxapisetup.py" command, this time in an Administrator Command Prompt. It succeeded, and now I'm happily running VirtualBox VMs in GNS3 VBE.

C:\Program Files\Oracle\VirtualBox\sdk\install>"c:\Program Files\Python26\python.exe" vboxapisetup.py install
Cleaning COM cache at c:\Program Files\Python26\Lib\site-packages\win32com\gen_py and C:\Users\jim\AppData\Local\Temp\gen_py
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\vboxapi
copying vboxapi\VirtualBox_constants.py -> build\lib\vboxapi
copying vboxapi\__init__.py -> build\lib\vboxapi
running install_lib
creating c:\Program Files\Python26\Lib\site-packages\vboxapi
copying build\lib\vboxapi\VirtualBox_constants.py -> c:\Program Files\Python26\Lib\site-packages\vboxapi
copying build\lib\vboxapi\__init__.py -> c:\Program Files\Python26\Lib\site-packages\vboxapi
byte-compiling c:\Program Files\Python26\Lib\site-packages\vboxapi\VirtualBox_constants.py to VirtualBox_constants.pyc
byte-compiling c:\Program Files\Python26\Lib\site-packages\vboxapi\__init__.py to __init__.pyc
running install_egg_info
Writing c:\Program Files\Python26\Lib\site-packages\vboxapi-1.0-py2.6.egg-info

C:\Program Files\Oracle\VirtualBox\sdk\install>