forked from NetApp/netappdvp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ontap_common.go
70 lines (58 loc) · 2.2 KB
/
ontap_common.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
// Copyright 2016 NetApp, Inc. All Rights Reserved.
package storage_drivers
import (
"fmt"
"os"
"strconv"
"github.com/netapp/netappdvp/apis/ontap"
log "github.com/Sirupsen/logrus"
)
// InitializeOntapDriver will attempt to derive the SVM to use if not provided
func InitializeOntapDriver(config OntapStorageDriverConfig) (*ontap.Driver, error) {
api := ontap.NewDriver(ontap.DriverConfig{
ManagementLIF: config.ManagementLIF,
SVM: config.SVM,
Username: config.Username,
Password: config.Password,
})
if config.SVM != "" {
log.Debugf("Using specified SVM: %v", config.SVM)
return api, nil
}
// use VserverGetIterRequest to populate config.SVM if it wasn't specified and we can derive it
response1, err := api.VserverGetIterRequest()
if !isPassed(response1.Result.ResultStatusAttr) || err != nil {
return nil, fmt.Errorf("Error ennumerating SVMs: status: %v error: %v", response1.Result.ResultStatusAttr, err)
}
if response1.Result.NumRecords() != 1 {
return nil, fmt.Errorf("Cannot derive SVM to use, please specify SVM in config file.")
}
// update everything to use our derived svm
config.SVM = response1.Result.AttributesList()[0].VserverName()
api = ontap.NewDriver(ontap.DriverConfig{
ManagementLIF: config.ManagementLIF,
SVM: config.SVM,
Username: config.Username,
Password: config.Password,
})
log.Debugf("Using derived SVM: %v", config.SVM)
return api, nil
}
// EmsInitialized logs an ASUP message that this docker volume plugin has been initialized
// view them via filer::> event log show
func EmsInitialized(driverName string, api *ontap.Driver) {
// log an informational message when this plugin starts
myHostname, hostlookupErr := os.Hostname()
if hostlookupErr != nil {
log.Warnf("problem while looking up hostname, error: %v", hostlookupErr)
myHostname = "unknown"
}
_, emsErr := api.EmsAutosupportLog(strconv.Itoa(CurrentDriverVersion), false, "initialized", myHostname, driverName+" docker volume plugin initialized, version "+DriverVersion, 1, "netappdvp", 6)
if emsErr != nil {
log.Warnf("problem while logging ems message, error: %v", emsErr)
}
}
func isPassed(s string) bool {
const passed = "passed"
return s == passed
}