# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1237338803 25200
# Node ID c9ad0f077d3882423b438340d3b557c398d4c582
# Parent 4da70fdbb9a00f3fe874c3347f175efd973d8745
(#3) Add logic to generate a pool XML to xmlgen.c
Updates from 2 to 3:
-Be sure to return an error message from net_pool_xml()
-Also fix the return bits of pool_to_xml() - don't print out the xml if the
xml variable is NULL.
Updates from 1 to 2:
-The pool ID should not be added as a property to the top level network tag.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 4da70fdbb9a0 -r c9ad0f077d38 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c Tue Mar 17 18:13:23 2009 -0700
+++ b/libxkutil/xmlgen.c Tue Mar 17 18:13:23 2009 -0700
@@ -38,6 +38,7 @@
#define XML_ERROR "Failed to allocate XML memory"
typedef const char *(*devfn_t)(xmlNodePtr node, struct domain *dominfo);
+typedef const char *(*poolfn_t)(xmlNodePtr node, struct virt_pool *pool);
static char *disk_block_xml(xmlNodePtr root, struct disk_device *dev)
{
@@ -770,6 +771,122 @@
return xml;
}
+static const char *net_pool_xml(xmlNodePtr root,
+ struct virt_pool *_pool)
+{
+ xmlNodePtr net = NULL;
+ xmlNodePtr ip = NULL;
+ xmlNodePtr forward = NULL;
+ xmlNodePtr dhcp = NULL;
+ xmlNodePtr range = NULL;
+ struct net_pool *pool = &_pool->pool_info.net;
+
+ net = xmlNewChild(root, NULL, BAD_CAST "network", NULL);
+ if (net == NULL)
+ goto out;
+
+ if (xmlNewChild(net, NULL, BAD_CAST "name", BAD_CAST _pool->id) ==
NULL)
+ goto out;
+
+ if (xmlNewChild(net, NULL, BAD_CAST "bridge", NULL) == NULL)
+ goto out;
+
+ if (pool->forward_mode != NULL) {
+ forward = xmlNewChild(net, NULL, BAD_CAST "forward", NULL);
+ if (forward == NULL)
+ goto out;
+
+ if (xmlNewProp(forward,
+ BAD_CAST "mode",
+ BAD_CAST pool->forward_mode) == NULL)
+ goto out;
+
+ if (pool->forward_dev != NULL) {
+ if (xmlNewProp(forward,
+ BAD_CAST "dev",
+ BAD_CAST pool->forward_dev) == NULL)
+ goto out;
+ }
+ }
+
+ ip = xmlNewChild(net, NULL, BAD_CAST "ip", NULL);
+ if (ip == NULL)
+ goto out;
+
+ if (xmlNewProp(ip, BAD_CAST "address", BAD_CAST pool->addr) ==
NULL)
+ goto out;
+
+ if (xmlNewProp(ip, BAD_CAST "netmask", BAD_CAST pool->netmask) ==
NULL)
+ goto out;
+
+ if ((pool->ip_start != NULL) && (pool->ip_end != NULL)) {
+ dhcp = xmlNewChild(ip, NULL, BAD_CAST "dhcp", NULL);
+ if (dhcp == NULL)
+ goto out;
+
+ range = xmlNewChild(dhcp, NULL, BAD_CAST "range", NULL);
+ if (range == NULL)
+ goto out;
+
+ if (xmlNewProp(range,
+ BAD_CAST "start",
+ BAD_CAST pool->ip_start) == NULL)
+ goto out;
+
+ if (xmlNewProp(range,
+ BAD_CAST "end",
+ BAD_CAST pool->ip_end) == NULL)
+ goto out;
+ }
+
+ return NULL;
+
+ out:
+ return XML_ERROR;
+}
+
+char *pool_to_xml(struct virt_pool *pool) {
+ char *xml = NULL;
+ xmlNodePtr root = NULL;
+ int type = pool->type;
+ const char *msg = NULL;
+ poolfn_t func;
+
+ root = xmlNewNode(NULL, BAD_CAST "tmp");
+ if (root == NULL) {
+ msg = XML_ERROR;
+ goto out;
+ }
+
+ switch (type) {
+ case CIM_RES_TYPE_NET:
+ func = net_pool_xml;
+ break;
+ default:
+ CU_DEBUG("pool_to_xml: invalid type specified: %d", type);
+ msg = "pool_to_xml: invalid type specified";
+ goto out;
+ }
+
+ msg = func(root, pool);
+ if (msg != NULL)
+ goto out;
+
+ xml = tree_to_xml(root->children);
+ if (xml == NULL)
+ msg = "XML generation failed";
+ out:
+ if (msg != NULL) {
+ CU_DEBUG("Failed to create pool XML: %s", msg);
+ } else {
+ CU_DEBUG("Created pool XML:\n%s\n", xml);
+ }
+
+ xmlFreeNode(root);
+
+ return xml;
+}
+
/*
* Local Variables:
* mode: C
diff -r 4da70fdbb9a0 -r c9ad0f077d38 libxkutil/xmlgen.h
--- a/libxkutil/xmlgen.h Tue Mar 17 18:13:23 2009 -0700
+++ b/libxkutil/xmlgen.h Tue Mar 17 18:13:23 2009 -0700
@@ -22,6 +22,7 @@
#define __XMLGEN_H
#include "device_parsing.h"
+#include "pool_parsing.h"
#include "cmpidt.h"
@@ -33,4 +34,6 @@
char *system_to_xml(struct domain *dominfo);
char *device_to_xml(struct virt_device *dev);
+char *pool_to_xml(struct virt_pool *pool);
+
#endif