Skip to content

Commit

Permalink
!44 enable BGP routing when legacy and TMOS mode.
Browse files Browse the repository at this point in the history
Merge pull request !44 from zongzw/zong-clear-legacy-bgp
  • Loading branch information
zongzw authored and gitee-org committed Dec 16, 2022
2 parents fe12db6 + 95cafb5 commit 4304536
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func setupBIGIPs() error {

bc := &f5_bigip.BIGIPContext{BIGIP: *bigip, Context: context.TODO()}
if c.Calico != nil {
if err := bc.ModifyDbValue("tmrouted.tmos.routing", "enable"); err != nil {
if err := pkg.EnableBGPRouting(bc); err != nil {
errs = append(errs, fmt.Sprintf("config #%d: %s", i, err.Error()))
continue
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/deployer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pkg

import (
"fmt"

f5_bigip "gitee.com/zongzw/f5-bigip-rest/bigip"
"gitee.com/zongzw/f5-bigip-rest/utils"
)
Expand Down Expand Up @@ -114,3 +116,34 @@ func Deployer(stopCh chan struct{}, bigips []*f5_bigip.BIGIP) {
}
}
}

func EnableBGPRouting(bc *f5_bigip.BIGIPContext) error {
kind := "net/route-domain"
partition, subfolder, name := "Common", "", "0" // route domain 0

exists, err := bc.Exist(kind, name, partition, subfolder)
if err != nil {
return err
}
if exists == nil {
return fmt.Errorf("route domain 0 must exist. check it")
}
// "Cannot mix routing-protocol Legacy and TMOS mode for route-domain (/Common/0)."
// We need to remove "BGP" from routingProtocol for TMOS mode
if (*exists)["routingProtocol"] != nil {
nrps := []interface{}{}
for _, rp := range (*exists)["routingProtocol"].([]interface{}) {
if rp.(string) != "BGP" {
nrps = append(nrps, rp)
}
}
body := map[string]interface{}{
"routingProtocol": nrps,
}
if err := bc.Update(kind, name, partition, subfolder, body); err != nil {
return err
}
}

return bc.ModifyDbValue("tmrouted.tmos.routing", "enable")
}

0 comments on commit 4304536

Please sign in to comment.