Example #1
0
func (h *Hypervisor) GetDefinedStoragePools() ([]string, error) {
	number := C.virConnectNumOfDefinedStoragePools(h.cptr)
	if number == -1 {
		return nil, GetLastError()
	}

	names := make([]string, number)

	if number == 0 {
		return names, nil
	}

	cnames := make([]*C.char, number)
	result := C.virConnectListDefinedStoragePools(h.cptr, &cnames[0], number)
	if result == -1 {
		return nil, GetLastError()
	}

	for i, v := range cnames {
		names[i] = C.GoString(v)
		defer C.free(unsafe.Pointer(v))
	}

	return names, nil
}
Example #2
0
func (c *VirConnection) ListDefinedStoragePools() ([]string, error) {
	const maxPools = 1024
	var names [maxPools](*C.char)
	namesPtr := unsafe.Pointer(&names)
	numStoragePools := C.virConnectListDefinedStoragePools(
		c.ptr,
		(**C.char)(namesPtr),
		maxPools)
	if numStoragePools == -1 {
		return nil, GetLastError()
	}
	goNames := make([]string, numStoragePools)
	for k := 0; k < int(numStoragePools); k++ {
		goNames[k] = C.GoString(names[k])
		C.free(unsafe.Pointer(names[k]))
	}
	return goNames, nil
}