-
Notifications
You must be signed in to change notification settings - Fork 8
/
cephconnection.go
42 lines (34 loc) · 1.16 KB
/
cephconnection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/ceph/go-ceph/rados"
"log"
"os"
)
func connectioninit(params params) *cephconnection {
cephConn := &cephconnection{}
var err error
if _, err := os.Stat(params.config); os.IsNotExist(err) {
log.Fatalf("Congif file not exists. Error: %v\n", err)
}
if _, err := os.Stat(params.keyring); os.IsNotExist(err) {
log.Fatalf("Keyring file not exists. Error: %v\n", err)
}
cephConn.conn, err = rados.NewConnWithClusterAndUser(params.cluster, params.user)
if err != nil {
log.Fatalf("Can't create connection with cluster:%v and user:%v. Error: %v\n", params.cluster, params.user, err)
}
if err = cephConn.conn.ReadConfigFile(params.config); err != nil {
log.Fatalf("Can't read config file. Error: %v\n", err)
}
if err = cephConn.conn.SetConfigOption("keyring", params.keyring); err != nil {
log.Fatalf("Can't set config option. Error: %v\n", err)
}
if err = cephConn.conn.Connect(); err != nil {
log.Fatalf("Failed to connect cluster. Error: %v\n", err)
}
cephConn.ioctx, err = cephConn.conn.OpenIOContext(params.pool)
if err != nil {
log.Fatalf("Can't open pool %v. Error: %v\n", params.pool, err)
}
return cephConn
}