// 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)) } }
// create the cluster handle with the ClusterName and UserName configured. func (conn *Connection) createClusterHandle() error { conn.cluster = new(Cluster) var ret C.int switch { // use rados_create2() since cluster and user are both specified case conn.ClusterName != "" && conn.UserName != "": cluster := C.CString(conn.ClusterName) user := C.CString(conn.UserName) defer freeString(cluster) defer freeString(user) ret = C.rados_create2(&conn.cluster.handle, cluster, user, 0) // use rados_create() with the given UserName case conn.ClusterName == "" && conn.UserName != "": user := C.CString(conn.UserName) defer freeString(user) ret = C.rados_create(&conn.cluster.handle, user) // use rados_create() with a nil user case conn.ClusterName == "" && conn.UserName == "": ret = C.rados_create(&conn.cluster.handle, nil) default: return &RadosError{ Code: -2, Message: "Unable to create cluster handle. If cluster name is specified, also include qualified user name.", } } if err := toRadosError(ret); err != nil { err.Message = "Unable to create cluster handle. Make sure you have access to the ceph cluster." return err } return nil }