-
Notifications
You must be signed in to change notification settings - Fork 7
/
system_network_route.go
98 lines (81 loc) · 2.39 KB
/
system_network_route.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package fmgclient
import (
"fmt"
)
// JSONSysNetworkRoute contains the params for creating or updating network route
type JSONSysNetworkRoute struct {
Device string `json:"device"`
Dst string `json:"dst"`
Gateway string `json:"gateway"`
SeqNum string `json:"seq_num"`
}
// CreateUpdateSystemNetworkRoute is for creating or updating network route
// Input:
// @params: infor needed
// @method: operation method, "add" or "update"
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) CreateUpdateSystemNetworkRoute(params *JSONSysNetworkRoute, method string) (err error) {
defer c.Trace("CreateUpdateSystemNetworkRoute")()
p := map[string]interface{}{
"data": *params,
"url": "/cli/global/system/route",
}
_, err = c.Do(method, p)
if err != nil {
err = fmt.Errorf("CreateUpdateSystemNetworkRoute failed: %s", err)
return
}
return
}
// ReadSystemNetworkRoute is for reading the specific network route
// Input:
// @id: network route id
// Output:
// @out: network route infor
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) ReadSystemNetworkRoute(id string) (out *JSONSysNetworkRoute, err error) {
defer c.Trace("ReadSystemNetworkRoute")()
p := map[string]interface{}{
"url": "/cli/global/system/route/" + id,
}
result, err := c.Do("get", p)
if err != nil {
err = fmt.Errorf("ReadSystemNetworkRoute failed: %s", err)
return
}
data := (result["result"].([]interface{}))[0].(map[string]interface{})["data"].(map[string]interface{})
if data == nil {
err = fmt.Errorf("cannot get the results from the response")
return
}
out = &JSONSysNetworkRoute{}
if data["device"] != nil {
out.Device = data["device"].(string)
}
if data["gateway"] != nil {
out.Gateway = data["gateway"].(string)
}
if data["dst"] != nil {
ip := data["dst"].([]interface{})
out.Dst = ip[0].(string) + " " + ip[1].(string)
}
return
}
// DeleteSystemNetworkRoute is for deleting the specific network route
// Input:
// @id: network route id
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) DeleteSystemNetworkRoute(id string) (err error) {
defer c.Trace("DeleteSystemNetworkRoute")()
p := map[string]interface{}{
"url": "/cli/global/system/route/" + id,
}
_, err = c.Do("delete", p)
if err != nil {
err = fmt.Errorf("DeleteSystemNetworkRoute failed: %s", err)
return
}
return
}