<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
Hi Klaus,</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
I'm using the following python code snippet to retrieve the relevant information from running "VBoxManage list vms --long":</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
<div>
<div>    result = subprocess.run( <span style="background-color:rgb(255, 255, 255);display:inline !important">
"VBoxManage list vms --long"</span>, stdout = subprocess.PIPE, shell = True ).stdout.decode()</div>
<div>    for line in result.splitlines():<br>
</div>
</div>
<div>        if line.startswith( "Name:" ):</div>
<div>            name = line.split( "Name:" )[ 1 ].strip()</div>
<div><br>
</div>
<div>        elif line.startswith( "Groups:" ):</div>
<div>            groups = line.split( '/' )[ 1 : ]</div>
<div><br>
</div>
<div>        elif line.startswith( "UUID:" ):</div>
<span>            uuid = line.split( "UUID:" )[ 1 ].strip()</span><br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
        print( name, groups, uuid )</div>
<div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
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...</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
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!</div>
<div id="Signature">
<div>
<div></div>
<div id="divtagdefaultwrapper" style="font-size:10pt; color:#000000; font-family:Arial,Helvetica,sans-serif">
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><br>
</font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2">I have taken a look at the output of running <span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important">"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...</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important">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).</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important">Fingers crossed the VBoxManage approach(es) are stable and long term!</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important">Thanks again,</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></font></span></div>
<div style="line-height:21px"><span style="line-height:18px"><font face="Arial" size="2"><span style="font-size:small;background-color:rgb(255, 255, 255);display:inline !important">Bernard.</span></font></span></div>
<div style="line-height:21px"><br>
</div>
</div>
</div>
</div>
</div>
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> vbox-dev-bounces@virtualbox.org <vbox-dev-bounces@virtualbox.org> on behalf of Klaus Espenlaub <klaus.espenlaub@oracle.com><br>
<b>Sent:</b> Friday, 5 November 2021 05:03<br>
<b>To:</b> vbox-dev@virtualbox.org <vbox-dev@virtualbox.org><br>
<b>Subject:</b> Re: [vbox-dev] VB xml format</font>
<div> </div>
</div>
<div>Hi Bernard,<br>
<br>
On 2021-11-04 09:11, Bernard Giannetti wrote:<br>
<blockquote type="cite">
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
Hi Stéphane, <span style="">fth0</span>, Klaus,</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
Thanks for your responses.  I have done some digging/reading...</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
Looking at</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
    <span style="background-color:rgb(255,255,255); display:inline!important"><a href="https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp" class="x_moz-txt-link-freetext">https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp</a></span> </div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
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.<br>
</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
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:</div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
<div><br>
</div>
<div>    VBoxManage list vms --long<br>
</div>
<div><br>
</div>
<div>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.</div>
</div>
</blockquote>
<br>
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).<br>
<br>
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
 "".<br>
<br>
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.<br>
<br>
Klaus<br>
<br>
<blockquote type="cite">
<div style="font-family:Arial,Helvetica,sans-serif; font-size:10pt; color:rgb(0,0,0)">
<div><br>
</div>
<div><br>
</div>
<div>Thanks again for the help,</div>
<div><br>
</div>
<div class="x_moz-signature">Bernard.<font size="2" face="Verdana,
            Arial, Helvetica, sans-serif" color="#666666">
</font></div>
</div>
</blockquote>
</div>
</div>
</body>
</html>