
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1237338803 25200 # Node ID 4da70fdbb9a00f3fe874c3347f175efd973d8745 # Parent b092b78f4a892c6855f6851bb3ce18d873f80be9 (#2) Add basic support for creating network pools. Updates from 1 to 2: -Add function for free'ing the elements of the virt_pool struct Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r b092b78f4a89 -r 4da70fdbb9a0 libxkutil/Makefile.am --- a/libxkutil/Makefile.am Sun Mar 22 14:49:45 2009 -0700 +++ b/libxkutil/Makefile.am Tue Mar 17 18:13:23 2009 -0700 @@ -4,14 +4,15 @@ CFLAGS += $(CFLAGS_STRICT) -noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h +noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ + pool_parsing.h lib_LTLIBRARIES = libxkutil.la AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ - xmlgen.c infostore.c + xmlgen.c infostore.c pool_parsing.c noinst_PROGRAMS = xml_parse_test diff -r b092b78f4a89 -r 4da70fdbb9a0 libxkutil/pool_parsing.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/pool_parsing.c Tue Mar 17 18:13:23 2009 -0700 @@ -0,0 +1,95 @@ +/* + * Copyright IBM Corp. 2009 + * + * Authors: + * Kaitlin Rupert <karupert@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdbool.h> +#include <inttypes.h> +#include <sys/stat.h> +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> + +#include <libcmpiutil/libcmpiutil.h> + +#include "pool_parsing.h" +#include "../src/svpc_types.h" + +static void cleanup_net_pool(struct net_pool pool) { + free(pool.addr); + free(pool.netmask); + free(pool.ip_start); + free(pool.ip_end); + free(pool.forward_mode); + free(pool.forward_dev); +} + +void cleanup_virt_pool(struct virt_pool **pool) +{ + struct virt_pool *_pool = *pool; + + if ((pool == NULL) || (*pool == NULL)) + return; + + if (_pool->type == CIM_RES_TYPE_NET) + cleanup_net_pool(_pool->pool_info.net); + + free(_pool->id); + free(_pool); + + *pool = NULL; +} + +int define_pool(virConnectPtr conn, const char *xml, int res_type) +{ + int ret = 1; + + if (res_type == CIM_RES_TYPE_NET) { + virNetworkPtr ptr = virNetworkDefineXML(conn, xml); + if (ptr == NULL) { + CU_DEBUG("Unable to define virtual network"); + return 0; + } + + if (virNetworkCreate(ptr) != 0) { + CU_DEBUG("Unable to start virtual network"); + ret = 0; + + if (virNetworkUndefine(ptr) != 0) + CU_DEBUG("Unable to undefine virtual network"); + } + + virNetworkFree(ptr); + } + + return ret; +} + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ + diff -r b092b78f4a89 -r 4da70fdbb9a0 libxkutil/pool_parsing.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/pool_parsing.h Tue Mar 17 18:13:23 2009 -0700 @@ -0,0 +1,62 @@ +/* + * Copyright IBM Corp. 2009 + * + * Authors: + * Kaitlin Rupert <karupert@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __RES_POOLS_H_ +#define __RES_POOLS_H + +#include <stdint.h> +#include <stdbool.h> +#include <libvirt/libvirt.h> + +#include "../src/svpc_types.h" + +struct net_pool { + char *addr; + char *netmask; + char *ip_start; + char *ip_end; + char *forward_mode; + char *forward_dev; +}; + +struct virt_pool { + uint16_t type; + union { + struct net_pool net; + } pool_info; + char *id; +}; + +void cleanup_virt_pool(struct virt_pool **pool); + +int define_pool(virConnectPtr conn, const char *xml, int res_type); + + +#endif + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */