-
Notifications
You must be signed in to change notification settings - Fork 2
/
DriverInfoManager.go
134 lines (105 loc) · 3.19 KB
/
DriverInfoManager.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
// Cloud Driver Info. Manager of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2019.09.
package driverinfomanager
import (
"fmt"
"github.com/cloud-barista/cb-store/config"
"github.com/sirupsen/logrus"
)
var cblog *logrus.Logger
func init() {
cblog = config.Cblogger
}
//====================================================================
type CloudDriverInfo struct {
DriverName string // ex) "AWS-Test-Driver-V0.5"
ProviderName string // ex) "AWS"
DriverLibFileName string // ex) "aws-test-driver-v0.5.so" //Already, you need to insert "*.so" in $CB_SPIDER_ROOT/cloud-driver/libs.
}
//====================================================================
func RegisterCloudDriverInfo(cldInfo CloudDriverInfo) (*CloudDriverInfo, error) {
return RegisterCloudDriver(cldInfo.DriverName, cldInfo.ProviderName, cldInfo.DriverLibFileName)
}
// 1. check params
// 2. check driver files
// 3. insert them into cb-store
// You should copy the driver library into ~/libs before.
func RegisterCloudDriver(driverName string, providerName string, driverLibFileName string) (*CloudDriverInfo, error) {
cblog.Info("call RegisterCloudDriver()")
cblog.Debug("check params")
err := checkParams(driverName, providerName, driverLibFileName)
if err != nil {
return nil, err
}
cblog.Debug("check the driver library file")
err = checkDriverLibFile(driverLibFileName)
if err != nil {
return nil, err
}
cblog.Debug("insert metainfo into store")
err = insertInfo(driverName, providerName, driverLibFileName)
if err != nil {
cblog.Error(err)
return nil, err
}
drvInfo := &CloudDriverInfo{driverName, providerName, driverLibFileName}
return drvInfo, nil
}
func ListCloudDriver() ([]*CloudDriverInfo, error) {
cblog.Info("call ListCloudDriver()")
cloudDriverInfoList, err := listInfo()
if err != nil {
return nil, err
}
return cloudDriverInfoList, nil
}
// 1. check params
// 2. get DriverInfo from cb-store
func GetCloudDriver(driverName string) (*CloudDriverInfo, error) {
cblog.Info("call GetCloudDriver()")
if driverName == "" {
return nil, fmt.Errorf("DriverName is empty!")
}
drvInfo, err := getInfo(driverName)
if err != nil {
cblog.Error(err)
return nil, err
}
return drvInfo, err
}
func UnRegisterCloudDriver(driverName string) (bool, error) {
cblog.Info("call UnRegisterCloudDriver()")
if driverName == "" {
return false, fmt.Errorf("DriverName is empty!")
}
result, err := deleteInfo(driverName)
if err != nil {
cblog.Error(err)
return false, err
}
return result, nil
}
//----------------
func checkParams(driverName string, providerName string, driverLibFileName string) error {
if driverName == "" {
return fmt.Errorf("DriverName is empty!")
}
if providerName == "" {
return fmt.Errorf("ProviderName is empty!")
}
if driverLibFileName == "" {
return fmt.Errorf("DriverLibFileName is empty!")
}
return nil
}
// 1. check to exist file
// 2. check to be a shared library file
func checkDriverLibFile(driverLibFileName string) error {
// @todo
return nil
}