# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1237338803 25200
# Node ID e5f7a88bf9aa81e71232d3ef86b7572d9461997c
# Parent 177ae29d2ae5c1f9fe37e8cffb000bfeb2dc28af
(#2) Add logic to generate a pool XML to xmlgen.c
Updates:
-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 177ae29d2ae5 -r e5f7a88bf9aa 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,114 @@
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;
+ const char *msg = 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;
+ }
+
+ out:
+ return msg;
+}
+
+char *pool_to_xml(struct virt_pool *pool) {
+ char *xml = NULL;
+ xmlNodePtr root = NULL;
+ int type = pool->type;
+ const char *msg;
+ poolfn_t func;
+
+ root = xmlNewNode(NULL, BAD_CAST "tmp");
+ if (root == NULL)
+ 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);
+ goto out;
+ }
+
+ msg = func(root, pool);
+ if (msg != NULL) {
+ CU_DEBUG("Failed to create pool XML: %s", msg);
+ goto out;
+ }
+
+ xml = tree_to_xml(root->children);
+ out:
+ CU_DEBUG("Created Device XML:\n%s\n", xml);
+
+ xmlFreeNode(root);
+
+ return xml;
+}
+
/*
* Local Variables:
* mode: C
diff -r 177ae29d2ae5 -r e5f7a88bf9aa 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