Comments

On Fri, Jul 27, 2012 at 06:20:48PM +0800, Wenchao Xia wrote:
> This patch would add option -j in qemu-img info command, which> would generate json output in stdout.
I like this idea in general, because currently apps (oVirt, OpenStack, etc)
rely on parsing the human format, which is just as evil as libvirt relying
on -help format.
It would be helpful if you actually included the JSON output in your
commit message. For the benefit of other reviews, it generates the
following:
#qemu-img info -j /var/lib/libvirt/images/bar.qcow2
{
"information": {
"actual_size": "139264",
"fmt": "qcow2",
"virtual_size": "10485760",
"filename": "/var/lib/libvirt/images/bar.qcow2",
"cluster_size": 65536,
"encrypted": 0,
"snapshot_list": [
],
"dirty_flag": 0,
"backing_filename": "/dev/sda1"
},
"return": 0
}
IIUC,the 'return' element here is just duplicating the qemu-img
exit status. I think this is rather dubious, and would rather
just see the stuff in the 'information' sub-block be output
directly. It also seems to forget to mention the backing
file format.
Daniel

Il 27/07/2012 12:33, Daniel P. Berrange ha scritto:
> #qemu-img info -j /var/lib/libvirt/images/bar.qcow2> {> "information": {> "actual_size": "139264",> "fmt": "qcow2",> "virtual_size": "10485760",> "filename": "/var/lib/libvirt/images/bar.qcow2",> "cluster_size": 65536,> "encrypted": 0,> "snapshot_list": [> ],> "dirty_flag": 0,> "backing_filename": "/dev/sda1"> },> "return": 0> }> > IIUC,the 'return' element here is just duplicating the qemu-img> exit status. I think this is rather dubious, and would rather> just see the stuff in the 'information' sub-block be output> directly. It also seems to forget to mention the backing> file format.
I wonder if we could add this also to the QEMU monitor ("info
block-image foo"), so that the code would be shared between qemu-img.c
and QEMU.
Paolo

On 08/15/2012 02:49 AM, Benoît Canet wrote:
>> I think an --format=json option would be a bit more extensible and>> better matches what most tools are doing these days.> > The qemu-img info subcommand already use the "-f" short option.> What alternative could be use instead of --format=json ?
You are right that the mnemonic 'format' collides with -f and -F
(rebase), and 'output' collides with -o and -O (convert). Maybe we
could use the mnemonic '--layout=json', since '-L' appears to be
available? Or maybe '--machine=json' with -m, to indicate that the
output is machine-parseable (and where other machine-parseable layouts
like xml might be added in the future)?
Also, there's no rule that says that the short option must match the
mnemonic of the long option; we could always go with the short option of
'-j' even if the long option is spelled '--format', even if it means a
theoretical addition of '--format=xml' would map to the odd-looking '-j
xml'.