1
2 """
3 GSLB module: aXAPI GSLB configuration implementation.
4 Support the object-oriented interface for the GSLB such as:
5 GslbSite
6 GslbZone
7 GslbPolicy
8 GslbDnsProxy
9 GslbServiceIp
10 GslbSnmpTemplate
11 GslbGlobalSettings
12
13 Author : Richard Zhang, A10 Networks (c)
14 email : rzhang@a10networks.com
15 Date : 03/06/2012
16 """
17
18 import method_call
19 from base import AxObject, AxAPIError
22 """
23 Implementation of the aXAPI gslb.site.* method to
24 manage the GSLB site configuration as getAll/create/delete/update
25
26 Usage:
27 # Site with parameters:
28 # name (required) Site name
29 # weight weight
30 # template name of GSLB template
31 # status site status is enabled(1) or disabled(0)
32 # bandwidth_cost tag of bandwidth cost
33 # limit bandwidth limit of bandwidth cost
34 # threshold threshold of bandwidth cost
35 # active_rrt tag of active RRT
36 # aging_time aging time of active RRT
37 # bind_geoloc bind geographic of active RRT
38 # overlap overlap of active RRT
39 # limit limit of active RRT
40 # mask_len mask length of active RRT
41 # range_factor range factor of active RRT
42 # smooth_factor smooth factor of active RRT
43 # ip_server_list tag of IP server list
44 # name name of IP server
45 # ip_addr IP address of SLB device
46 # slb_device_list tag of SLB device list
47 # name SLB device name
48 # ip_addr IP address of SLB device
49 # admin_preference admin preference option
50 # max_client max num of clients
51 # gateway gateway
52 # vip_server_list tag of virtual server list
53 # name Name of virtual server
54
55 # Example:
56 # create a GSLB site configuration as:
57 !
58 gslb site site1
59 bw-cost limit 100 threshold 10
60 active-rtt mask /0
61 slb-dev ABC 2.4.6.9
62 admin-preference 10
63 slb-dev ABD 2.4.6.10
64 admin-preference 10
65 !
66 #
67 site1 = GslbSite(name="site1")
68 site1.weigth = 5
69 site1.status = AxAPI.STATUS_ENABLED
70 site1.bandwidth_cost["status"]= AxAPI.STATUS_ENABLED
71 site1.bandwidth_cost["limit"] = 100
72 site1.bandwidth_cost["threshold"] = 10
73 site1.active_rrt["aging_time"] = 10
74 site1.active_rrt["bind_geoloc"] = 0
75 site1.active_rrt["ignore_count"] = 5
76 site1.active_rrt["limit"] = 16383
77 site1.active_rrt["mask_len"] = 0
78 site1.slb_device_list = [{"name":"ABC", "ip_addr":"2.4.6.9", "admin_preference":10, "max_client":32768, "gateway":"0.0.0.0", "passive_rtt_timer":3, "protocol_aging_fast":1, "protocol_aging_time":0, "protocol_compatible":0}, {"name":"ABD", "ip_addr":"2.4.6.10", "admin_preference":10, "max_client":32768, "gateway":"0.0.0.0", "passive_rtt_timer":3, "protocol_aging_fast":1, "protocol_aging_time":0, "protocol_compatible":0}]
79 site1.create()
80 """
81
82 __display__ = ["name", "status"]
83 __obj_name__ = 'gslb_site'
84 __xml_convrt__ = {"gslb_site_list": "gslb_site", "ip_server_list": "ip_server", "slb_device_list": "slb_device", "vip_server_list": "vip_server"}
85
87 if not params.has_key("bandwidth_cost"):
88 params["bandwidth_cost"] = dict()
89 if not params.has_key("active_rrt"):
90 params["active_rrt"] = dict()
91 AxObject._set_properties(self, **params)
92
93 @staticmethod
95 """ method : gslb.site.getAll
96 Returns a list of GSLB sites in GslbSite instance.
97 """
98 try:
99 res = method_call.call_api(GslbSite(), method = "gslb.site.getAll", format = "json")
100 site_list = []
101 for item in res["gslb_site_list"]:
102 site_list.append( GslbSite(**item) )
103 return site_list
104 except AxAPIError:
105 return None
106
107 @staticmethod
117
127
129 """ method: gslb.site.delete
130 Delete the GSLB site.
131 """
132 try:
133 method_call.call_api(self, method = "gslb.site.delete", format = "json", name = self.name)
134 return 0
135 except AxAPIError, e:
136 return e.code
137
147
151 """
152 Implementation of the aXAPI gslb.zone.* method to
153 manage the GSLB zone configuration as getAll/create/delete/update
154
155 Usage:
156 # Zone with parameters:
157 # name (required) name of GSLB zone
158 # ttl TTL of GSLB zone
159 # policy policy of GSLB zone
160 # disable_all_services zone status is enabled(0) or disabled(1)
161 # dns_mx_record_list tag of DNS MX record list
162 # name name of DNS MX record
163 # priority priority of DNS MX record
164 # dns_ns_record_list tag of DNS NS record list
165 # name name of DNS DN record
166 # service_list tag of service list
167 # name name of service
168 # port port of service
169 # policy policy of service
170 # action action of service
171 # dns_address_record_list tag of DNS address record list
172 # as_replace as replace option of DNS address record
173 # no_response no replace option of DNS address record
174 # static static option of DNS address record
175 # weight weight option of DNS address record
176 # dns_mx_record_list tag of DNS MX record list
177 # name name of DNS MX record
178 # priority priority of DNS MX record
179 # dns_cname_record_list tag of DNS CName record list
180 # name name of DNS CName
181 # dns_ns_record_list tag of DNS NS record list
182 # name name of DNS NS record
183 # dns_ptr_record_list tag of DNS PTR record list
184 # name name of DNS PTR record
185
186 # Example:
187 # create a GSLB DNS proxy configuration as:
188 !
189 gslb zone CCC1
190 ttl 1
191 service 45 ffdfdd
192 service ftp ffffeeee
193 dns-a-record service2 as-replace
194 ip-order service1 service2
195 dns-mx-record ffff 12
196 dns-mx-record ffff1 12
197 !
198 # The services, service1 and service2, are required.
199 z = GslbZone(name="ccc1")
200 z.ttl = 1
201 z.policy = "default"
202 z.disable_all_services = 0
203 z.service_list = [{"name":"ffdfdd", "port":45, "policy":"default", "action":0}, {"name":"ffffeeee", "port":21, "policy":"default", "action":0, "dns_address_record_list":[{"vip_order":"service1", "as_replace":0, "no_response":0, "static":0, "weight":0 },{"vip_order":"service2","as_replace":0,"no_response":1,"static":1,"weight":0}], "dns_mx_record_list":[{"name":"ffff","priority":12},{"name":"ffff1","priority":12}]}]
204 z.create()
205 """
206
207 __display__ = ["name", "status"]
208 __obj_name__ = 'zone'
209 __xml_convrt__ = {"zone_list": "zone", "dns_mx_record_list": "dns_mx_record", "dns_ns_record_list": "dns_ns_record", "service_list": "service"}
210
211 @staticmethod
213 """ method : gslb.zone.getAll
214 Returns a list of GSLB zones in GslbZone instance.
215 """
216 try:
217 res = method_call.call_api(GslbZone(), method = "gslb.zone.getAll", format = "json")
218 zone_list = []
219 for item in res["zone_list"]:
220 zone_list.append( GslbZone(**item) )
221 return zone_list
222 except AxAPIError:
223 return None
224
225 @staticmethod
235
245
247 """ method: gslb.zone.delete
248 Delete the GSLB zone.
249 """
250 try:
251 method_call.call_api(self, method = "gslb.zone.delete", format = "json", name = self.name)
252 except AxAPIError, e:
253 return e.code
254
264
267 """
268 Implementation of the aXAPI gslb.dns_proxy.* method to
269 manage the GSLB DNS proxy configuration as getAll/create/delete/update
270
271 Usage:
272 # DNS proxy with parameters:
273 # name (required) GSLB DNS proxy name
274 # ip_address (required) IP address of the dns proxy
275 # status status, enabled(1) or disabled(0)
276 # ha_group HA group ID (1 - 31)
277 # ha_group_dynamic_weight Dynamic weight of the DNS proxy in the HA group
278 # vport_list Virtual port list of the GSLB DNS proxy
279 # port_number Virtual port number (1 - 65535)
280 # service_group service group(name) of this virtual port
281 # status enabled(1) or disabled(0)
282 # connection_limit connection limit (1 - 8000000)
283 # over_connection_limit_action over connection limit action, drop(0), reset (1)
284 # source_nat_pool source NAT pool name
285 # aflex aFlex(name) of this virtual port
286 # udp_template UDP template (name) of this virtual port
287
288 # Example:
289 # create a GSLB DNS proxy configuration as:
290 !
291 slb virtual-server my_dns_proxy 22.2.2.1
292 stats-data-disable
293 port 55 udp
294 name _22.2.2.1_UDP_55
295 disable
296 gslb-enable
297 service-group http
298 no def-selection-if-pref-failed
299 stats-data-disable
300 port 80 udp
301 name _22.2.2.1_UDP_80
302 gslb-enable
303 service-group http
304 no def-selection-if-pref-failed
305 stats-data-disable
306 !
307 # Above service group 'http' has been created before
308 dns_proxy = GslbDnsProxy(name="my_dns_proxy", ip_address="22.2.2.1")
309 dns_proxy.vport_list = [{"port_number": 55, "service_group": "http", "status": AxAPI.STATUS_DISABLED}, {"port_number": 80, "service_group": "http", "status": AxAPI.STATUS_ENABLED}]
310 dns_proxy.create()
311
312 # retrieve all GSLB DNS proxy configuration:
313 d_proxies = GslbDnsProxy.getAll()
314 for e in d_proxies:
315 print e
316 e.dump()
317
318 """
319
320 __display__ = ["name", "ip_address", "status"]
321 __obj_name__ = 'gslb_vserver'
322 __xml_convrt__ = {"gslb_vserver_list": "gslb_vserver", "vport_list": "vport"}
323
324 @staticmethod
326 """ method : gslb.dns_proxy.getAll
327 Returns a list of GSLB DNS-proxy in GslbDnsProxy instance.
328 """
329 try:
330 res = method_call.call_api(GslbDnsProxy(), method = "gslb.dns_proxy.getAll", format = "json")
331 dns_proxy_list = []
332 for item in res["gslb_vserver_list"]:
333 dns_proxy_list.append( GslbDnsProxy(**item) )
334 return dns_proxy_list
335 except AxAPIError:
336 return None
337
338 @staticmethod
348
350 """ method: gslb.dns_proxy.create
351 Create the GSLB DNS proxy.
352 """
353 try:
354 method_call.call_api(self, method = "gslb.dns_proxy.create", format = "json", post_data = self.getRequestPostDataJson())
355 return 0
356 except AxAPIError, e:
357 return e.code
358
360 """ method: gslb.dns_proxy.delete
361 Delete the GSLB DNS proxy.
362 """
363 try:
364 method_call.call_api(self, method = "gslb.dns_proxy.delete", format = "json", name = self.name)
365 return 0
366 except AxAPIError, e:
367 return e.code
368
370 """ method: gslb.dns_proxy.update
371 Update the GSLB DNS proxy.
372 """
373 try:
374 method_call.call_api(self, method = "gslb.dns_proxy.update", format = "json", post_data = self.getRequestPostDataJson())
375 return 0
376 except AxAPIError, e:
377 return e.code
378
381 """
382 Implementation of the aXAPI gslb.policy.* method to
383 manage the GSLB policy configuration as getAll/create/delete/update
384
385 Usage:
386 # DNS proxy with parameters:
387 # name (required) GSLB DNS proxy name
388 # name GSLB policy name
389 # metric tag for the metric list
390 # session_capacity tag for session capacity
391 # enabled the status of session capacity
392 # threshold threshold of session capacity
393 # active_rrt
394 # enabled the status of active RRT
395 # samples the number of samples
396 # difference difference
397 # tolerance tolerance
398 # time_out time out
399 # skip skip
400 # single_shot single shot
401 # connection_load
402 # enabled the status of connection load
403 # limit connection limit
404 # samples_num sample number
405 # samples_interval sample interval
406 # num_session number session
407 # enabled status of number session
408 # tolerance tolerance
409 # geo_graphic tag of geographic
410 # enabled status of geographic option
411 # ordered_ip tag if ordered IP option
412 # enabled status of ordered IP option
413 # weighted_site tag of weighted site option
414 # enabled status of weighted site option
415 # active_servers tag of active servers
416 # enabled status of active servers
417 # weighted_ip tag of weighted IP option
418 # enabled status of weighted IP option
419 # bandwidth_cost tag of bandwidth option
420 # enabled status of bandwidth
421 # health_check tag of health check option
422 # enabled status of health check option
423 # admin_perference tag of administrator preference
424 # enabled status of administrator preference option
425 # least_response tag of least connection option
426 # enabled status of least response option
427 # round_robin tag of round robin option
428 # enabled status of round robin
429 # dns_options tag of DNS options
430 # action action
431 # active_only action only
432 # best_only best only
433 # dns_cache tag of DNS cache
434 # enabled status of DNS cache
435 # dns_cache_aging_time DNS cache aging time
436 # cname_detect CName detected
437 # external_ip external IP
438 # ip_replace IP replace
439 # geo_location_alias geographic location alias
440 # geo_location_action geographic location action
441 # geo_location_policy geographic location policy
442 # mx_additional MX additional
443 # server_mode tag of server mode
444 # enabled status of server mode
445 # authoritative_mode authoritative mode
446 # full_server_list full server list
447 # server_mx server MX record
448 # server_mx_additional server MX additional record
449 # server_ns server NS record
450 # server_auto_ns server auto NS
451 # server_ptr server PTR
452 # server_auto_ptr server auto PTR
453 # sticky tag of sticky
454 # enabled status of sticky
455 # sticky_dns_client_ip_mask_len sticky DNS client IP mask length
456 # ttl tag of TTL
457 # enabled status of TTL
458 # ttl_time_live TTL time live
459 # geo_location tag of geographic location
460 # geo_location_match_first geographic location match first
461 # geo_location_overlap geographic location overlap
462
463 # Example:
464 # create a GSLB policy configuration as:
465 !
466 gslb policy policy01
467 dns action
468 dns ttl 0
469 capacity threshold 80
470 num-session tolerance 0
471 active-rtt tolerance 20
472 active-rtt difference 5
473 active-rtt samples 8
474 active-rtt timeout 2
475 active-rtt skip 5
476 metric-order health-check geographic weighted-ip active-servers weighted-site capacity active-rtt num-session connection-load admin-preference bw-cost least-response ordered-ip
477 !
478 #
479 policy1 = GslbPolicy(name="policy01")
480 policy1.metric["session_capacity"] = {"enabled": 0, "threshold": 80}
481 policy1.metric["active_rrt"] = {"enabled": 0, "samples": 8, "difference": 5, "tolerance": 20, "timeout": 2, "skip": 5, "single_short": 1}
482 policy1.metric["connection_load"] = {"enabled": 0, "limit": 0, "samples_num": 5, "samples_interval": 5}
483 policy1.metric["num_sessions"] = {"enabled": 0, "tolerance": 0}
484 policy1.metric["geo_graphic"] = {"enabled": 1}
485 policy1.metric["orderid_ip"] = {"enabled": 0}
486 policy1.metric["weighted_site"] = {"enabled": 0}
487 policy1.dns_options["dns_cache"] = {"enabled": 1}
488 policy1.dns_options["action"] = 1
489 policy1.dns_options["active_only"] = 0
490 policy1.dns_options["best_only"] = 0
491 policy1.dns_options["dns_cache"] = {"enabled": 0, "dns_cache_aging_time": 0}
492 policy1.dns_options["cname_detect"] = 1
493 policy1.dns_options["external_ip"] = 1
494 policy1.dns_options["ip_replace"] = 0
495 policy1.dns_options["geo_location_alias"] = 0
496 policy1.dns_options["geo_location_action"] = 0
497 policy1.dns_options["geo_location_policy"] = 0
498 policy1.dns_options["mx_additional"] = 0
499 policy1.dns_options["server_mode"] = {"enabled":0, "authoritative_mode":0}
500 policy1.dns_options["ttl"] = {"enabled":1, "ttl_time_live":0}
501 policy1.create()
502 """
503
504 __display__ = ["name"]
505 __obj_name__ = 'policy'
506 __xml_convrt__ = {"policy_list": "policy"}
507
509 if not params.has_key("metric"):
510 params["metric"] = dict()
511 if not params.has_key("dns_options"):
512 params["dns_options"] = dict()
513 if not params.has_key("geo_location"):
514 params["geo_location"] = dict()
515 AxObject._set_properties(self, **params)
516
517 @staticmethod
519 """ method : gslb.policy.getAll
520 Returns a list of GSLB policy in GslbPolicy instance.
521 """
522 try:
523 res = method_call.call_api(GslbPolicy(), method = "gslb.policy.getAll", format = "json")
524 policy_list = []
525 for item in res["policy_list"]:
526 policy_list.append( GslbPolicy(**item) )
527 return policy_list
528 except AxAPIError:
529 return None
530
531 @staticmethod
541
543 """ method: gslb.policy.create
544 Create the GSLB policy.
545 """
546 try:
547 method_call.call_api(self, method = "gslb.policy.create", format = "json", post_data = self.getRequestPostDataJson())
548 return 0
549 except AxAPIError, e:
550 return e.code
551
553 """ method: gslb.policy.delete
554 Delete the GSLB policy.
555 """
556 try:
557 method_call.call_api(self, method = "gslb.policy.delete", format = "json", name = self.name)
558 return 0
559 except AxAPIError, e:
560 return e.code
561
563 """ method: gslb.policy.update
564 Update the GSLB policy.
565 """
566 try:
567 method_call.call_api(self, method = "gslb.policy.update", format = "json", post_data = self.getRequestPostDataJson())
568 return 0
569 except AxAPIError, e:
570 return e.code
571
573 """
574 Implementation of the aXAPI gslb.service_ip.* method to
575 manage the GSLB service IP configuration as getAll/create/delete/update
576
577 Usage:
578 # GSLB Service IP with parameters:
579 # name (required) name of service IP
580 # ip_address (required) ip address of service IP
581 # external_ip_address external IP address of service IP
582 # health_monitor health monitor of service IP
583 # status status of service IP
584 # port_list tag of port list
585 # port_num port number of port
586 # protocol protocol of port
587 # health_monitor health monitor of port
588 # status status of port
589
590 # Example:
591 # create a GSLB service IP configuration as:
592 !
593 gslb service-ip service6 1.6.61.41
594 external-ip 123.123.123.15
595 health-check ping
596 port 8888 tcp
597 port 8787 tcp
598 health-check ping
599 port 8789 tcp
600 health-check ping
601 !
602 #
603 svc_ip = GslbServiceIP(name="service6", ip_address="1.6.61.41")
604 svc_ip.external_ip_address = "123.123.123.15"
605 svc_ip.health_monitor = "ping"
606 svc_ip.port_list = [{"port_num": 8888, "protocol": AxAPI.PROTO_TCP, "health_monitor": "ping", "status": AxAPI.STATUS_ENABLED}, {"port_num": 8789, "protocol": AxAPI.PROTO_TCP, "health_monitor": "ping", "status": AxAPI.STATUS_ENABLED}]
607 svc_ip.create()
608 """
609
610 __display__ = ["name"]
611 __obj_name__ = 'service_ip'
612 __xml_convrt__ = {"service_ip_list": "service_ip", "port_list": "port"}
613
614 @staticmethod
616 """ method : gslb.service_ip.getAll
617 Returns a list of GSLB service_ip in GslbServiceIP instance.
618 """
619 try:
620 res = method_call.call_api(GslbServiceIP(), method = "gslb.service_ip.getAll", format = "json")
621 policy_list = []
622 for item in res["service_ip_list"]:
623 policy_list.append( GslbServiceIP(**item) )
624 return policy_list
625 except AxAPIError:
626 return None
627
628 @staticmethod
638
640 """ method: gslb.service_ip.create
641 Create the GSLB service IP.
642 """
643 try:
644 method_call.call_api(self, method = "gslb.service_ip.create", format = "json", post_data = self.getRequestPostDataJson())
645 return 0
646 except AxAPIError, e:
647 return e.code
648
650 """ method: gslb.service_ip.delete
651 Delete the GSLB service IP.
652 """
653 try:
654 method_call.call_api(self, method = "gslb.service_ip.delete", format = "json", name = self.name)
655 return 0
656 except AxAPIError, e:
657 return e.code
658
660 """ method: gslb.service_ip.update
661 Update the GSLB service IP.
662 """
663 try:
664 method_call.call_api(self, method = "gslb.service_ip.update", format = "json", post_data = self.getRequestPostDataJson())
665 return 0
666 except AxAPIError, e:
667 return e.code
668
671 """
672 Implementation of the aXAPI gslb.snmp_template.* method to
673 manage the GSLB DNS proxy configuration as getAll/create/delete/update
674
675 Usage:
676 # DNS proxy with parameters:
677 # name (required) SNMP template name
678 # user_name SNMP template user name
679 # community community
680 # host host name or host IP
681 # port SNMP port
682 # version SNMP version
683 # oid SNMP OID
684 # interface interface
685 # security_level secure level
686 # security_engine_id security engine ID
687 # auth_key authentication key
688 # auth_protocol authentication protocol
689 # private_key private key
690 # private_protocol private protocol
691 # context_engine_id context engine ID
692 # context_name context name
693 # interval interval
694
695 # Example:
696 # create a GSLB SNMP template configuration as:
697 !
698 gslb template snmp template2
699 version v2c
700 username user1
701 community public
702 !
703 #
704 snmp_temp = GslbSnmpTemplate(name="template2")
705 snmp_temp.user_name ="user1"
706 snmp_temp.community ="public"
707 snmp_temp.port = 161
708 snmp_temp.version = 2
709 snmp_temp.interval = 3
710 snmp_temp.create()
711 """
712
713 __display__ = ["name"]
714 __obj_name__ = 'snmp_template'
715 __xml_convrt__ = {"snmp_template_list": "snmp_template"}
716
717 @staticmethod
719 """ method : gslb.snmp_template.getAll
720 Returns a list of GSLB service_ip in GslbSnmpTemplate instance.
721 """
722 try:
723 res = method_call.call_api(GslbSnmpTemplate(), method = "gslb.snmp_template.getAll", format = "json")
724 temp_list = []
725 for item in res["snmp_template_list"]:
726 temp_list.append( GslbSnmpTemplate(**item) )
727 return temp_list
728 except AxAPIError:
729 return None
730
731 @staticmethod
741
743 """ method: gslb.snmp_template.create
744 Create the GSLB SNMP template.
745 """
746 try:
747 method_call.call_api(self, method = "gslb.snmp_template.create", format = "json", post_data = self.getRequestPostDataJson())
748 return 0
749 except AxAPIError, e:
750 return e.code
751
753 """ method: gslb.snmp_template.delete
754 Delete the GSLB SNMP template.
755 """
756 try:
757 method_call.call_api(self, method = "gslb.snmp_template.delete", format = "json", name = self.name)
758 return 0
759 except AxAPIError, e:
760 return e.code
761
763 """ method: gslb.snmp_template.update
764 Update the GSLB SNMP template.
765 """
766 try:
767 method_call.call_api(self, method = "gslb.snmp_template.update", format = "json", post_data = self.getRequestPostDataJson())
768 return 0
769 except AxAPIError, e:
770 return e.code
771
773 """
774 Implementation of the aXAPI gslb.global.get/.set method
775
776 Usage:
777 """
778
779 @staticmethod
789
791 """ method : gslb.global.set
792 Update GSLB global settings.
793 """
794 try:
795 method_call.call_api(self, method = "gslb.global.set", format = "json", post_data = self.getRequestPostDataJson())
796 return 0
797 except AxAPIError, e:
798 return e.code
799