# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1199395746 28800
# Node ID 003644d3e86528251c0c84b52af6a92a81253682
# Parent 65a07575d2cfc4dfd3c1d57e0a0828c88dacf540
Add XML parsing tester for use when working on Xen PV and KVM support
This simply takes a domain argument, gets the XML from libvirt, parses
it in the same way the providers will, and prints the domain information
in a structured way. This can be used to test the previous patch, by
validating the FV-specific data items, such as emulator and the HVM loader
path.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 65a07575d2cf -r 003644d3e865 libxkutil/Makefile.am
--- a/libxkutil/Makefile.am Thu Jan 03 13:27:33 2008 -0800
+++ b/libxkutil/Makefile.am Thu Jan 03 13:29:06 2008 -0800
@@ -12,3 +12,9 @@ AM_LDFLAGS = -lvirt -luuid
libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \
xmlgen.c
+
+noinst_PROGRAMS = xml_parse_test
+
+xml_parse_test_SOURCES = xml_parse_test.c
+#xml_parse_test_HEADERS = device_parsing.h
+xml_parse_test_LDADD = -lvirt -lxkutil
diff -r 65a07575d2cf -r 003644d3e865 libxkutil/xml_parse_test.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libxkutil/xml_parse_test.c Thu Jan 03 13:29:06 2008 -0800
@@ -0,0 +1,172 @@
+#include <stdio.h>
+
+#include <libvirt/libvirt.h>
+
+#include "device_parsing.h"
+
+static void print_value(FILE *d, const char *name, const char *val)
+{
+ fprintf(d, "%-15s: %s\n", name, val);
+}
+
+static void print_u64(FILE *d, const char *name, uint64_t val)
+{
+ fprintf(d, "%-15s: %lu\n", name, val);
+}
+
+static void print_os(struct domain *dom,
+ FILE *d)
+{
+
+ if (dom->type == DOMAIN_XENPV) {
+ print_value(d, "Domain Type", "Xen PV");
+ print_value(d, "Type", dom->os_info.pv.type);
+ print_value(d, "Kernel", dom->os_info.pv.kernel);
+ print_value(d, "Ramdisk", dom->os_info.pv.initrd);
+ print_value(d, "Args", dom->os_info.pv.cmdline);
+ } else if (dom->type == DOMAIN_XENFV) {
+ print_value(d, "Domain Type", "Xen FV");
+ print_value(d, "Type", dom->os_info.fv.type);
+ print_value(d, "Loader", dom->os_info.fv.loader);
+ print_value(d, "Boot", dom->os_info.fv.boot);
+ } else {
+ fprintf(d, "[ Unknown domain type %i ]\n", dom->type);
+ }
+}
+
+static void print_dominfo(struct domain *dominfo,
+ FILE *d)
+{
+ print_value(d, "Name", dominfo->name);
+ print_value(d, "UUID", dominfo->uuid);
+ print_value(d, "Bootloader", dominfo->bootloader);
+ print_value(d, " args", dominfo->bootloader_args);
+
+ fprintf(d, "Actions: : P:%i R:%i C:%i\n",
+ dominfo->on_poweroff,
+ dominfo->on_reboot,
+ dominfo->on_crash);
+
+ print_os(dominfo, d);
+}
+
+static void print_dev_mem(struct virt_device *dev,
+ FILE *d)
+{
+ print_u64(d, "Memory", dev->dev.mem.size);
+ print_u64(d, "Maximum", dev->dev.mem.maxsize);
+}
+static void print_dev_net(struct virt_device *dev,
+ FILE *d)
+{
+ print_value(d, "Type", dev->dev.net.type);
+ print_value(d, "MAC", dev->dev.net.mac);
+}
+
+static void print_dev_disk(struct virt_device *dev,
+ FILE *d)
+{
+ print_value(d, "Type", dev->dev.disk.type);
+ print_value(d, "Device", dev->dev.disk.device);
+ print_value(d, "Driver", dev->dev.disk.driver);
+ print_value(d, "Source", dev->dev.disk.source);
+ print_value(d, "Virt Device", dev->dev.disk.virtual_dev);
+}
+
+static void print_dev_vcpu(struct virt_device *dev,
+ FILE *d)
+{
+ print_value(d, "Virtual CPU", "Present");
+}
+
+static void print_dev_emu(struct virt_device *dev,
+ FILE *d)
+{
+ print_value(d, "Emulator", dev->dev.emu.path);
+}
+
+static void print_dev_graphics(struct virt_device *dev,
+ FILE *d)
+{
+ print_value(d, "Graphics Type", dev->dev.graphics.type);
+ print_value(d, "Graphics Port", dev->dev.graphics.port);
+}
+
+static void print_devices(struct domain *dominfo,
+ FILE *d)
+{
+ int i;
+
+ fprintf(d, "\n-- Memory (%i) --\n", dominfo->dev_mem_ct);
+ for (i = 0; i < dominfo->dev_mem_ct; i++)
+ print_dev_mem(&dominfo->dev_mem[i], d);
+
+ fprintf(d, "\n-- Network (%i) --\n", dominfo->dev_net_ct);
+ for (i = 0; i < dominfo->dev_net_ct; i++)
+ print_dev_net(&dominfo->dev_net[i], d);
+
+ fprintf(d, "\n-- Disk (%i) --\n", dominfo->dev_disk_ct);
+ for (i = 0; i < dominfo->dev_disk_ct; i++)
+ print_dev_disk(&dominfo->dev_disk[i], d);
+
+ fprintf(d, "\n-- VCPU (%i) -- \n", dominfo->dev_vcpu_ct);
+ for (i = 0; i < dominfo->dev_vcpu_ct; i++)
+ print_dev_vcpu(&dominfo->dev_vcpu[i], d);
+
+ if (dominfo->type != DOMAIN_XENPV) {
+ fprintf(d, "\n-- Emulator --\n");
+ print_dev_emu(dominfo->dev_emu, d);
+ }
+
+ if (dominfo->dev_graphics) {
+ fprintf(d, "\n-- Graphics --\n");
+ print_dev_graphics(dominfo->dev_graphics, d);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ virConnectPtr conn;
+ virDomainPtr dom;
+ struct domain *dominfo;
+
+ if (argc != 2) {
+ printf("Usage: %s domain\n", argv[0]);
+ return 1;
+ }
+
+ conn = virConnectOpen("xen:///");
+ if (conn == NULL) {
+ printf("Unable to connect to libvirt\n");
+ return 2;
+ }
+
+ dom = virDomainLookupByName(conn, argv[1]);
+ if (dom == NULL) {
+ printf("Unable to lookup domain `%s'\n", argv[1]);
+ return 3;
+ }
+
+ if (get_dominfo(dom, &dominfo) == 0) {
+ printf("Failed to parse domain info\n");
+ return 4;
+ }
+
+ printf("Parsed domain info\n");
+
+ print_dominfo(dominfo, stdout);
+ print_devices(dominfo, stdout);
+
+ return 0;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */