Skip to content

Commit 95cafb5

Browse files
committed
enable BGP routing when legacy and TMOS mode.
Cannot mix routing-protocol Legacy and TMOS mode for route-domain (/Common/0)
1 parent fe12db6 commit 95cafb5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func setupBIGIPs() error {
279279

280280
bc := &f5_bigip.BIGIPContext{BIGIP: *bigip, Context: context.TODO()}
281281
if c.Calico != nil {
282-
if err := bc.ModifyDbValue("tmrouted.tmos.routing", "enable"); err != nil {
282+
if err := pkg.EnableBGPRouting(bc); err != nil {
283283
errs = append(errs, fmt.Sprintf("config #%d: %s", i, err.Error()))
284284
continue
285285
}

pkg/deployer.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pkg
22

33
import (
4+
"fmt"
5+
46
f5_bigip "gitee.com/zongzw/f5-bigip-rest/bigip"
57
"gitee.com/zongzw/f5-bigip-rest/utils"
68
)
@@ -114,3 +116,34 @@ func Deployer(stopCh chan struct{}, bigips []*f5_bigip.BIGIP) {
114116
}
115117
}
116118
}
119+
120+
func EnableBGPRouting(bc *f5_bigip.BIGIPContext) error {
121+
kind := "net/route-domain"
122+
partition, subfolder, name := "Common", "", "0" // route domain 0
123+
124+
exists, err := bc.Exist(kind, name, partition, subfolder)
125+
if err != nil {
126+
return err
127+
}
128+
if exists == nil {
129+
return fmt.Errorf("route domain 0 must exist. check it")
130+
}
131+
// "Cannot mix routing-protocol Legacy and TMOS mode for route-domain (/Common/0)."
132+
// We need to remove "BGP" from routingProtocol for TMOS mode
133+
if (*exists)["routingProtocol"] != nil {
134+
nrps := []interface{}{}
135+
for _, rp := range (*exists)["routingProtocol"].([]interface{}) {
136+
if rp.(string) != "BGP" {
137+
nrps = append(nrps, rp)
138+
}
139+
}
140+
body := map[string]interface{}{
141+
"routingProtocol": nrps,
142+
}
143+
if err := bc.Update(kind, name, partition, subfolder, body); err != nil {
144+
return err
145+
}
146+
}
147+
148+
return bc.ModifyDbValue("tmrouted.tmos.routing", "enable")
149+
}

0 commit comments

Comments
 (0)