-
Notifications
You must be signed in to change notification settings - Fork 48
/
controller_bgp_max_as_limit_config.go
73 lines (63 loc) · 2.01 KB
/
controller_bgp_max_as_limit_config.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
package goaviatrix
import (
"context"
"fmt"
"strconv"
"strings"
)
func (c *Client) SetControllerBgpMaxAsLimit(ctx context.Context, maxAsLimit int) error {
data := map[string]string{
"action": "set_bgp_max_as_limit",
"CID": c.CID,
"max_as_limit": fmt.Sprint(maxAsLimit),
}
checkFunc := func(action, method, reason string, ret bool) error {
if !ret && !strings.Contains(reason, "Configured BGP maximum AS limit is not changed") {
return fmt.Errorf("rest API %s %s failed: %s", action, method, reason)
}
return nil
}
return c.PostAPIContext(ctx, data["action"], data, checkFunc)
}
func (c *Client) DisableControllerBgpMaxAsLimit(ctx context.Context) error {
data := map[string]string{
"action": "set_bgp_max_as_limit",
"CID": c.CID,
"max_as_limit": "",
}
checkFunc := func(action, method, reason string, ret bool) error {
if !ret && !strings.Contains(reason, "Configured BGP maximum AS limit is not changed") {
return fmt.Errorf("rest API %s %s failed: %s", action, method, reason)
}
return nil
}
return c.PostAPIContext(ctx, data["action"], data, checkFunc)
}
func (c *Client) GetControllerBgpMaxAsLimit(ctx context.Context) (int, error) {
data := map[string]string{
"action": "show_bgp_max_as_limit",
"CID": c.CID,
}
type BgpMaxAsLimitResults struct {
BgpMaxAsLimit string `json:"bgp_max_as_limit"`
}
type BgpMaxAsLimitResponse struct {
Results BgpMaxAsLimitResults
}
var resp BgpMaxAsLimitResponse
err := c.GetAPIContext(ctx, &resp, data["action"], data, BasicCheck)
if err != nil {
return 0, err
}
if resp.Results.BgpMaxAsLimit == "" {
return 0, ErrNotFound
}
maxAsLimit, err := strconv.Atoi(resp.Results.BgpMaxAsLimit)
if err != nil {
return 0, fmt.Errorf("error converting max_as_limit to int: %v", err)
}
if maxAsLimit < 1 || maxAsLimit > 254 {
return 0, fmt.Errorf("rest API show_bgp_max_as_limit returned invalid value for max_as_limit: %d. It must be an integer in the range of [1-254]", maxAsLimit)
}
return maxAsLimit, nil
}