-
Notifications
You must be signed in to change notification settings - Fork 907
/
driver_cephfs_utils.go
62 lines (51 loc) · 1.83 KB
/
driver_cephfs_utils.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package drivers
import (
"fmt"
"github.com/canonical/lxd/shared"
)
// fsExists checks that the Ceph FS instance indeed exists.
func (d *cephfs) fsExists(clusterName string, userName string, fsName string) (bool, error) {
_, err := shared.RunCommand("ceph", "--name", fmt.Sprintf("client.%s", userName), "--cluster", clusterName, "fs", "get", fsName)
if err != nil {
status, _ := shared.ExitStatus(err)
// If the error status code is 2, the fs definitely doesn't exist.
if status == 2 {
return false, nil
}
// Else, the error status is not 0 or 2,
// so we can't be sure if the fs exists or not
// as it might be a network issue, an internal ceph issue, etc.
return false, err
}
return true, nil
}
// osdPoolExists checks that the Ceph OSD Pool indeed exists.
func (d *cephfs) osdPoolExists(clusterName string, userName string, osdPoolName string) (bool, error) {
_, err := shared.RunCommand("ceph", "--name", fmt.Sprintf("client.%s", userName), "--cluster", clusterName, "osd", "pool", "get", osdPoolName, "size")
if err != nil {
status, _ := shared.ExitStatus(err)
// If the error status code is 2, the pool definitely doesn't exist.
if status == 2 {
return false, nil
}
// Else, the error status is not 0 or 2,
// so we can't be sure if the pool exists or not
// as it might be a network issue, an internal ceph issue, etc.
return false, err
}
return true, nil
}
// getConfig parses the Ceph configuration file and returns the list of monitors and secret key.
func (d *cephfs) getConfig(clusterName string, userName string) ([]string, string, error) {
// Get the monitor list.
monitors, err := CephMonitors(clusterName)
if err != nil {
return nil, "", err
}
// Get the keyring entry.
secret, err := CephKeyring(clusterName, userName)
if err != nil {
return nil, "", err
}
return monitors, secret, nil
}