Firstly, is there such a thing already? (libvirt doesn't count since it cannot generate -readconfig configuration files)
Well, I have written one. It's in C and doesn't have any dependencies beyond the standard C library: https://github.com/rwmjones/libguestfs/tree/max-disks/common/qemuopts It models command line parameters as either flags (eg. ‘-nodefconfig’), flags with a single argument (‘-name guest’), or flags taking a list (eg. ‘-drive file=foo,id=bar’ modeled as a list of strings). I'm immediately aware that there are shortcomings with this approach (see below). Is there a better model to use for qemu command line options that also allows -readconfig config files to be generated? Some of the more obvious problems: * I don't know if single flags can be translated into config files. * Config files treat the "id=.." parameter as special, eg: ‘-drive file=foo,id=bar’ is translated to: [drive "bar"] file = "foo" * There's no clear mapping between some command line parameters and the config file, eg. ‘-m 2048 -kernel foo’ should be translated into: [memory] size = "2048" [machine] kernel = "foo" but my library couldn't do that translation without a look-up table that would duplicate the internals of qemu. There are also unknown unknowns: * Is comma-quoting (ie. doubling any commas) sufficient? Or are there other forms of quoting? A quick look at options parsing in qemu doesn't show any. * From the point of view of a client generating command lines, is there any significance to dotted names (eg. ‘-drive file.driver=ssh,...’) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v