Merge pull request #22 from travisn/patch-1

Add an overload for creating a connection to a non-default cluster name

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2015-06-18 06:50:52 -06:00
commit 037adbe79e
2 changed files with 23 additions and 0 deletions

View File

@ -52,3 +52,21 @@ func NewConnWithUser(user string) (*Conn, error) {
return nil, RadosError(int(ret)) return nil, RadosError(int(ret))
} }
} }
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
// It returns the connection and an error, if any.
func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, error) {
c_cluster_name := C.CString(clusterName)
defer C.free(unsafe.Pointer(c_cluster_name))
c_name := C.CString(userName)
defer C.free(unsafe.Pointer(c_name))
conn := &Conn{}
ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0)
if ret == 0 {
return conn, nil
} else {
return nil, RadosError(int(ret))
}
}

View File

@ -466,6 +466,11 @@ func TestNewConnWithUser(t *testing.T) {
assert.Equal(t, err, nil) assert.Equal(t, err, nil)
} }
func TestNewConnWithClusterAndUser(t *testing.T) {
_, err := rados.NewConnWithClusterAndUser("ceph", "client.admin")
assert.Equal(t, err, nil)
}
func TestReadWriteXattr(t *testing.T) { func TestReadWriteXattr(t *testing.T) {
conn, _ := rados.NewConn() conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile() conn.ReadDefaultConfigFile()