lib: add conn.ListPools

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2014-05-26 10:53:30 -07:00
parent 8ba5ad18e5
commit eb1efa6edb

29
conn.go
View File

@ -6,6 +6,7 @@ package rados
import "C" import "C"
import "unsafe" import "unsafe"
import "bytes"
type Conn struct { type Conn struct {
cluster C.rados_t cluster C.rados_t
@ -75,3 +76,31 @@ func (c *Conn) OpenPool(pool string) (*Pool, error) {
return nil, RadosError(int(ret)) return nil, RadosError(int(ret))
} }
} }
// ListPools returns the current list of pool names. It returns an error, if
// any.
func (c *Conn) ListPools() (names []string, err error) {
buf := make([]byte, 4096)
for {
ret := int(C.rados_pool_list(c.cluster,
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
if ret < 0 {
return nil, RadosError(int(ret))
}
if ret > len(buf) {
buf = make([]byte, ret)
continue
}
tmp := bytes.SplitAfter(buf[:ret-1], []byte{0})
for _, s := range tmp {
if len(s) > 0 {
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
names = append(names, name)
}
}
return names, nil
}
}