forked from hpe-storage/common-host-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.go
93 lines (84 loc) · 3.42 KB
/
volume.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
// Copyright 2020 Hewlett Packard Enterprise Development LP
package util
import (
"encoding/json"
"github.com/hpe-storage/common-host-libs/logger"
"github.com/hpe-storage/common-host-libs/model"
)
func GetVolumeObject(serialNumber, lunID string) *model.Volume {
logger.Tracef(">>>>> GetVolumeObject %s, %s", serialNumber, lunID)
defer logger.Tracef("<<<< GetVolumeObject")
var volObj *model.Volume
volObj = &model.Volume{}
volObj.SerialNumber = serialNumber
volObj.LunID = lunID
return volObj
}
func GetSecondaryArrayLUNIds(details string) []int32 {
logger.Tracef(">>>>> GetSecondaryArrayLUNIds %s", details)
defer logger.Tracef("<<<< GetSecondaryArrayLUNIds")
var secondaryArrayDetails model.SecondaryBackendDetails
logger.Tracef("\n About to unmarshal %s", details)
err := json.Unmarshal([]byte(details), &secondaryArrayDetails)
if err != nil {
logger.Errorf("\n Error in GetSecondaryArrayLUNIds %s", err.Error())
return []int32{}
}
numberOfSecondaryBackends := len(secondaryArrayDetails.PeerArrayDetails)
var secondaryLunIds []int32 = make([]int32, numberOfSecondaryBackends)
for i := 0; i < numberOfSecondaryBackends; i++ {
secondaryLunIds[i] = secondaryArrayDetails.PeerArrayDetails[i].LunID
}
return secondaryLunIds
}
func GetSecondaryArrayTargetNames(details string) []string {
logger.Tracef(">>>>> GetSecondaryArrayTargetNames %s", details)
defer logger.Tracef("<<<< GetSecondaryArrayTargetNames")
var secondaryArrayDetails model.SecondaryBackendDetails
logger.Tracef("\n About to unmarshal %s", details)
err := json.Unmarshal([]byte(details), &secondaryArrayDetails)
if err != nil {
logger.Errorf("\n Error in GetSecondaryArrayTargetNames %s", err.Error())
return []string{}
}
numberOfSecondaryBackends := len(secondaryArrayDetails.PeerArrayDetails)
var secondaryTargetNames []string
for i := 0; i < numberOfSecondaryBackends; i++ {
for _, targetNameRetrieved := range secondaryArrayDetails.PeerArrayDetails[i].TargetNames {
secondaryTargetNames = append(secondaryTargetNames, targetNameRetrieved)
}
}
return secondaryTargetNames
}
func GetSecondaryArrayDiscoveryIps(details string) []string {
logger.Tracef(">>>>> GetSecondaryArrayDiscoveryIps %s", details)
defer logger.Tracef("<<<< GetSecondaryArrayDiscoveryIps")
var secondaryArrayDetails model.SecondaryBackendDetails
logger.Tracef("\n About to unmarshal %s", details)
err := json.Unmarshal([]byte(details), &secondaryArrayDetails)
if err != nil {
logger.Errorf("\n Error in GetSecondaryArrayDiscoveryIps %s", err.Error())
return []string{}
}
numberOfSecondaryBackends := len(secondaryArrayDetails.PeerArrayDetails)
var secondaryDiscoverIps []string
for i := 0; i < numberOfSecondaryBackends; i++ {
for _, discoveryIpRetrieved := range secondaryArrayDetails.PeerArrayDetails[i].DiscoveryIPs {
secondaryDiscoverIps = append(secondaryDiscoverIps, discoveryIpRetrieved)
}
}
return secondaryDiscoverIps
}
func GetSecondaryBackends(details string) []*model.SecondaryLunInfo {
logger.Tracef(">>>>> GetSecondaryBackends %s", details)
defer logger.Tracef("<<<< GetSecondaryBackends")
var secondaryArrayDetails model.SecondaryBackendDetails
logger.Tracef("\n About to unmarshal %s", details)
err := json.Unmarshal([]byte(details), &secondaryArrayDetails)
if err != nil {
logger.Errorf("\n Error in GetSecondaryBackends %s", err.Error())
logger.Errorf("\n Passed details %s", details)
return nil
}
return secondaryArrayDetails.PeerArrayDetails
}