-
Notifications
You must be signed in to change notification settings - Fork 907
/
load.go
91 lines (73 loc) · 2.49 KB
/
load.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package drivers
import (
"github.com/canonical/lxd/lxd/state"
"github.com/canonical/lxd/shared/logger"
)
var drivers = map[string]func() driver{
"btrfs": func() driver { return &btrfs{} },
"ceph": func() driver { return &ceph{} },
"cephfs": func() driver { return &cephfs{} },
"cephobject": func() driver { return &cephobject{} },
"dir": func() driver { return &dir{} },
"lvm": func() driver { return &lvm{} },
"powerflex": func() driver { return &powerflex{} },
"zfs": func() driver { return &zfs{} },
}
// Validators contains functions used for validating a drivers's config.
type Validators struct {
PoolRules func() map[string]func(string) error
VolumeRules func(vol Volume) map[string]func(string) error
}
// Load returns a Driver for an existing low-level storage pool.
func Load(state *state.State, driverName string, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonRules *Validators) (Driver, error) {
var driverFunc func() driver
// Locate the driver loader.
if state.OS.MockMode {
driverFunc = func() driver { return &mock{} }
} else {
df, ok := drivers[driverName]
if !ok {
return nil, ErrUnknownDriver
}
driverFunc = df
}
d := driverFunc()
d.init(state, name, config, logger, volIDFunc, commonRules)
err := d.load()
if err != nil {
return nil, err
}
return d, nil
}
// SupportedDrivers returns a list of supported storage drivers by loading each storage driver and running its
// compatibility inspection process. This can take a long time if a driver is not supported.
func SupportedDrivers(s *state.State) []Info {
supportedDrivers := make([]Info, 0, len(drivers))
for driverName := range drivers {
driver, err := Load(s, driverName, "", nil, nil, nil, nil)
if err != nil {
continue
}
supportedDrivers = append(supportedDrivers, driver.Info())
}
return supportedDrivers
}
// AllDriverNames returns a list of all storage driver names.
func AllDriverNames() []string {
driverNames := make([]string, 0, len(drivers))
for driverName := range drivers {
driverNames = append(driverNames, driverName)
}
return driverNames
}
// RemoteDriverNames returns a list of remote storage driver names.
func RemoteDriverNames() []string {
driverNames := make([]string, 0, len(drivers))
for driverName, driverFunc := range drivers {
if !driverFunc().isRemote() {
continue
}
driverNames = append(driverNames, driverName)
}
return driverNames
}