forked from walkamongus/go-bigip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.go
544 lines (457 loc) · 16.8 KB
/
net.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
package bigip
import (
"strings"
)
// Interfaces contains a list of every interface on the BIG-IP system.
type Interfaces struct {
Interfaces []Interface `json:"items"`
}
// Interface contains information about each individual interface.
type Interface struct {
Name string `json:"name,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Bundle string `json:"bundle,omitempty"`
Enabled bool `json:"enabled,omitempty"`
FlowControl string `json:"flowControl,omitempty"`
ForceGigabitFiber string `json:"forceGigabitFiber,omitempty"`
IfIndex int `json:"ifIndex,omitempty"`
LLDPAdmin string `json:"lldpAdmin,omitempty"`
LLDPTlvmap int `json:"lldpTlvmap,omitempty"`
MACAddress string `json:"macAddress,omitempty"`
MediaActive string `json:"mediaActive,omitempty"`
MediaFixed string `json:"mediaFixed,omitempty"`
MediaMax string `json:"mediaMax,omitempty"`
MediaSFP string `json:"mediaSfp,omitempty"`
MTU int `json:"mtu,omitempty"`
PreferPort string `json:"preferPort,omitempty"`
SFlow struct {
PollInterval int `json:"pollInterval,omitempty"`
PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"`
} `json:"sflow,omitempty"`
STP string `json:"stp,omitempty"`
STPAutoEdgePort string `json:"stpAutoEdgePort,omitempty"`
STPEdgePort string `json:"stpEdgePort,omitempty"`
STPLinkType string `json:"stpLinkType,omitempty"`
}
// SelfIPs contains a list of every self IP on the BIG-IP system.
type SelfIPs struct {
SelfIPs []SelfIP `json:"items"`
}
// SelfIP contains information about each individual self IP. You can use all of
// these fields when modifying a self IP.
type SelfIP struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Address string `json:"address,omitempty"`
Floating string `json:"floating,omitempty"`
InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty"`
TrafficGroup string `json:"trafficGroup,omitempty"`
Unit int `json:"unit,omitempty"`
Vlan string `json:"vlan,omitempty"`
// AllowService []string `json:"allowService"`
}
// Trunks contains a list of every trunk on the BIG-IP system.
type Trunks struct {
Trunks []Trunk `json:"items"`
}
// Trunk contains information about each individual trunk. You can use all of
// these fields when modifying a trunk.
type Trunk struct {
Name string `json:"name,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Bandwidth int `json:"bandwidth,omitempty"`
MemberCount int `json:"cfgMbrCount,omitempty"`
DistributionHash string `json:"distributionHash,omitempty"`
ID int `json:"id,omitempty"`
LACP string `json:"lacp,omitempty"`
LACPMode string `json:"lacpMode,omitempty"`
LACPTimeout string `json:"lacpTimeout,omitempty"`
LinkSelectPolicy string `json:"linkSelectPolicy,omitempty"`
MACAddress string `json:"macAddress,omitempty"`
STP string `json:"stp,omitempty"`
Type string `json:"type,omitempty"`
WorkingMemberCount int `json:"workingMbrCount,omitempty"`
Interfaces []string `json:"interfaces,omitempty"`
}
// Vlans contains a list of every VLAN on the BIG-IP system.
type Vlans struct {
Vlans []Vlan `json:"items"`
}
// Vlan contains information about each individual VLAN. You can use all of
// these fields when modifying a VLAN.
type Vlan struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
AutoLastHop string `json:"autoLastHop,omitempty"`
CMPHash string `json:"cmpHash,omitempty"`
DAGRoundRobin string `json:"dagRoundRobin,omitempty"`
Failsafe string `json:"failsafe,omitempty"`
FailsafeAction string `json:"failsafeAction,omitempty"`
FailsafeTimeout int `json:"failsafeTimeout,omitempty"`
IfIndex int `json:"ifIndex,omitempty"`
Learning string `json:"learning,omitempty"`
MTU int `json:"mtu,omitempty"`
SFlow struct {
PollInterval int `json:"pollInterval,omitempty"`
PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"`
SamplingRate int `json:"samplingRate,omitempty"`
SamplingRateGlobal string `json:"samplingRateGlobal,omitempty"`
} `json:"sflow,omitempty"`
SourceChecking string `json:"sourceChecking,omitempty"`
Tag int `json:"tag,omitempty"`
}
// VlanInterface contains fields to be used when adding an interface to a VLAN.
type VlanInterface struct {
Name string `json:"name,omitempty"`
Tagged bool `json:"tagged,omitempty"`
Untagged bool `json:"untagged,omitempty"`
}
// Routes contains a list of every route on the BIG-IP system.
type Routes struct {
Routes []Route `json:"items"`
}
// Route contains information about each individual route. You can use all
// of these fields when modifying a route.
type Route struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
MTU int `json:"mtu,omitempty"`
Network string `json:"network,omitempty"`
// Mutually exclusive fields
Blackhole bool `json:"blackhole,omitempty"`
Gateway string `json:"gw,omitempty"`
Pool string `json:"pool,omitempty"`
Interface string `json:"tmInterface,omitempty"`
}
// RouteDomains contains a list of every route domain on the BIG-IP system.
type RouteDomains struct {
RouteDomains []RouteDomain `json:"items"`
}
// RouteDomain contains information about each individual route domain. You can use all
// of these fields when modifying a route domain.
type RouteDomain struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
ID int `json:"id,omitempty"`
Strict string `json:"strict,omitempty"`
Vlans []string `json:"vlans,omitempty"`
}
// BGPInstances contains a list of every BGP instance on the BIG-IP system.
type BGPInstances struct {
BGPInstances []BGPInstance `json:"items"`
}
// BGPInstance contains information about each individual BGP instance. You can use all
// of these fields when modifying a BGP instance.
type BGPInstance struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
LocalAS int `json:"localAs,omitempty"`
}
// BGPNeighbors contains a list of BGP neighbors of a BGP instance on the BIG-IP system.
type BGPNeighbors struct {
BGPNeighbors []BGPNeighbor `json:"items"`
}
// BGPNeighbor contains information about each individual BGP neighbor. You can use all
// of these fields when modifying a BGP neighbor.
type BGPNeighbor struct {
Name string `json:"name,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
RemoteAS int `json:"remoteAs,omitempty"`
}
const (
uriNet = "net"
uriInterface = "interface"
uriSelf = "self"
uriTrunk = "trunk"
uriVlan = "vlan"
uriRoute = "route"
uriRouteDomain = "route-domain"
uriRouting = "routing"
uriBGP = "bgp"
uriNeighbor = "neighbor"
)
// Interfaces returns a list of interfaces.
func (b *BigIP) Interfaces() (*Interfaces, error) {
var interfaces Interfaces
err, _ := b.getForEntity(&interfaces, uriNet, uriInterface)
if err != nil {
return nil, err
}
return &interfaces, nil
}
// AddInterfaceToVlan associates the given interface to the specified VLAN.
func (b *BigIP) AddInterfaceToVlan(vlan, iface string, tagged bool) error {
config := &VlanInterface{}
config.Name = iface
if tagged {
config.Tagged = true
} else {
config.Untagged = true
}
return b.put(config, uriNet, uriVlan, vlan, "interfaces")
}
// SelfIPs returns a list of self IP's.
func (b *BigIP) SelfIPs() (*SelfIPs, error) {
var self SelfIPs
err, _ := b.getForEntity(&self, uriNet, uriSelf)
if err != nil {
return nil, err
}
return &self, nil
}
// CreateSelfIP adds a new self IP to the BIG-IP system. For <address>, you
// must include the subnet mask in CIDR notation, i.e.: "10.1.1.1/24".
func (b *BigIP) CreateSelfIP(name, address, vlan string) error {
config := &SelfIP{
Name: name,
Address: address,
Vlan: vlan,
}
return b.post(config, uriNet, uriSelf)
}
// DeleteSelfIP removes a self IP.
func (b *BigIP) DeleteSelfIP(name string) error {
return b.delete(uriNet, uriSelf, name)
}
// ModifySelfIP allows you to change any attribute of a self IP. Fields that
// can be modified are referenced in the SelfIP struct.
func (b *BigIP) ModifySelfIP(name string, config *SelfIP) error {
return b.put(config, uriNet, uriSelf, name)
}
// Trunks returns a list of trunks.
func (b *BigIP) Trunks() (*Trunks, error) {
var trunks Trunks
err, _ := b.getForEntity(&trunks, uriNet, uriTrunk)
if err != nil {
return nil, err
}
return &trunks, nil
}
// CreateTrunk adds a new trunk to the BIG-IP system. <interfaces> must be
// separated by a comma, i.e.: "1.4, 1.6, 1.8".
func (b *BigIP) CreateTrunk(name, interfaces string, lacp bool) error {
rawInts := strings.Split(interfaces, ",")
ints := []string{}
for _, i := range rawInts {
ints = append(ints, strings.Trim(i, " "))
}
config := &Trunk{
Name: name,
Interfaces: ints,
}
if lacp {
config.LACP = "enabled"
}
return b.post(config, uriNet, uriTrunk)
}
// DeleteTrunk removes a trunk.
func (b *BigIP) DeleteTrunk(name string) error {
return b.delete(uriNet, uriTrunk, name)
}
// ModifyTrunk allows you to change any attribute of a trunk. Fields that
// can be modified are referenced in the Trunk struct.
func (b *BigIP) ModifyTrunk(name string, config *Trunk) error {
return b.put(config, uriNet, uriTrunk, name)
}
// Vlans returns a list of vlans.
func (b *BigIP) Vlans() (*Vlans, error) {
var vlans Vlans
err, _ := b.getForEntity(&vlans, uriNet, uriVlan)
if err != nil {
return nil, err
}
return &vlans, nil
}
// CreateVlan adds a new VLAN to the BIG-IP system.
func (b *BigIP) CreateVlan(name string, tag int) error {
config := &Vlan{
Name: name,
Tag: tag,
}
return b.post(config, uriNet, uriVlan)
}
// DeleteVlan removes a vlan.
func (b *BigIP) DeleteVlan(name string) error {
return b.delete(uriNet, uriVlan, name)
}
// ModifyVlan allows you to change any attribute of a VLAN. Fields that
// can be modified are referenced in the Vlan struct.
func (b *BigIP) ModifyVlan(name string, config *Vlan) error {
return b.put(config, uriNet, uriVlan, name)
}
// Routes returns a list of routes.
func (b *BigIP) Routes() (*Routes, error) {
var routes Routes
err, _ := b.getForEntity(&routes, uriNet, uriRoute)
if err != nil {
return nil, err
}
return &routes, nil
}
// CreateRoute adds a new static route to the BIG-IP system. <dest> must include the
// subnet mask in CIDR notation, i.e.: "10.1.1.0/24".
func (b *BigIP) CreateRoute(name, dest, gateway string) error {
config := &Route{
Name: name,
Network: dest,
Gateway: gateway,
}
return b.post(config, uriNet, uriRoute)
}
// AddRoute adds a new static route to the BIG-IP system.
func (b *BigIP) AddRoute(config *Route) error {
return b.post(config, uriNet, uriRoute)
}
// GetRoute gets a static route.
func (b *BigIP) GetRoute(name string) (*Route, error) {
var route Route
err, _ := b.getForEntity(&route, uriNet, uriRoute, name)
if err != nil {
return nil, err
}
return &route, nil
}
// DeleteRoute removes a static route.
func (b *BigIP) DeleteRoute(name string) error {
return b.delete(uriNet, uriRoute, name)
}
// ModifyRoute allows you to change any attribute of a static route. Fields that
// can be modified are referenced in the Route struct.
func (b *BigIP) ModifyRoute(name string, config *Route) error {
return b.put(config, uriNet, uriRoute, name)
}
// RouteDomains returns a list of route domains.
func (b *BigIP) RouteDomains() (*RouteDomains, error) {
var rd RouteDomains
err, _ := b.getForEntity(&rd, uriNet, uriRouteDomain)
if err != nil {
return nil, err
}
return &rd, nil
}
// CreateRouteDomain adds a new route domain to the BIG-IP system. <vlans> must be separated
// by a comma, i.e.: "vlan1010, vlan1020".
func (b *BigIP) CreateRouteDomain(name string, id int, strict bool, vlans string) error {
strictIsolation := "enabled"
vlanMembers := []string{}
rawVlans := strings.Split(vlans, ",")
for _, v := range rawVlans {
vlanMembers = append(vlanMembers, strings.Trim(v, " "))
}
if !strict {
strictIsolation = "disabled"
}
config := &RouteDomain{
Name: name,
ID: id,
Strict: strictIsolation,
Vlans: vlanMembers,
}
return b.post(config, uriNet, uriRouteDomain)
}
// DeleteRouteDomain removes a route domain.
func (b *BigIP) DeleteRouteDomain(name string) error {
return b.delete(uriNet, uriRouteDomain, name)
}
// ModifyRouteDomain allows you to change any attribute of a route domain. Fields that
// can be modified are referenced in the RouteDomain struct.
func (b *BigIP) ModifyRouteDomain(name string, config *RouteDomain) error {
return b.put(config, uriNet, uriRouteDomain, name)
}
// BGPInstances returns a list of BGP instances.
func (b *BigIP) BGPInstances() (*BGPInstances, error) {
var bgpInstances BGPInstances
err, _ := b.getForEntity(&bgpInstances, uriNet, uriRouting, uriBGP)
if err != nil {
return nil, err
}
return &bgpInstances, nil
}
// CreateBGPInstance adds a new BGP instance to the BIG-IP system.
func (b *BigIP) CreateBGPInstance(name string, localAS int) error {
config := &BGPInstance{
Name: name,
LocalAS: localAS,
}
return b.post(config, uriNet, uriRouting, uriBGP)
}
// AddBGPInstance adds a new BGP instance to the BIG-IP system.
func (b *BigIP) AddBGPInstance(config *BGPInstance) error {
return b.post(config, uriNet, uriRouting, uriBGP)
}
// GetBGPInstance gets a BGP instance.
func (b *BigIP) GetBGPInstance(name string) (*BGPInstance, error) {
var bgpInstance BGPInstance
err, ok := b.getForEntity(&bgpInstance, uriNet, uriRouting, uriBGP, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpInstance, nil
}
// DeleteBGPInstance removes a BGP instance.
func (b *BigIP) DeleteBGPInstance(name string) error {
return b.delete(uriNet, uriRouting, uriBGP, name)
}
// ModifyBGPInstance allows you to change any attribute of a BGP instance. Fields that
// can be modified are referenced in the BGPInstance struct.
func (b *BigIP) ModifyBGPInstance(name string, config *BGPInstance) error {
return b.put(config, uriNet, uriRouting, uriBGP, name)
}
// BGPNeighbors returns a list of BGP neighbors of a BGP instance.
func (b *BigIP) BGPNeighbors(instance string) (*BGPNeighbors, error) {
var bgpNeighbors BGPNeighbors
err, _ := b.getForEntity(&bgpNeighbors, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
if err != nil {
return nil, err
}
return &bgpNeighbors, nil
}
// CreateBGPNeighbor adds a new BGP neigbhor to a BGP instance in the BIG-IP system.
func (b *BigIP) CreateBGPNeighbor(instance, name string, remoteAS int) error {
config := &BGPNeighbor{
Name: name,
RemoteAS: remoteAS,
}
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
}
// AddBGPNeighbor adds a new BGP neighbor to a BGP instance in the BIG-IP system.
func (b *BigIP) AddBGPNeighbor(instance string, config *BGPNeighbor) error {
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
}
// GetBGPNeighbor gets a BGP neighbor of a BGP instance.
func (b *BigIP) GetBGPNeighbor(instance, name string) (*BGPNeighbor, error) {
var bgpNeighbor BGPNeighbor
err, ok := b.getForEntity(&bgpNeighbor, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpNeighbor, nil
}
// DeleteBGPNeighbor removes a BGP neighbor from a BGP instance.
func (b *BigIP) DeleteBGPNeighbor(instance, name string) error {
return b.delete(uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
}
// ModifyBGPNeighbor allows you to change any attribute of a BGP neighbor of a BGP instance.
// Fields that can be modified are referenced in the BGPNeighbor struct.
func (b *BigIP) ModifyBGPNeighbor(instance, name string, config *BGPNeighbor) error {
return b.put(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
}