rados: use test suite to share code

Signed-off-by: Noah Watkins <nwatkins@redhat.com>
This commit is contained in:
Noah Watkins 2018-07-28 14:57:10 -07:00
parent 0a30725b59
commit 6363bf77ae
2 changed files with 1101 additions and 1059 deletions

View File

@ -7,6 +7,7 @@ import "C"
import "unsafe"
import "bytes"
import "fmt"
// ClusterStat represents Ceph cluster statistics.
type ClusterStat struct {
@ -46,6 +47,7 @@ func (c *Conn) PingMonitor(id string) (string, error) {
func (c *Conn) Connect() error {
ret := C.rados_connect(c.cluster)
if ret == 0 {
c.connected = true
return nil
} else {
return RadosError(int(ret))
@ -54,6 +56,9 @@ func (c *Conn) Connect() error {
// Shutdown disconnects from the cluster.
func (c *Conn) Shutdown() {
if err := c.ensure_connected(); err != nil {
return
}
C.rados_shutdown(c.cluster)
}
@ -163,9 +168,20 @@ func (c *Conn) WaitForLatestOSDMap() error {
}
}
func (c *Conn) ensure_connected() error {
if c.connected {
return nil
} else {
return RadosError(1)
}
}
// GetClusterStat returns statistics about the cluster associated with the
// connection.
func (c *Conn) GetClusterStats() (stat ClusterStat, err error) {
if err := c.ensure_connected(); err != nil {
return ClusterStat{}, err
}
c_stat := C.struct_rados_cluster_stat_t{}
ret := C.rados_cluster_stat(c.cluster, &c_stat)
if ret < 0 {
@ -251,6 +267,10 @@ func (c *Conn) MakePool(name string) error {
// DeletePool deletes a pool and all the data inside the pool.
func (c *Conn) DeletePool(name string) error {
if err := c.ensure_connected(); err != nil {
fmt.Println("NOT CONNECTED WHOOPS")
return err
}
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
ret := int(C.rados_pool_delete(c.cluster, c_name))

File diff suppressed because it is too large Load Diff