diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2012-02-07 17:01:57 +0000 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2012-02-07 17:01:57 +0000 |
commit | 9faa8b12d80ffb9615bc07adc2249af60c0e32f8 (patch) | |
tree | 288e80d3464bd8e0a742f371162308d4707759f4 /tools/libxl/libxl_json.c | |
parent | 914e61c1ec5a7996a3e71692ce41e77359e70e0c (diff) | |
download | xen-9faa8b12d80ffb9615bc07adc2249af60c0e32f8.tar.gz xen-9faa8b12d80ffb9615bc07adc2249af60c0e32f8.tar.bz2 xen-9faa8b12d80ffb9615bc07adc2249af60c0e32f8.zip |
xl: use json output by default
Move the sxp producing code off into a separate file. It is supported
for legacy reasons and needn't be updated other than the improve
compatibility with xm.
libxl_domain_config is not currently generated by the IDL (adding the
necessary support for Array types is on my to do list) so hand code
the json generation function for now.
Since this rather directly exposes a libxl data structure it's not
clear what sort of forward compatibility guarantees we can
make. However it seems like it should be as stable as libxl's own API
(which we are looking to stabilise)
(Gratuitous string.h include needed for memset in libxl_util.h)
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_json.c')
-rw-r--r-- | tools/libxl/libxl_json.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c index d5e970d20f..54186838d3 100644 --- a/tools/libxl/libxl_json.c +++ b/tools/libxl/libxl_json.c @@ -843,6 +843,158 @@ out: return ret; } +yajl_gen_status libxl_domain_config_gen_json(yajl_gen hand, + libxl_domain_config *p) +{ + yajl_gen_status s; + int i; + + s = yajl_gen_map_open(hand); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"c_info", + sizeof("c_info")-1); + if (s != yajl_gen_status_ok) + goto out; + s = libxl_domain_create_info_gen_json(hand, &p->c_info); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"b_info", + sizeof("b_info")-1); + if (s != yajl_gen_status_ok) + goto out; + s = libxl_domain_build_info_gen_json(hand, &p->b_info); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"disks", + sizeof("disks")-1); + if (s != yajl_gen_status_ok) + goto out; + s = yajl_gen_array_open(hand); + if (s != yajl_gen_status_ok) + goto out; + for (i = 0; i < p->num_disks; i++) { + s = libxl_device_disk_gen_json(hand, &p->disks[i]); + if (s != yajl_gen_status_ok) + goto out; + } + s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"vifs", + sizeof("vifs")-1); + if (s != yajl_gen_status_ok) + goto out; + s = yajl_gen_array_open(hand); + if (s != yajl_gen_status_ok) + goto out; + for (i = 0; i < p->num_vifs; i++) { + s = libxl_device_nic_gen_json(hand, &p->vifs[i]); + if (s != yajl_gen_status_ok) + goto out; + } + s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"pcidevs", + sizeof("pcidevs")-1); + if (s != yajl_gen_status_ok) + goto out; + s = yajl_gen_array_open(hand); + if (s != yajl_gen_status_ok) + goto out; + for (i = 0; i < p->num_pcidevs; i++) { + s = libxl_device_pci_gen_json(hand, &p->pcidevs[i]); + if (s != yajl_gen_status_ok) + goto out; + } + s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"vfbs", + sizeof("vfbs")-1); + if (s != yajl_gen_status_ok) + goto out; + s = yajl_gen_array_open(hand); + if (s != yajl_gen_status_ok) + goto out; + for (i = 0; i < p->num_vfbs; i++) { + s = libxl_device_vfb_gen_json(hand, &p->vfbs[i]); + if (s != yajl_gen_status_ok) + goto out; + } + s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"vkbs", + sizeof("vkbs")-1); + if (s != yajl_gen_status_ok) + goto out; + s = yajl_gen_array_open(hand); + if (s != yajl_gen_status_ok) + goto out; + for (i = 0; i < p->num_vkbs; i++) { + s = libxl_device_vkb_gen_json(hand, &p->vkbs[i]); + if (s != yajl_gen_status_ok) + goto out; + } + s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"on_poweroff", + sizeof("on_poweroff")-1); + if (s != yajl_gen_status_ok) + goto out; + s = libxl_action_on_shutdown_gen_json(hand, &p->on_poweroff); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"on_reboot", + sizeof("on_reboot")-1); + if (s != yajl_gen_status_ok) + goto out; + s = libxl_action_on_shutdown_gen_json(hand, &p->on_reboot); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"on_watchdog", + sizeof("on_watchdog")-1); + if (s != yajl_gen_status_ok) + goto out; + s = libxl_action_on_shutdown_gen_json(hand, &p->on_watchdog); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_string(hand, (const unsigned char *)"on_crash", + sizeof("on_crash")-1); + if (s != yajl_gen_status_ok) + goto out; + s = libxl_action_on_shutdown_gen_json(hand, &p->on_crash); + if (s != yajl_gen_status_ok) + goto out; + + s = yajl_gen_map_close(hand); + if (s != yajl_gen_status_ok) + goto out; + out: + return s; +} + +char *libxl_domain_config_to_json(libxl_ctx *ctx, libxl_domain_config *p) +{ + return libxl__object_to_json(ctx, "libxl_domain_config", + (libxl__gen_json_callback)&libxl_domain_config_gen_json, + (void *)p); +} + /* * Local variables: * mode: C |