lib: add accessor for cluster fsid/instance_id

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2014-08-29 15:56:17 -07:00
parent 4ff181b2e5
commit 3103698734
2 changed files with 37 additions and 0 deletions

22
conn.go
View File

@ -198,3 +198,25 @@ func (c *Conn) ParseDefaultConfigEnv() error {
return RadosError(int(ret)) return RadosError(int(ret))
} }
} }
// GetFSID returns the fsid of the cluster as a hexadecimal string. The fsid
// is a unique identifier of an entire Ceph cluster.
func (c *Conn) GetFSID() (fsid string, err error) {
buf := make([]byte, 37)
ret := int(C.rados_cluster_fsid(c.cluster,
(*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
// FIXME: the success case isn't documented correctly in librados.h
if ret == 36 {
fsid = C.GoString((*C.char)(unsafe.Pointer(&buf[0])))
return fsid, nil
} else {
return "", RadosError(int(ret))
}
}
// GetInstanceID returns a globally unique identifier for the cluster
// connection instance.
func (c *Conn) GetInstanceID() uint64 {
// FIXME: are there any error cases for this?
return uint64(C.rados_get_instance_id(c.cluster))
}

View File

@ -75,9 +75,24 @@ func TestGetClusterStats(t *testing.T) {
assert.True(t, stat.Num_objects > 0) assert.True(t, stat.Num_objects > 0)
} }
func TestGetFSID(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
fsid, err := conn.GetFSID()
assert.NoError(t, err)
assert.NotEqual(t, fsid, "")
}
func TestGetInstanceID(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
id := conn.GetInstanceID()
assert.NotEqual(t, id, 0)
}