Creating a machine using the APIs

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
JimBob227
Posts: 3
Joined: 17. Dec 2015, 20:49

Creating a machine using the APIs

Post by JimBob227 »

So I am trying to create a machine using entirely APIs and configuring qualities of that machine to specific values. (Note, I am using the python implementation of the APIs). Currently what I do is:

import virtualbox
vbox = virtualbox.VirtualBox()
vm = vbox.create_machine(settings_file,"test_vm",[],"Linux","")

This successfully creates a machine with all default parameters. I need to change some of them, for example the base memory, network attachment needs to be a bridged adapter with a specific adapter type, I need to specify the MAC address, etc.

Is there some sort of standard API/method used to set these or is it specific to each property? Or is there documentation on this hidden somewhere?
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: Creating a machine using the APIs

Post by noteirak »

Creating a VM in the common sense is a 4 steps action:
1. Create the VM itself
2. Apply default settings or your own, create disks, etc.
3. Save it to a configuration file
4. Register that configuration file in VirtualBox so the VM can be used

What you did so far is #1 and you have a VM which is unusable since the config will not work out of the box, you don't have a disk, you don't have a NIC.
The different steps are also explained in more details on IVirtualBox::createMachine()

To know what parameters can be changed, you need to look at the IMachine interface which is described in the SDK - either online or with the PDF provided in the SDK you downloaded (which I would recommend).

About step #2, you can get the recommended settings for the given OS Type (4th parameter of IVirtualBox::createMachine()) in the specific IGuestOsType via the ::recommandedXXX() methods.
To get the specific IGuestOsType, use IVirtualBox::getGuestOsType(id)

#3 is done via IMachine::saveSettings() on the current IMachine object you have after IVirtualBox::createMachine();

#4 is done via IVirtualBox::registerMachine() again on the IMachine object you have.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply