Back in 2005, when the libvirt project was started, XML was pretty
much the only sensible, widely used format one could use to store
structured data. A lot has changed since then, and these days you'd
be hard pressed to find any API that does not use JSON for encoding
information; in fact, we already use JSON heavily inside libvirt, for
example to communicate with QEMU processes through QMP or store
configuration data for use by the libvirt NSS plugin.
The reasons for JSON's success over XML are plain to see: you get the
same nicely structured data, but none of the ugly angle brackets or
annoying repetition caused by having to both open *and* close
elements explicitly; additionally, you get support for extremely
useful and common data structures such as lists and dictionary out of
the box, and even properly typed strings and numbers. It's just an
overall much better data representation language.
This RFC series provides the initial, very basic (yet fully
functional) implementation of a JSON-based alternative to the
existing virDomainDefineXML(); over time, we would introduce similar
APIs for defining libvirt objects other than domains, such as for
example networks.
Once enough time has passed, we might even consider removing the
XML-based APIs altogether and drop the XML parsing code along with
our libxml2 dependency, making libvirt much leaner in the process.
Andrea Bolognani (8):
conf: Introduce virDomainDefParseJSONString()
tests: Add qemujson2argvtest
rpc: Add JSON to the list of fixups in gendispatch
Introduce the virDomainDefineJSONFlags() public API
remote: Implement virDomainDefineJSONFlags() support
qemu: Add virDomainDefineJSONFlags() support
virsh: Add JSON support to the 'define' subcommand
news: Update for virDomainDefineJSONFlags()
docs/news.xml | 11 +
include/libvirt/libvirt-domain.h | 3 +
include/libvirt/virterror.h | 1 +
src/conf/domain_conf.c | 241 ++++
src/conf/domain_conf.h | 5 +
src/driver-hypervisor.h | 6 +
src/libvirt-domain.c | 45 +
src/libvirt_private.syms | 1 +
src/libvirt_public.syms | 1 +
src/qemu/qemu_driver.c | 84 ++
src/remote/remote_driver.c | 3 +-
src/remote/remote_protocol.x | 19 +-
src/remote_protocol-structs | 8 +
src/rpc/gendispatch.pl | 1 +
src/util/virerror.c | 3 +
tests/Makefile.am | 15 +
tests/qemujson2argvdata/tiny.json | 29 +
.../qemujson2argvdata/tiny.x86_64-latest.args | 33 +
tests/qemujson2argvtest.c | 1001 +++++++++++++++++
tools/virsh-domain.c | 36 +-
20 files changed, 1540 insertions(+), 6 deletions(-)
create mode 100644 tests/qemujson2argvdata/tiny.json
create mode 100644 tests/qemujson2argvdata/tiny.x86_64-latest.args
create mode 100644 tests/qemujson2argvtest.c
--
2.20.1