[vbox-dev] VB xml format

Bernard Giannetti thebernmeister at hotmail.com
Thu Nov 4 22:14:56 UTC 2021

Hi Klaus,

I'm using the following python code snippet to retrieve the relevant information from running "VBoxManage list vms --long":

    result = subprocess.run( "VBoxManage list vms --long", stdout = subprocess.PIPE, shell = True ).stdout.decode()
    for line in result.splitlines():
        if line.startswith( "Name:" ):
            name = line.split( "Name:" )[ 1 ].strip()

        elif line.startswith( "Groups:" ):
            groups = line.split( '/' )[ 1 : ]

        elif line.startswith( "UUID:" ):
            uuid = line.split( "UUID:" )[ 1 ].strip()

        print( name, groups, uuid )

Didn't take long to knock up the above code and I'm now in the middle of massaging the nested group information into an internal Python object to represent each machine/group.  I did this already in a different fashion when parsing the XML file, so hopefully won't take me too long...

I developed my indicator in 2012 and have noticed changes in format within the XML file over the years.  Nothing too drastic, but given the undocumented nature of the file, I was always slightly nervous.  I have avoided legacy data by always moving with the supported versions of VirtualBox, currently 5 and 6, but I'm not 100% confident that will always work as the XML file still does support very old config files and is not publicly documented...not ideal conditions for parsing!

I have taken a look at the output of running "VBoxManage showvminfo uuid --machinereadable" and whilst it looks slightly easier to retrieve the information, it does have the disadvantage of needing to poll every VM.  I implement this way and compare with that above to see how long it takes in comparison.  But regardless, I feel using the VBoxManage command(s) is the way to go...

I wasn't able to easily determine how to access the Python bindings/API.  I did download the SDK and after cursorily reading the documentation I suspect each user of my indicator also needs part of the SDK (I can package it up but now there are more moving parts than I care for and I'm not even sure of the licensing).

Fingers crossed the VBoxManage approach(es) are stable and long term!

Thanks again,


From: vbox-dev-bounces at virtualbox.org <vbox-dev-bounces at virtualbox.org> on behalf of Klaus Espenlaub <klaus.espenlaub at oracle.com>
Sent: Friday, 5 November 2021 05:03
To: vbox-dev at virtualbox.org <vbox-dev at virtualbox.org>
Subject: Re: [vbox-dev] VB xml format

Hi Bernard,

On 2021-11-04 09:11, Bernard Giannetti wrote:
Hi Stéphane, fth0, Klaus,

Thanks for your responses.  I have done some digging/reading...

Looking at

and the functions prefixToString() and optionToString(), I see the characters that define group and machine, but there are some other characters which don't make sense...but that I don't believe affects my situation.  That 'gc' and 'go' both refer to groups, that fixes my immediate issue.

Longer term, I will ditch parsing the XML configuration file as this is chasing my tail at best!  After some investigation, I believe I can use:

    VBoxManage list vms --long

to give me each machine's name, UUID and group.  Hopefully this works as expected as this is preferable to calling the API via a COM wrapper or the web server interface.

My recommendation would be using the Python API bindings since that's rather convenient, balancing flexibility with pretty limited impact from API changes (that said, the Python API bindings may not be available in a certain VirtualBox installation, depending on how annoying the support of a specific Linux distro's Python 2/3 migration strategy is).

If you insist using "VBoxManage" (one of the main source of useless error reports e.g. from Vagrant fans) then I would at least hope you go for an approach which will be a little more reliable ("VBoxManage list vms --long" produces human readable output, i.e. it can change relatively arbitrarily): go for a two-stage approach. First get the list of VM UUIDs with "VBoxManage list vms", and then get the detail information you need with "VBoxManage showvminfo uuid --machinereadable". The output of the latter should be a lot easier to process. It is kind of a list of shell variables (anything with an all lowercase name is the associated VBoxManage modifyvm option name, anything mixed case has no direct correspondence), with string values possibly containing spaces in "".

In principle this could be also offered with "VBoxManage list vms --long", but so far no one has thought of this and therefore it wouldn't work for existing VirtualBox releases.


Thanks again for the help,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20211104/166dce2e/attachment.html>

More information about the vbox-dev mailing list