1
2 """
3 Network module: aXAPI network configuration implementation.
4 Support the object-oriented interface for the network such as:
5 Interface
6 VirtualInterface
7 MgmtInterface
8 GatewayConfig
9 Trunk
10 VlanConfig
11 NetworkRoute
12 NetworkArp
13 NetworkDns
14
15
16 Author : Richard Zhang, A10 Networks (c)
17 email : rzhang@a10networks.com
18 Date : 03/08/2012
19 """
20
21 import method_call
22 from base import AxObject, AxAPIError
25 """
26 Implementation of the aXAPI network.interface.* method to
27 manage the interface configuration as getAll/get/set/ipv4.add/ipv4.delete/ipv6.add/ipv6.delete,
28 and interface global.set/global.get
29
30 Usage:
31 # interface with options:
32 # port_num (required) interface number
33 # type interface type, always be ‘ethernet’
34 # name interface name
35 # status interface status, disabled(0) or enabled(1)
36 # mac_addr interface MAC address
37 # duplexity interface duplexity setting, ‘auto’,’ half’ or ‘full’
38 # speed interface speed setting, ‘auto’, ‘10M’, ‘100M’ or ‘1G’
39 # flow_ctl flow control
40 # normal_rate ICMP normal rate, if this option is set, ICMP rate limit is enabled, if
41 # this option is not set, ICMP rate limit is disabled on this virtual port.
42 # lockup_rate ICMP lockup rate
43 # lockup_period ICMP lockup period
44 # ipv4_addr_list tag for the collection of interface IPv4 info list
45 # ipv4_addr IPv4 address of this interface
46 # ipv4_mask IPv4 mask
47 # ipv4_acl IPv4 access list
48 # ipv6_addr_list tag for the collection of interface IPv6 info list
49 # ipv6_addr interface IPv6 address
50 # ipv6_prefix_len interface IPv6 prefix length
51 # ipv6_is_any_cast_addr yes(1), no(0)
52 # ipv6_auto_link_local whether to link local address automatic or not
53 # ipv6_link_local_config tag for interfaces IPv6 link local configuration.
54 # ipv6_link_local_addr IPv6 link local address
55 # ipv6_link_local_prefix IPv6 link local prefix length
56 # ipv6_link_local_is_any_cast yes(1), no(0)
57 # ipv6_acl IPv6 access list
58 # allow_promiscuous_vip allow promiscuous VIP status, disabled(0) or enabled(1)
59 # tcp_sync_cookie TCP syn cookie status, disabled(0) or enabled(1)
60 # ha_status interface HA status, disabled(0) or enabled(1)
61 # ha_type none(0), router-interface(1), server-interface(2) or both(3)
62 # ha_heartbeat status when HA status enabled, disabled(0) or enabled(1)
63 # ha_vlan vlan id, only when interface HA status is enabled(1)
64
65 # Example:
66 """
67
68 __display__ = ["port_num", "status", "name"]
69 __obj_name__ = 'interface'
70 __xml_convrt__ = {"interface_list": "interface", "ipv4_addr_list": "ipv4", "ipv6_addr_list": "ipv6"}
71
72 @staticmethod
74 """ method : network.interface.getAll
75 Returns a list of interface configuration in Interface instance.
76 """
77 try:
78 res = method_call.call_api(Interface(), method = "network.interface.getAll", format = "url")
79 a_list = []
80 for item in res["interface_list"]:
81 a_list.append( Interface(**item) )
82 return a_list
83 except AxAPIError:
84 return None
85
86 @staticmethod
96
106
108 """ method: network.interface.ipv4.delete
109 Delete the IPv4 address, addr/mask for given interface.
110 """
111 try:
112 method_call.call_api(self, method = "network.interface.ipv4.delete", format = "url", port_num=self.port_num, ipv4_addr=addr, ipv4_mask=mask)
113 return 0
114 except AxAPIError, e:
115 return e.code
116
118 """ method: network.interface.ipv4.add
119 Add the IPv4 address, addr/mask for given interface.
120 """
121 try:
122 method_call.call_api(self, method = "network.interface.ipv4.add", format = "url", port_num=self.port_num, ipv4_addr=addr, ipv4_mask=mask)
123 return 0
124 except AxAPIError, e:
125 return e.code
126
128 """ method: network.interface.ipv6.delete
129 Delete the IPv6 address, v6_addr/v6_addr_prefix_len for given interface.
130 """
131 try:
132 method_call.call_api(self, method = "network.interface.ipv6.delete", format = "url", port_num=self.port_num, ipv6_addr=v6_addr, ipv6_prefix_len=v6_addr_prefix_len)
133 return 0
134 except AxAPIError, e:
135 return e.code
136
138 """ method: network.interface.ipv6.add
139 Add the IPv6 address, v6_addr/v6_addr_prefix_len for given interface.
140 """
141 try:
142 method_call.call_api(self, method = "network.interface.ipv6.add", format = "url", port_num=self.port_num, ipv6_addr=v6_addr, ipv6_prefix_len=v6_addr_prefix_len)
143 return 0
144 except AxAPIError, e:
145 return e.code
146
156
158 try:
159 if self.getObjectDict.has_key("ipv6_addr_list"):
160 addr_list = self.getObjectDict()["ipv6_addr_list"]
161 for addr in addr_list:
162 self.deleteIpv6Address(addr.ipv6_addr, addr.ipv6_prefix_len)
163 return 0
164 except AxAPIError, e:
165 return e.code
166
168 """
169 Implementation of the aXAPI network.ve.* method to
170 manage the virtual interface configuration as getAll/get/set/ipv4.add/ipv4.delete/ipv6.add/ipv6.delete.
171
172 Usage:
173 # ve with options:
174 # port_num (required) virtual interface number
175 # name virtual interface name
176 # status virtual interface status, disabled(0) or enabled(1)
177 # normal_rate icmp normal rate limit, if option is set, icmp rate limit is enabled,
178 # if option is not set, icmp rate limit is disabled on this virtual port.
179 # lookup_rate icmp lookup rate.
180 # lookup_period icmp lookup period.
181 # ipv4_addr_list tag of IPv4 address list.
182 # ipv4_addr IPv4 address
183 # ipv4_mask IPv4 mask
184 # ipv4_acl IPv4 access list
185 # ipv6_addr_list tag of IPv6 address list
186 # ipv6_addr IPv6 address
187 # ipv6_prefix_len IPv6 prefix length
188 # ipv6_is_any_cast_addr any cast status of address, enabled (1), disabled (0)
189 # ipv6_auto_link_local automatic link local status, enabled(1), disabled(0)
190 # ipv6_link_loal_cfg tag of manual IPv6 link local address.
191 # ipv6_link_local_addr IPv6 link local address
192 # ipv6_link_local_prefix_len the prefix length of this IPv6 address
193 # ipv6_link_local_is_any_cast any cast status of address. Enabled (1), disabled (0)
194 # ipv6_acl IPv6 access name
195 # allow_promiscuous_vip status, enabled (1), disabled (0)
196 # tcp_sync_cookie TCP sync cookie status, enabled (1), disabled (0)
197
198 # Example:
199 """
200
201 __display__ = ["port_num", "status", "name"]
202 __obj_name__ = 've'
203 __xml_convrt__ = {"ve_list": "ve", "ipv4_addr_list": "ipv4", "ipv6_addr_list": "ipv6_addr"}
204
205 @staticmethod
207 """ method : network.ve.getAll
208 Returns a list of ve configuration in VirtualInterface instance.
209 """
210 try:
211 res = method_call.call_api(VirtualInterface(), method = "network.ve.getAll", format = "url")
212 a_list = []
213 for item in res["ve_list"]:
214 a_list.append( VirtualInterface(**item) )
215 return a_list
216 except AxAPIError:
217 return None
218
219 @staticmethod
229
239
241 """ method: network.ve.ipv4.delete
242 Delete the IPv4 address, addr/mask for given interface.
243 """
244 try:
245 method_call.call_api(self, method = "network.ve.ipv4.delete", format = "url", port_num=self.port_num, ipv4_addr=addr, ipv4_mask=mask)
246 return 0
247 except AxAPIError, e:
248 return e.code
249
251 """ method: network.ve.ipv4.add
252 Add the IPv4 address, addr/mask for given interface.
253 """
254 try:
255 method_call.call_api(self, method = "network.ve.ipv4.add", format = "url", port_num=self.port_num, ipv4_addr=addr, ipv4_mask=mask)
256 return 0
257 except AxAPIError, e:
258 return e.code
259
261 """ method: network.interface.ipv6.delete
262 Delete the IPv6 address, v6_addr/v6_addr_prefix_len for given interface.
263 """
264 try:
265 method_call.call_api(self, method = "network.ve.ipv6.delete", format = "url", port_num=self.port_num, ipv6_addr=v6_addr, ipv6_prefix_len=v6_addr_prefix_len)
266 return 0
267 except AxAPIError, e:
268 return e.code
269
271 """ method: network.interface.ipv6.add
272 Add the IPv6 address, v6_addr/v6_addr_prefix_len for given interface.
273 """
274 try:
275 method_call.call_api(self, method = "network.ve.ipv6.add", format = "url", port_num=self.port_num, ipv6_addr=v6_addr, ipv6_prefix_len=v6_addr_prefix_len)
276 return 0
277 except AxAPIError, e:
278 return e.code
279
289
291 try:
292 if self.getObjectDict.has_key("ipv6_addr_list"):
293 addr_list = self.getObjectDict()["ipv6_addr_list"]
294 for addr in addr_list:
295 self.deleteIpv6Address(addr.ipv6_addr, addr.ipv6_prefix_len)
296 return 0
297 except AxAPIError, e:
298 return e.code
299