-
Notifications
You must be signed in to change notification settings - Fork 10
/
interfaces_vlan.go
201 lines (172 loc) · 4.93 KB
/
interfaces_vlan.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package ciscoasa
import "fmt"
// VlanInterfaceCollection represents a collection of vlan interfaces.
type VlanInterfaceCollection struct {
RangeInfo RangeInfo `json:"rangeInfo"`
Items []*VlanInterface `json:"items"`
Kind string `json:"kind"`
SelfLink string `json:"selfLink"`
}
// VlanInterface represents an vlan interface.
type VlanInterface struct {
HardwareID string `json:"hardwareID"`
InterfaceDesc string `json:"interfaceDesc"`
ForwardTrafficCX bool `json:"forwardTrafficCX"`
ForwardTrafficSFR bool `json:"forwardTrafficSFR"`
ActiveMacAddress string `json:"activeMacAddress"`
StandByMacAddress string `json:"standByMacAddress"`
ManagementOnly bool `json:"managementOnly"`
Mtu int `json:"mtu"`
Name string `json:"name"`
SecurityLevel int `json:"securityLevel"`
Shutdown bool `json:"shutdown"`
VlanID int `json:"vlanID"`
IPAddress *IPAddress `json:"ipAddress,omitempty"`
Ipv6Info *IPv6Info `json:"ipv6Info,omitempty"`
Kind string `json:"kind"`
ObjectID string `json:"objectId,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}
// ListVlanInterfaces returns a collection of interfaces.
func (s *interfaceService) ListVlanInterfaces() (*VlanInterfaceCollection, error) {
result := &VlanInterfaceCollection{}
page := 0
for {
offset := page * s.pageLimit
u := fmt.Sprintf("/api/interfaces/vlan?limit=%d&offset=%d", s.pageLimit, offset)
req, err := s.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
e := &VlanInterfaceCollection{}
_, err = s.do(req, e)
if err != nil {
return nil, err
}
result.RangeInfo = e.RangeInfo
result.Items = append(result.Items, e.Items...)
result.Kind = e.Kind
result.SelfLink = e.SelfLink
if e.RangeInfo.Offset+e.RangeInfo.Limit == e.RangeInfo.Total {
break
}
page++
}
return result, nil
}
// CreateVlanInterface creates a vlan interface.
func (s *interfaceService) CreateVlanInterface(
activeMacAddress string,
forwardTrafficCX bool,
forwardTrafficSFR bool,
hardwareID string,
interfaceDesc string,
ipAddress *IPAddress,
ipv6Info *IPv6Info,
kind string,
managementOnly bool,
mtu int,
name string,
securityLevel int,
shutdown bool,
standByMacAddress string,
vlanId int,
) (string, error) {
u := "/api/interfaces/vlan/"
r := &VlanInterface{
ActiveMacAddress: activeMacAddress,
ForwardTrafficCX: forwardTrafficCX,
ForwardTrafficSFR: forwardTrafficSFR,
HardwareID: hardwareID,
InterfaceDesc: interfaceDesc,
IPAddress: ipAddress,
Ipv6Info: ipv6Info,
Kind: kind,
ManagementOnly: managementOnly,
Mtu: mtu,
Name: name,
SecurityLevel: securityLevel,
Shutdown: shutdown,
StandByMacAddress: standByMacAddress,
VlanID: vlanId,
}
req, err := s.newRequest("POST", u, r)
if err != nil {
return "", err
}
resp, err := s.do(req, nil)
if err != nil {
return "", err
}
return idFromResponse(resp)
}
// UpdateVlanInterface updates a vlan interface.
func (s *interfaceService) UpdateVlanInterface(
activeMacAddress string,
forwardTrafficCX bool,
forwardTrafficSFR bool,
hardwareID string,
interfaceDesc string,
ipAddress *IPAddress,
ipv6Info *IPv6Info,
kind string,
managementOnly bool,
mtu int,
name string,
objectID string,
securityLevel int,
shutdown bool,
standByMacAddress string,
vlanId int,
) error {
u := fmt.Sprintf("/api/interfaces/vlan/%s", objectID)
r := &VlanInterface{
ActiveMacAddress: activeMacAddress,
ForwardTrafficCX: forwardTrafficCX,
ForwardTrafficSFR: forwardTrafficSFR,
HardwareID: hardwareID,
InterfaceDesc: interfaceDesc,
IPAddress: ipAddress,
Ipv6Info: ipv6Info,
Kind: kind,
ManagementOnly: managementOnly,
Mtu: mtu,
Name: name,
ObjectID: objectID,
SecurityLevel: securityLevel,
Shutdown: shutdown,
StandByMacAddress: standByMacAddress,
VlanID: vlanId,
}
req, err := s.newRequest("PUT", u, r)
if err != nil {
return err
}
resp, err := s.do(req, nil)
if err != nil {
return err
}
err = checkResponse(resp)
return err
}
// GetVlanInterface retrieves a vlan interface.
func (s *interfaceService) GetVlanInterface(objectID string) (*VlanInterface, error) {
u := fmt.Sprintf("/api/interfaces/vlan/%s", objectID)
req, err := s.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
r := &VlanInterface{}
_, err = s.do(req, r)
return r, err
}
// DeleteVlanInterface deletes a vlan interface.
func (s *interfaceService) DeleteVlanInterface(objectID string) error {
u := fmt.Sprintf("/api/interfaces/vlan/%s", objectID)
req, err := s.newRequest("DELETE", u, nil)
if err != nil {
return err
}
_, err = s.do(req, nil)
return err
}