How to automate V-box VM in C++ on Linux

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
MVS
Posts: 11
Joined: 27. Aug 2013, 15:08

How to automate V-box VM in C++ on Linux

Post by MVS »

Hi to all,

I wish to automate virtual machine using c++ language in Linux OS. Following are the list of things i wish to do

1)creating Virtual machine
2)Attaching device(i.e either .vhd or .vmdk)
3)starting virtual machine
4)Listing Virtual machines which are available
5)taking snapshot of virtual machine

is this things possible using C++ language on Linux platform, if so, can some one guide me how to start this

comments, suggestions, sample codes are most welcome

Regard's
Mohan
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to automate V-box VM in C++ on Linux

Post by noteirak »

All this if possible yes.
First of all, download the SDK for your version. File name is formated like this : VirtualBoxSDK-x.x.x-revision.zip
In the ZIP file, you'll find a doc folder with a PDF. This explains to you how to get started. You'll also find sample code in the ZIP file.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How to automate V-box VM in C++ on Linux

Post by socratis »

If these are the only steps that you want to do, another option would be to use the "VBoxManage" command-line tool in a script. Take a look at Chapter 8 in the User Manual. Example:

VBoxManage createvm --name <name>
VBoxManage storageattach <uuid|vmname> --storagectl <name>
VBoxManage startvm <uuid|vmname>
VBoxManage list vms|runningvms
VBoxManage snapshot <uuid|vmname>
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
MVS
Posts: 11
Joined: 27. Aug 2013, 15:08

Re: How to automate V-box VM in C++ on Linux

Post by MVS »

Thanks for your quick reply

previously I have done all these in windows platform using VirtualBoxSDK-4.2.16-86992.zip and that working so well, now i want to do the same in linux, for this need to use linux based sdk or is it possible to make the same windows code work in linux platform

if for both linux and windows is there separate API ? or can i use the same zip file which i have used for windows ?

I have found some files like virtualbox-4.2_4.2.16-86992~Debian~squeeze_amd64.deb at the link which you have sended before is this file regarding linux related API ?

Regard's
Mohan
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to automate V-box VM in C++ on Linux

Post by noteirak »

Windows us COM(MSCOM) while Linux use XPCOM. The API would be the same, the actualy initialization code would differ. I never used C++ with Virtualbox, so I can't tell you the exact difference, but it is all explained in the PDF reference. It's quite long to read, but worth it.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply