-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathltm.go
53 lines (47 loc) · 1.32 KB
/
ltm.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
package tmsh
import (
"fmt"
"strconv"
"strings"
)
func splitLtmOutput(str string) []string {
sep := "ltm"
strs := []string{}
for _, s := range strings.Split(str, sep) {
if s == "" {
continue
}
s = sep + s
strs = append(strs, s)
}
return strs
}
func (bigip *BigIP) RouteAdvertisementEnabled(targetVIP string) error {
cmd := "modify ltm virtual-address " + targetVIP + " route-advertisement enabled"
ret, _ := bigip.ExecuteCommand(cmd)
if ret != "" {
return fmt.Errorf(ret)
}
return nil
}
func (bigip *BigIP) CreateSecurityFWPolicy(firewallPolicyName string) error {
cmd := "create security firewall policy " + firewallPolicyName
ret, _ := bigip.ExecuteCommand(cmd)
if ret != "" {
return fmt.Errorf(ret)
}
return nil
}
func (bigip *BigIP) AddSecurityFWPolicyRule(firewallPolicyName, ruleName, action string, targetPort int) error {
if action != "accept" && action != "accept-decisively" &&
action != "drop" && action != "reject" {
return fmt.Errorf("Invalid action name: " + action)
}
cmd := "modify security firewall policy " + firewallPolicyName + " rules add { " + ruleName +
" { action " + action + " ip-protocol tcp destination { ports add { " + strconv.Itoa(targetPort) + " } } place-after last } }"
ret, _ := bigip.ExecuteCommand(cmd)
if ret != "" {
return fmt.Errorf(ret)
}
return nil
}