/
uplinkset.go
250 lines (197 loc) · 6.71 KB
/
uplinkset.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package oneview
import (
"fmt"
//"io/ioutil"
"log"
"os"
"sort"
//"strings"
"sync"
//"github.com/ghodss/yaml"
)
type UplinkSetCol struct {
Type string `json:"type"`
Members UplinkSetList `json:"members"`
Count int `json:"count"`
Total int `json:"total"`
NextPageURI string `json:"nextPageUri"`
Start int `json:"start"`
PrevPageURI string `json:"prevPageUri"`
Category string `json:"category"`
Modified string `json:"modified"`
ETag string `json:"eTag"`
Created string `json:"created"`
URI string `json:"uri"`
}
type UplinkSetList []UplinkSet
type UplinkSet struct {
Type string `json:"type"`
ConnectionMode string `json:"connectionMode"`
ManualLoginRedistributionState string `json:"manualLoginRedistributionState"`
NativeNetworkURI string `json:"nativeNetworkUri"`
FcoeNetworkUris []string `json:"fcoeNetworkUris"`
FcNetworkUris []string `json:"fcNetworkUris"`
PrimaryPortLocation string `json:"primaryPortLocation"`
LogicalInterconnectURI string `json:"logicalInterconnectUri"`
NetworkType string `json:"networkType"`
EthernetNetworkType string `json:"ethernetNetworkType"`
PortConfigInfos []PortConfigInfo `json:"portConfigInfos"`
Reachability string `json:"reachability"`
NetworkUris []string `json:"networkUris"`
LacpTimer string `json:"lacpTimer"`
Description string `json:"description"`
Status string `json:"status"`
Name string `json:"name"`
State string `json:"state"`
Category string `json:"category"`
Modified string `json:"modified"`
ETag string `json:"eTag"`
Created string `json:"created"`
URI string `json:"uri"`
LIName string //manually add to be get LI name from LogicalInterconnectURI
UplinkPorts UplinkPortList
Networks []NetworkSummary
}
type UplinkPortList []UplinkPort
type UplinkPort struct {
Enclosure string
Bay string
Port string
}
type PortConfigInfo struct {
DesiredSpeed string `json:"desiredSpeed"`
PortURI string `json:"portUri"`
ExpectedNeighbor ExpectedNeighbor `json:"expectedNeighbor"`
Location struct {
LocationEntries []struct {
Value string `json:"value"`
Type string `json:"type"`
} `json:"locationEntries"`
} `json:"location"`
}
type ExpectedNeighbor struct {
RemoteChassisID string `json:"remoteChassisId"`
RemotePortID string `json:"remotePortId"`
}
//GetUplinkSet is to retrive uplinkset information
func (c *CLIOVClient) GetUplinkSet() UplinkSetList {
var wg sync.WaitGroup
rl := []string{"UplinkSet", "LI"}
for _, v := range rl {
localv := v
wg.Add(1)
go func() {
defer wg.Done()
c.GetResourceLists(localv)
}()
}
wg.Wait()
l := *(rmap["UplinkSet"].listptr.(*UplinkSetList))
liList := *(rmap["LI"].listptr.(*[]LI))
liMap := make(map[string]LI)
for _, v := range liList {
liMap[v.URI] = v
}
for i, v := range l {
l[i].LIName = liMap[v.LogicalInterconnectURI].Name
}
sort.Slice(l, func(i, j int) bool { return l[i].Name < l[j].Name })
return l
}
//GetUplinkSet is to retrive uplinkset information
func (c *CLIOVClient) GetUplinkSetVerbose(name string) UplinkSetList {
var wg sync.WaitGroup
rl := []string{"UplinkSet", "LI", "Enclosure", "ENetwork"}
for _, v := range rl {
localv := v
wg.Add(1)
go func() {
defer wg.Done()
c.GetResourceLists(localv)
}()
}
wg.Wait()
l := *(rmap["UplinkSet"].listptr.(*UplinkSetList))
liList := *(rmap["LI"].listptr.(*[]LI))
encList := *(rmap["Enclosure"].listptr.(*[]Enclosure))
netList := *(rmap["ENetwork"].listptr.(*[]ENetwork))
log.Printf("[DEBUG] uslist length: %d\n", len(l))
log.Printf("[DEBUG] lilist length: %d\n", len(liList))
log.Printf("[DEBUG] enclist length: %d\n", len(encList))
log.Printf("[DEBUG] netlist length: %d\n", len(netList))
if err := validateName(&l, name); err != nil {
fmt.Println(err)
os.Exit(1)
}
l.genList(liList, netList, encList)
return l
}
func (usList UplinkSetList) genList(liList LIList, netList []ENetwork, encList EncList) {
for i := range usList {
(&usList[i]).getUplinkPort(encList)
(&usList[i]).getNetwork(netList)
(&usList[i]).getLI(liList)
}
}
func (us *UplinkSet) getNetwork(networkList []ENetwork) {
networkMap := make(map[string]ENetwork)
for _, v := range networkList {
networkMap[v.URI] = v
}
networklist := make([]NetworkSummary, 0)
for _, v := range us.NetworkUris {
vlanname := networkMap[v].Name
vlanid := networkMap[v].VlanId
vlantype := networkMap[v].EthernetNetworkType
//lig.UplinkSets[i].Networks = append(lig.UplinkSets[i].Networks, NetworkSummary{vlanname, vlanid})
networklist = append(networklist, NetworkSummary{vlanname, vlanid, vlantype})
}
sort.Slice(networklist, func(i, j int) bool { return networklist[i].Name < networklist[j].Name })
(*us).Networks = networklist
//sort.Slice(lig.UplinkSets[i].Networks, func(x, y int) bool { return lig.UplinkSets[i].Networks[x].Name < lig.UplinkSets[i].Networks[y].Name })
}
func (us *UplinkSet) getUplinkPort(encList EncList) {
encMap := make(map[string]Enclosure)
for _, v := range encList {
encMap[v.URI] = v
}
portlist := make(UplinkPortList, 0)
for _, v := range us.PortConfigInfos {
var e, b, p string
for _, v := range v.Location.LocationEntries {
switch v.Type {
case "Enclosure":
e = encMap[v.Value].Name
case "Bay":
b = v.Value
case "Port":
p = v.Value
}
}
portlist = append(portlist, UplinkPort{e, b, p})
sort.Slice(portlist, func(i, j int) bool { return portlist.multiSort(i, j) })
}
(*us).UplinkPorts = portlist
}
func (us *UplinkSet) getLI(liList LIList) {
liMap := make(map[string]LI)
for _, v := range liList {
liMap[v.URI] = v
}
(*us).LIName = liMap[us.LogicalInterconnectURI].Name
}
func (x UplinkPortList) multiSort(i, j int) bool {
switch {
case x[i].Enclosure < x[j].Enclosure:
return true
case x[i].Enclosure > x[j].Enclosure:
return false
case x[i].Bay < x[j].Bay:
return true
case x[i].Bay > x[j].Bay:
return false
case x[i].Port < x[j].Port:
return true
}
return false
}