forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rexray.go
136 lines (114 loc) · 2.75 KB
/
rexray.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package core
import (
log "github.com/Sirupsen/logrus"
"github.com/akutz/gofig"
"github.com/akutz/gotil"
)
// RexRay is the library's entrance type and storage management platform.
type RexRay struct {
Config gofig.Config
OS OSDriverManager
Volume VolumeDriverManager
Storage StorageDriverManager
drivers map[string]Driver
}
// New creates a new REX-Ray instance and configures it with the
// provided configuration instance.
func New(conf gofig.Config) *RexRay {
if conf == nil {
conf = gofig.New()
}
r := &RexRay{
Config: conf,
drivers: map[string]Driver{},
}
for name, ctor := range driverCtors {
r.drivers[name] = ctor()
log.WithField("driverName", name).Debug("constructed driver")
}
return r
}
// InitDrivers initializes the drivers for the REX-Ray platform.
func (r *RexRay) InitDrivers() error {
od := map[string]OSDriver{}
vd := map[string]VolumeDriver{}
sd := map[string]StorageDriver{}
log.Info(r.Config.Get("rexray.osDrivers"))
log.Info(r.Config.Get("rexray.volumeDrivers"))
log.Info(r.Config.Get("rexray.storageDrivers"))
osDrivers := r.Config.GetStringSlice("rexray.osDrivers")
volDrivers := r.Config.GetStringSlice("rexray.volumeDrivers")
storDrivers := r.Config.GetStringSlice("rexray.storageDrivers")
log.WithFields(log.Fields{
"osDrivers": osDrivers,
"volumeDrivers": volDrivers,
"storageDrivers": storDrivers,
}).Debug("core get drivers")
for n, d := range r.drivers {
switch td := d.(type) {
case OSDriver:
if gotil.StringInSlice(n, osDrivers) {
if err := d.Init(r); err != nil {
log.WithFields(log.Fields{
"driverName": n,
"error": err}).Debug("error initializing driver")
continue
}
od[n] = td
}
case VolumeDriver:
if gotil.StringInSlice(n, volDrivers) {
if err := d.Init(r); err != nil {
log.WithFields(log.Fields{
"driverName": n,
"error": err}).Debug("error initializing driver")
continue
}
vd[n] = td
}
case StorageDriver:
if gotil.StringInSlice(n, storDrivers) {
if err := d.Init(r); err != nil {
log.WithFields(log.Fields{
"driverName": n,
"error": err}).Debug("error initializing driver")
continue
}
sd[n] = td
}
}
}
r.OS = &odm{
rexray: r,
drivers: od,
}
r.Volume = &vdm{
rexray: r,
drivers: vd,
}
r.Storage = &sdm{
rexray: r,
drivers: sd,
}
if err := r.OS.Init(r); err != nil {
return err
}
if err := r.Volume.Init(r); err != nil {
return err
}
if err := r.Storage.Init(r); err != nil {
return err
}
return nil
}
// DriverNames returns a list of the registered driver names.
func (r *RexRay) DriverNames() <-chan string {
c := make(chan string)
go func() {
for n := range r.drivers {
c <- n
}
close(c)
}()
return c
}