|
1 | 1 | package pkg |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
| 5 | + |
4 | 6 | f5_bigip "gitee.com/zongzw/f5-bigip-rest/bigip" |
5 | 7 | "gitee.com/zongzw/f5-bigip-rest/utils" |
6 | 8 | ) |
@@ -114,3 +116,34 @@ func Deployer(stopCh chan struct{}, bigips []*f5_bigip.BIGIP) { |
114 | 116 | } |
115 | 117 | } |
116 | 118 | } |
| 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