[PATCH 0 of 2] Add support for DeleteResourcePool()

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1238534753 25200 # Node ID 91ecd86e3c8799eb3b0cac91b9716c1fb6b782a9 # Parent 47050ea54020ae7dfd3ae0f936ef9bfea052d70c Add ability to delete a virtual network pools Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 47050ea54020 -r 91ecd86e3c87 libxkutil/pool_parsing.c --- a/libxkutil/pool_parsing.c Tue Mar 03 19:36:36 2009 -0300 +++ b/libxkutil/pool_parsing.c Tue Mar 31 14:25:53 2009 -0700 @@ -83,6 +83,38 @@ return ret; } +int destroy_pool(virConnectPtr conn, const char *name, int res_type) +{ + int ret = 0; + + if (res_type == CIM_RES_TYPE_NET) { + + virNetworkPtr ptr = virNetworkLookupByName(conn, name); + if (ptr == NULL) { + CU_DEBUG("Virtual network %s is not defined", name); + return ret; + } + + if (virNetworkDestroy(ptr) != 0) { + CU_DEBUG("Unable to destroy virtual network"); + goto err1; + } + + if (virNetworkUndefine(ptr) != 0) { + CU_DEBUG("Unable to undefine virtual network"); + goto err1; + } + + ret = 1; + + err1: + virNetworkFree(ptr); + } + + + return ret; +} + /* * Local Variables: * mode: C diff -r 47050ea54020 -r 91ecd86e3c87 libxkutil/pool_parsing.h --- a/libxkutil/pool_parsing.h Tue Mar 03 19:36:36 2009 -0300 +++ b/libxkutil/pool_parsing.h Tue Mar 31 14:25:53 2009 -0700 @@ -47,6 +47,7 @@ void cleanup_virt_pool(struct virt_pool **pool); int define_pool(virConnectPtr conn, const char *xml, int res_type); +int destroy_pool(virConnectPtr conn, const char *name, int res_type); #endif

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1238534753 25200 # Node ID 3dff43d9b55fdd8b684370a5e1de61640924d63e # Parent 91ecd86e3c8799eb3b0cac91b9716c1fb6b782a9 Add support for DeleteResourcePool() Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 91ecd86e3c87 -r 3dff43d9b55f src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Tue Mar 31 14:25:53 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Tue Mar 31 14:25:53 2009 -0700 @@ -323,6 +323,90 @@ return s; } +static CMPIStatus delete_pool(CMPIMethodMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + uint32_t rc = CIM_SVPC_RETURN_FAILED; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + CMPIObjectPath *pool = NULL; + virConnectPtr conn = NULL; + const char *poolid = NULL; + char *pool_name = NULL; + uint16_t type; + + CU_DEBUG("DeleteResourcePool"); + + if (cu_get_ref_arg(argsin, "Pool", &pool) != CMPI_RC_OK) { + CU_DEBUG("Failed to get Pool reference arg"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_INVALID_PARAMETER, + "Missing argument `Pool'"); + goto out; + } + + s = get_pool_by_ref(_BROKER, pool, &inst); + if (s.rc != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Resource pool instance does not exist"); + goto out; + } + + if (cu_get_str_path(pool, "InstanceID", &poolid) != CMPI_RC_OK) { + CU_DEBUG("Failed to get InstanceID from pool reference"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID in pool reference"); + goto out; + } + + pool_name = name_from_pool_id(poolid); + if (pool_name == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_INVALID_PARAMETER, + "Pool has invalid InstanceID"); + goto out; + } + + type = res_type_from_pool_classname(CLASSNAME(pool)); + if (type == CIM_RES_TYPE_UNKNOWN) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to determine resource type of pool"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to connect to hypervisor"); + goto out; + } + + if (destroy_pool(conn, pool_name, type) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to destroy resource pool"); + goto out; + } + + out: + free(pool_name); + virConnectClose(conn); + + if (s.rc == CMPI_RC_OK) + rc = CIM_SVPC_RETURN_COMPLETED; + CMReturnData(results, &rc, CMPI_uint32); + + return s; +} + static CMPIStatus dummy_handler(CMPIMethodMI *self, const CMPIContext *context, const CMPIResult *results, @@ -363,8 +447,10 @@ static struct method_handler DeleteResourcePool = { .name = "DeleteResourcePool", - .handler = dummy_handler, - .args = { ARG_END } + .handler = delete_pool, + .args = {{"Pool", CMPI_ref, false}, + ARG_END + } }; static struct method_handler *my_handlers[] = {

+1 Kaitlin Rupert wrote:
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel