Module slb
[hide private]
[frames] | no frames]

Source Code for Module slb

  1  # -*- encoding: utf8 -*-
 
  2  """
 
  3      SLB module:  aXAPI server load balancing implementation.
 
  4          Support the object-oriented interface for the SLB such as:
 
  5              ServiceGroup        configure the service groups
 
  6              ServiceGroupStats   collect the statistics of service group
 
  7              RealServer          configure the servers
 
  8              RealServerStats     collect the statistics of servers
 
  9              VirtualServer       configure the virtual servers and services
 
 10              VirtualServerStats  collect the statistics of virtual servers
 
 11              
 
 12      Author : Richard Zhang, A10 Networks (c)
 
 13      email  : rzhang@a10networks.com
 
 14      Date   : 03/06/2012
 
 15  """ 
 16  
 
 17  import method_call 
 18  from  base import AxObject, AxAPIError 
19 20 -class ServiceGroup(AxObject):
21 """ 22 Implementation of the aXAPI slb.service_group.* method to 23 manage the SLB service groups as getAll/create/delete/update 24 25 Usage: 26 # Service group with parameters: 27 # name (required) service group name. 28 # protocol (required) service group type, either TCP(2) or UDP(3). 29 # lb_method desired load-balancing algorithm on the service group with: 30 # 0 RoundRobin (default) 31 # 1 WeightedRoundRobin 32 # 2 LeastConnection 33 # 3 WeightedLeastConnection 34 # 4 LeastConnectionOnServicePort 35 # 5 WeightedLeastConnectionOnServicePort 36 # 6 FastResponseTime 37 # 7 LeastRequest 38 # 8 StrictRoundRobin 39 # 9 StateLessSourceIPHash 40 # 10 StateLessSourceIPHashOnly 41 # 11 StateLessDestinationIPHash 42 # 12 StateLessSourceDestinationIPHash 43 # 13 StateLessPerPacketRoundRobin 44 # health_monitor health monitor method used at the service group member. 45 # min_active_member min active members. 46 # status status of min active members, enabled(1) or disabled(0) 47 # number number of min active members. 48 # priority_set priority option of min active members: 49 # 0 Do nothing 50 # 1 Skip Priority Set 51 # 2 Dynamic PriorityRequired, please fill in a valid number.(1 - 63) 52 # client_reset send client reset when server selection fail enabled(1) or disabled(0) 53 # stats_data stats data, either enabled(1) or disabled(0) 54 # extended_stats extended stats, either enabled(1) or disabled(0) 55 # member_list tag for service group members 56 # server server name (or IPv4, IPv6 address) of this member 57 # port server port number 58 # template server port template name 59 # priority member priority 60 # stats_data member stats data, either enabled(1) or disabled(0) 61 62 # Example: 63 # retrieve all service groups 64 svc_group_list = ServiceGroup.getAll() 65 for sg in svc_group_list: 66 # work sg 67 print sg 68 # search for service group with name, g1 69 svc = ServiceGroup.searchByName("g1") 70 # check svc.name, svc.health_monitor, svc.member_list 71 72 # create a service group, g3 with members: 73 # 1.1.1.2:80 74 # 1.1.1.3:80 75 svc2 = ServiceGroup() 76 svc2.name = "g3" 77 svc2.protocol = AxAPI.PROTO_TCP 78 svc2.lb_method = AxAPI.LB_LEAST_CONNECTED_ON_SERVICE_PORT 79 svc2.member_list = [{"server":"1.1.1.2", "port": 80, "status": AxAPI.STATUS_ENABLED}, {"server":"1.1.1.3", "port": 80}] 80 svc2.create() 81 # disable g3 member 1.1.1.2:80 82 svc2.member_list = [{"server":"1.1.1.2", "port": 80, "status": AxAPI.STATUS_DISABLED}] 83 svc2.update() 84 """ 85 86 __display__ = ["name", "protocol", "lb_method"] 87 __obj_name__ = 'service_group' 88 __xml_convrt__ = {"service_group_list": "service_group", "member_list": "member"} 89 90 @staticmethod
91 - def getAll():
92 """ method :slb.service_group.getAll 93 Returns a list of service groups in ServiceGroup instance. 94 """ 95 try: 96 res = method_call.call_api(ServiceGroup(), method = "slb.service_group.getAll", format = "json") 97 svc_list = [] 98 for item in res["service_group_list"]: 99 svc_list.append( ServiceGroup(**item) ) 100 return svc_list 101 except AxAPIError: 102 return None
103 104 @staticmethod
105 - def searchByName(name):
106 """ method: slb.service_group.search 107 Search the service group by given name. 108 """ 109 try: 110 r = method_call.call_api(ServiceGroup(), method = "slb.service_group.search", name = name, format = "json") 111 return ServiceGroup(**r[ServiceGroup.__obj_name__]) 112 except AxAPIError: 113 return None
114
115 - def create(self):
116 """ method: slb.service_group.create 117 Create the service group. 118 """ 119 try: 120 method_call.call_api(self, method = "slb.service_group.create", format = "json", post_data = self.getRequestPostDataJson()) 121 return 0 122 except AxAPIError, e: 123 return e.code
124
125 - def delete(self):
126 """ method: slb.service_group.delete 127 Delete the service group. 128 """ 129 try: 130 method_call.call_api(self, method = "slb.service_group.delete", format = "json", name = self.name) 131 return 0 132 except AxAPIError, e: 133 return e.code
134
135 - def update(self):
136 """ method: slb.service_group.update 137 Update the service group. 138 """ 139 try: 140 method_call.call_api(self, method = "slb.service_group.update", format = "json", post_data = self.getRequestPostDataJson()) 141 return 0 142 except AxAPIError, e: 143 return e.code
144
145 -class ServiceGroupStats(AxObject):
146 """ 147 Implementation of the aXAPI slb.service_group.fetchAllStatistics/.fetchStatistics method to 148 collect the SLB service group statistics data 149 150 Usage: 151 # Service group stats with following data fields: all read-only 152 # name service group name. 153 # protocol L4 protocol of this service group, TCP(2) or UDP(3) 154 # status member status 155 # disabled(0) 156 # all members up (1) 157 # partition up(2) 158 # functional up (3) 159 # down (4) 160 # unknown (5) 161 # cur_conns total number of current connections 162 # tot_conns total number of connections, ulong64 163 # req_pkts total number of request packets received, ulong64 164 # resp_pkts total number of response packets sent, ulong64 165 # req_bytes total number of request bytes received, ulong64 166 # resp_bytes total number of response bytes sent, ulong64 167 # cur_reqs total number of current requests 168 # tot_reqs total number of requests, ulong64 169 # tot_succ_reqs total number of successful requests, ulong64 170 # member_stat_list tag for service group members 171 # server server IPv4 or IPv6 address 172 # port server port number 173 # status member status, up(1), down (4), unknown(5) 174 # cur_conns total number of current connections 175 # tot_conns total number of connections, ulong64 176 # req_pkts total number of request packets received, ulong64 177 # resp_pkts total number of response packets sent, ulong64 178 # req_bytes total number of request bytes received, ulong64 179 # resp_bytes total number of response bytes sent, ulong64 180 # cur_reqs total number of current requests 181 # tot_reqs total number of requests, ulong64 182 # tot_succ_reqs total number of successful requests, ulong64 183 184 # Example: 185 all_group_stats = ServiceGroupStats.getAll() 186 for grp in all_group_stats: 187 # work grp for stats data 188 print grp 189 # get the stats data for g1 190 aGroup = ServiceGroupStats.searchByName(name='g1') 191 print aGroup 192 193 """ 194 195 __display__ = ["name", "status", "protocol"] 196 __obj_name__ = 'service_group_stat_list' 197 __obj_readonly__ = True 198 __xml_convrt__ = {"service_group_stat_list": "service_group_stat", "member_stat_list": "member_stat"} 199
200 - def __init__(self,**params):
201 AxObject.__init__(self,**params)
202 203 @staticmethod
204 - def getAll():
205 """ method : slb.service_group.fetchAllStatistics 206 """ 207 try: 208 res = method_call.call_api(ServiceGroupStats(), method = "slb.service_group.fetchAllStatistics", format = "json") 209 svc_list = [] 210 for item in res[ServiceGroupStats.__obj_name__]: 211 svc_list.append( ServiceGroupStats(**item) ) 212 return svc_list 213 except AxAPIError: 214 return None
215 216 @staticmethod
217 - def searchByName(name):
218 try: 219 r = method_call.call_api(ServiceGroupStats(), method = "slb.service_group.fetchAllStatistics", name = name, format = "json") 220 if len(r[ServiceGroupStats.__obj_name__]) > 0: 221 return ServiceGroupStats(**r[ServiceGroupStats.__obj_name__][0]) 222 else: 223 return None 224 except AxAPIError: 225 return None
226
227 -class RealServer(AxObject):
228 """ 229 Implementation of the aXAPI slb.server.* method to 230 manage the SLB real servers as getAll/create/delete/update 231 232 Usage: 233 # Server with parameters: 234 # name (required) Server name 235 # host (required) Server IP address or dns name 236 # status Server status, enabled(1) or disabled(0), default is enabled 237 # gslb_external_address GSLB external IP address 238 # health_monitor Server health-monitor name, empty means the default 239 # weight Server weight 240 # conn_limit Server connection limit 241 # conn_limit_log Server connection limit logging, enabled(1) or disabled(0) 242 # conn_resume Server connection resume 243 # stats_data Server stat data option, enabled(1) or disabled(0) 244 # extended_stats Server extended stats, enabled(1) or disabled(0) 245 # slow_start Server slow start option, enabled(1) or disabled(0) 246 # spoofing_cache Server spoofing cache option, enabled(1) or disabled(0) 247 # template Server template name, empty means the default 248 # port_list tag for the server ports 249 # port_num (key) server port number 250 # protocol (key) either TCP(2) or UDP(3) protocol type 251 # weight server port weight 252 # no_ssl server port no ssl, enabled(1) or disabled(0) 253 # conn_limit server port connection limit 254 # conn_limit_log server port connection limit logging, enabled(1) or disabled(0) 255 # conn_resume server port connection resume 256 # template server port template name, empty means the default 257 # stats_data server port stat data option, enabled(1) or disabled(0) 258 # extended_stats server port extended stats, enabled(1) or disabled(0) 259 # health_monitor server port health monitor name, empty means the default. Only when follow port is not set 260 # follow_port tag of follow port, only when health monitor is not set 261 # follow_port_num follow port number 262 # follow_port_type follow port type 263 264 # Example: 265 266 """ 267 268 __display__ = ["name", "host", "status"] 269 __obj_name__ = 'server' 270 __xml_convrt__ = {"server_list": "server", "port_list": "port"} 271
272 - def __init__(self,**params):
273 AxObject.__init__(self,**params)
274 275 @staticmethod
276 - def getAll():
277 """ method :slb.server.getAll 278 Returns a list of real servers in RealServer instance. 279 """ 280 try: 281 res = method_call.call_api(RealServer(), method = "slb.server.getAll", format = "json") 282 rs_list = [] 283 for item in res["server_list"]: 284 rs_list.append( RealServer(**item) ) 285 return rs_list 286 except AxAPIError: 287 return None
288 289 @staticmethod
290 - def searchByName(name):
291 """ method: slb.server.search 292 Search the real server by given name. 293 """ 294 try: 295 r = method_call.call_api(RealServer(), method = "slb.server.search", name = name, format = "json") 296 return RealServer(**r[RealServer.__obj_name__]) 297 except AxAPIError: 298 return None
299 300 @staticmethod
301 - def searchByHost(host):
302 """ method: slb.server.search 303 Search the real server by given host IP or host name. 304 """ 305 try: 306 r = method_call.call_api(self, method="slb.server.search", host = host, format = "json") 307 return RealServer(**r[RealServer.__obj_name__]) 308 except AxAPIError: 309 return None
310
311 - def create(self):
312 """ method: slb.server.create 313 Create the real server. 314 """ 315 try: 316 method_call.call_api(self, method="slb.server.create", format = "json", post_data = self.getRequestPostDataJson()) 317 return 0 318 except AxAPIError, e: 319 return e.code
320
321 - def delete(self):
322 """ method: slb.server.delete 323 Delete the real server. 324 """ 325 try: 326 if len(self.name) > 0: 327 method_call.call_api(self, method = "slb.server.delete", format = "json", name = self.name) 328 else: 329 method_call.call_api(self, method = "slb.server.delete", format = "json", host = self.host) 330 return 0 331 except AxAPIError, e: 332 return e.code
333
334 - def update(self):
335 """ method: slb.server.update 336 Update the real server. 337 """ 338 try: 339 method_call.call_api(self, method = "slb.server.update", format = "json", post_data = self.getRequestPostDataJson()) 340 return 0 341 except AxAPIError, e: 342 return e.code
343
344 -class RealServerStats(AxObject):
345 """ 346 Implementation of the aXAPI slb.server.fetchAllStatistics/.fetchStatistics method to 347 collect the SLB server statistics data 348 349 Usage: 350 # Server stats with following data fields: all read-only 351 # name Server name. 352 # host Server IP address (IPv4 or IPv6) or dns name 353 # status Server status, either enabled(1) or disabled(0) 354 # cur_conns total number of current connections 355 # tot_conns total number of connections, ulong64 356 # req_pkts total number of request packets received, ulong64 357 # resp_pkts total number of response packets sent, ulong64 358 # req_bytes total number of request bytes received, ulong64 359 # resp_bytes total number of response bytes sent, ulong64 360 # cur_reqs total number of current requests 361 # total_reqs total number of requests, ulong64 362 # total _reqs_succ total number of successful requests, ulong64 363 # port_stat_list tag for the server ports 364 # port_num server port number 365 # protocol L3 protocol. TCP(2) or UDP(3) 366 # status member status either enabled(1) or disabled(0) 367 # cur_conns total number of current connections 368 # tot_conns total number of connections, ulong64 369 # req_pkts total number of request packets received, ulong64 370 # resp_pkts total number of response packets sent, ulong64 371 # req_bytes total number of request bytes received, ulong64 372 # resp_bytes total number of response bytes sent, ulong64 373 # cur_reqs total number of current requests 374 # total_reqs total number of requests, ulong64 375 # total_reqs_succ total number of successful requests, ulong64 376 377 # Example: 378 all_server_stats = RealServerStats.getAll() 379 for srv in all_server_stats: 380 # work srv for stats data 381 print srv 382 # get the stats data for s1 383 s = RealServerStats.searchByName(name='s1') 384 print s 385 386 """ 387 388 __display__ = ["name", "host", "status"] 389 __obj_name__ = 'server_stat_list' 390 __obj_readonly__ = True 391 __xml_convrt__ = {"server_stat_list": "server_stat", "port_stat_list": "port_stat"} 392
393 - def __init__(self,**params):
394 AxObject.__init__(self,**params)
395 396 @staticmethod
397 - def getAll():
398 """ method : slb.server.fetchAllStatistics 399 """ 400 try: 401 res = method_call.call_api(RealServerStats(), method = "slb.server.fetchAllStatistics", format = "json") 402 svc_list = [] 403 for item in res[RealServerStats.__obj_name__]: 404 svc_list.append( RealServerStats(**item) ) 405 return svc_list 406 except AxAPIError: 407 return None
408 409 @staticmethod
410 - def searchByName(name):
411 try: 412 r = method_call.call_api(RealServerStats(), method = "slb.server.fetchAllStatistics", name = name, format = "json") 413 if len(r[RealServerStats.__obj_name__]) > 0: 414 return RealServerStats(**r[RealServerStats.__obj_name__][0]) 415 else: 416 return None 417 except AxAPIError: 418 return None
419
420 -class VirtualServer(AxObject):
421 """ 422 Implementation of the aXAPI slb.virtual_server.* method to 423 manage the SLB virtual servers as getAll/create/delete/update 424 425 Usage: 426 # Virtual server with parameters: 427 # name (required) virtual server name. 428 # Required one of the following token (address, subnet, acl_id, acl_name): 429 # address virtual server address, either IPv4 or IPv6 430 # subnet IPv4 subnet 431 # address address of subnet 432 # mask_len the length of this subnet 433 # acl_id IPv4 ACL id 434 # acl_name IPv6 ACL name 435 # 436 # status virtual server status, either enabled(1) or disabled(0) 437 # arp_status ARP disabled option, either disabled(0) or enabled(1) 438 # stata_data stats data option, either disabled(0) or enabled(1) 439 # extended_stat extended stat option, either disabled(0) or enabled(1) 440 # disable_vserver_on_condition disable vserver on conditions. Do not disable virtual server in any case(0), disable virtual server when any port down (1), disable virtual server when all ports down(2) 441 # redistribution_flagged redistribution flagged option, either disabled(0) or enabled(1) 442 # ha_group configured HA group 443 # group status of HA config 444 # ha_group_id ha group id 445 # dynamic_server_weight dynamic server weight 446 # vip_template virtual server template name 447 # pbslb_template pbslb policy template name 448 # vport_list tag for virtual services 449 # protocol (key) virtual service protocol with: 450 # TCP 2 451 # UDP 3 452 # Other 4 453 # RTSP 5 454 # FTP 6 455 # MMS 7 456 # SIP 8 457 # FAST-HTTP 9 458 # TCP-PROXY 10 459 # HTTP 11 460 # HTTPS 12 461 # SSL-PROXY 13 462 # SMTP 14 463 # SIP-TCP 15 464 # SIP-TLS 16 465 # DIAMETER 17 466 # DNS-UDP 18 467 # TFTP 19 468 # port (key) virtual service port number 469 # service_group service group assigned to the virtual service 470 # status virtual service status either enabled(1) or disabled(0) 471 # connection_limit connection limit of the virtual service 472 # status connection limit status of the virtual service either enabled(1) or disabled(0) 473 # connection_limit connection limit value 474 # connection_limit_action connection limit action, either reset(1) or drop(0) 475 # connection_limit_log connection limit logging, either enabled(1) or disabled(0) 476 # default_selection use default server selection when preferred method fails, 477 # either enabled(1) or disabled(0) 478 # received_hop use received hop for response either enabled(1) or disabled(0) 479 # stats_data stats data, either enabled(1) or disabled(0) 480 # extended_stats extended stats, either enabled(1) or disabled(0) 481 # snat_against_vip source nat traffic against vip either enabled(1) or disabled(0) 482 # vport_template virtual server port template name 483 # port_acl_id assigned access-list, ipv4 only 484 # pbslb_template pbslb template 485 # aflex_list aflex list 486 # aflex name of aflex in aflex_list 487 # acl_natpool_binding_list acl – natpool binding list 488 # ***one of the follwing properties, acl_id or acl_name: 489 # acl_id ipv4 acl id 490 # acl_name IPv6 acl name 491 # nat_pool source nat pool name 492 # 493 # protocol=HTTP: vport has the following additional properties: 494 # send_reset send client reset when server selection fails, 495 # either enabled(1) or disabled(0) 496 # sync_cookie syn cookie, either enabled(1) or disabled(0) 497 # source_nat source NAT pool name 498 # http_template HTTP template name 499 # ram_cache_template RAM caching template name 500 # tcp_proxy_template TCP-Proxy template name 501 # server_ssl_template Server-SSL template name 502 # conn_reuse_template Connection-Reuse template name 503 # ***one of the following properties, source_ip_persistence_template/cookie_persistence_template 504 # source_ip_persistence_template Source-IP-Persistent template name 505 # cookie_persistence_template cookie persistence template name 506 # 507 # protocol=HTTPS: vport has the following additional properties: 508 # send_reset send client reset when server selection fails, 509 # either enabled(1) or disabled(0) 510 # sync_cookie syn cookie, either enabled(1) or disabled(0) 511 # source_nat source NAT pool name 512 # http_template HTTP template name 513 # ram_cache_template RAM caching template name 514 # tcp_proxy_template TCP-Proxy template name 515 # client_ssl_template client ssl template 516 # server_ssl_template Server-SSL template name 517 # conn_reuse_template Connection-Reuse template name 518 # ***one of the following properties: source_ip_persistence_template/cookie_persistence_template 519 # source_ip_persistence_template Source-IP-Persistent template name 520 # cookie_persistence_template cookie persistence template name 521 # 522 # protocol=FAST-HTTP: vport has the following additional properties: 523 # send_reset send client reset when server selection fails, 524 # either enabled(1) or disabled(0) 525 # sync_cookie syn cookie, either enabled(1) or disabled(0) 526 # source_nat source NAT pool name 527 # http_template HTTP template name 528 # tcp_template TCP template name 529 # conn_reuse_template Connection-Reuse template name 530 # ***one of the following properties: source_ip_persistence_template/cookie_persistence_template 531 # source_ip_persistence_template Source-IP-Persistent template name 532 # cookie_persistence_template cookie persistence template name 533 # 534 # protocol=TCP: vport has the following additional properties: 535 # send_reset send client reset when server selection fails, 536 # either enabled(1) or disabled(0) 537 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 538 # direct_server_return direct server return (no destination NAT) enabled (1) or disabled (0) 539 # sync_cookie syn cookie, either enabled(1) or disabled(0) 540 # source_nat source NAT pool name 541 # tcp_template TCP template name 542 # ***one of the following properties: source_ip_persistence_template/cookie_persistence_template 543 # source_ip_persistence_template Source-IP-Persistent template name 544 # cookie_persistence_template cookie persistence template name 545 # 546 # protocol=UDP: vport has the following additional properties: 547 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 548 # direct_server_return direct server return (no destination NAT) enabled (1) or disabled (0) 549 # source_nat source NAT pool name 550 # udp_template UDP template name 551 # dns_template DNS template name 552 # source_ip_persistence_template Source-IP-Persistent template name 553 # 554 # protocol=RTSP: vport has the following additional properties: 555 # send_reset send client reset when server selection fails, 556 # either enabled(1) or disabled(0) 557 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 558 # direct_server_return direct server return (no destination NAT) enabled (1) or disabled (0) 559 # sync_cookie syn cookie, either enabled(1) or disabled(0) 560 # tcp_template TCP template name 561 # rtsp_template RTSP template name 562 # 563 # protocol=FTP: vport has the following additional properties: 564 # send_reset send client reset when server selection fails, 565 # either enabled(1) or disabled(0) 566 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 567 # direct_server_return direct server return (no destination NAT) enabled (1) or disabled (0) 568 # sync_cookie syn cookie, either enabled(1) or disabled(0) 569 # source_nat source NAT pool name 570 # tcp_template TCP template name 571 # source_ip_persistence_template Source-IP-Persistent template name 572 # 573 # protocol=MMS: vport has the following additional properties: 574 # send_reset send client reset when server selection fails, 575 # either enabled(1) or disabled(0) 576 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 577 # sync_cookie syn cookie, either enabled(1) or disabled(0) 578 # tcp_template TCP template name 579 # 580 # protocol=SSL-PROXY: vport has the following additional properties: 581 # send_reset send client reset when server selection fails, 582 # either enabled(1) or disabled(0) 583 # sync_cookie syn cookie, either enabled(1) or disabled(0) 584 # source_nat source NAT pool name 585 # tcp_proxy_template TCP-Proxy template name 586 # client_ssl_template client ssl template 587 # server_ssl_template Server-SSL template name 588 # conn_reuse_template Connection-Reuse template name 589 # source_ip_persistence_template Source-IP-Persistent template name 590 # 591 # protocol=SMTP-PROXY: vport has the following additional properties: 592 # send_reset send client reset when server selection fails, 593 # either enabled(1) or disabled(0) 594 # sync_cookie syn cookie, either enabled(1) or disabled(0) 595 # source_nat source NAT pool name 596 # tcp_proxy_template TCP-Proxy template name 597 # client_ssl_template client ssl template 598 # smtp_template Server-SSL template name 599 # source_ip_persistence_template Source-IP-Persistent template name 600 # 601 # protocol=SIP: vport has the following additional properties: 602 # send_reset send client reset when server selection fails, 603 # either enabled(1) or disabled(0) 604 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 605 # udp_template UDP template name 606 # source_ip_persistence_template Source-IP-Persistent template name 607 # sip_template SIP template name 608 # dns_template DNS template name 609 # 610 # protocol=SIP-TCP: vport has the following additional properties: 611 # send_reset send client reset when server selection fails, 612 # either enabled(1) or disabled(0) 613 # sync_cookie syn cookie, either enabled(1) or disabled(0) 614 # source_nat source NAT pool name 615 # server_ssl_template Server-SSL template name 616 # conn_reuse_template Connection-Reuse template name 617 # tcp_proxy_template TCP-Proxy template name 618 # source_ip_persistence_template Source-IP-Persistent template name 619 # sip_template SIP template name 620 # 621 # protocol=SIP-TLS: vport has the following additional properties: 622 # send_reset send client reset when server selection fails, 623 # either enabled(1) or disabled(0) 624 # sync_cookie syn cookie, either enabled(1) or disabled(0) 625 # source_nat source NAT pool name 626 # client_ssl_template client ssl template 627 # server_ssl_template Server-SSL template name 628 # conn_reuse_template Connection-Reuse template name 629 # tcp_proxy_template TCP-Proxy template name 630 # source_ip_persistence_template Source-IP-Persistent template name 631 # sip_template SIP template name 632 # 633 # protocol=TCP-PROXY: vport has the following additional properties: 634 # send_reset send client reset when server selection fails, 635 # either enabled(1) or disabled(0) 636 # sync_cookie syn cookie, either enabled(1) or disabled(0) 637 # source_nat source NAT pool name 638 # tcp_proxy_template TCP-Proxy template name 639 # source_ip_persistence_template Source-IP-Persistent template name 640 # 641 # protocol=DNS-UDP: vport has the following additional properties: 642 # send_reset send client reset when server selection fails, 643 # either enabled(1) or disabled(0) 644 # source_nat source NAT pool name 645 # udp_template UDP template name 646 # source_ip_persistence_template Source-IP-Persistent template name 647 # dns_template DNS template name 648 # 649 # protocol=DIAMETER: vport has the following additional properties: 650 # send_reset send client reset when server selection fails, 651 # either enabled(1) or disabled(0) 652 # source_nat source NAT pool name 653 # udp_template UDP template name 654 # source_ip_persistence_template Source-IP-Persistent template name 655 # dns_template DNS template name 656 # 657 # protocol=TFTP: vport has the following additional properties: 658 # ha_connection_mirror HA connection mirror enabled(1) or disabled (0) 659 # direct_server_return direct server return (no destination NAT) enabled (1) 660 # source_nat source NAT pool name 661 # udp_template UDP template name 662 # 663 # protocol=OTHER: vport has the following additional properties: 664 # direct_server_return direct server return (no destination NAT) enabled (1) 665 # source_nat source NAT pool name 666 # udp_template UDP template name 667 # l4_template_type TCP (2) or UDP(3) 668 # ***one of the following properties: udp_template/tcp_template 669 # udp_template UDP template name 670 # tcp_template TCP template name 671 672 # Example: 673 # create a virtual server, test_vip1, with address 100.10.10.1 674 # and configure a HTTP service at port 80: 675 vip1 = VirtualServer(name="test_vip1", address="100.10.10.1") 676 vip1.vport_list = [{"port" : 80, "protocol": AxAPI.SVC_HTTP}] 677 vip1.create() 678 # disable the vip1 HTTP port 80: 679 vip1.vport_list = [{"port" : 80, "protocol": AxAPI.SVC_HTTP, "status": AxAPI.STATUS_DISABLED}] 680 vip1.update() 681 # delete the vip1 682 vip1.delete() 683 684 # get all virtual server 685 vip_list = VirtualServer.getAll() 686 for avip in vip_list: 687 # work on avip instance 688 print avip 689 # search a virtual server with name, vip2 690 vip2 = VirtualServer.searchByName("vip2") 691 """ 692 693 __display__ = ["name", "address", "status"] 694 __obj_name__ = 'virtual_server' 695 __xml_convrt__ = {"virtual_server_list": "virtual_server", "vport_list": "vport", "aflex_list": "aflex", "acl_natpool_binding_list": "acl_natpool_binding"} 696
697 - def __init__(self,**params):
698 AxObject.__init__(self,**params)
699 700 @staticmethod
701 - def getAll():
702 """ method :slb.virtual_server.getAll 703 Returns a list of virtual servers in VirtualServer instance. 704 """ 705 try: 706 res = method_call.call_api(VirtualServer(), method = "slb.virtual_server.getAll", format = "json") 707 vip_list = [] 708 for item in res["virtual_server_list"]: 709 vip_list.append( VirtualServer(**item) ) 710 return vip_list 711 except AxAPIError: 712 return None
713 714 @staticmethod
715 - def searchByName(name):
716 """ method: slb.virtual_server.search 717 Search the virtual server by given name. 718 """ 719 try: 720 r = method_call.call_api(VirtualServer(), method = "slb.virtual_server.search", name = name, format = "url") 721 return VirtualServer(**r[VirtualServer.__obj_name__]) 722 except AxAPIError: 723 return None
724
725 - def create(self):
726 """ method: slb.virtual_server.create 727 Create the virtual server. 728 """ 729 try: 730 method_call.call_api(self, method = "slb.virtual_server.create", format = "json", post_data = self.getRequestPostDataJson()) 731 return 0 732 except AxAPIError, e: 733 return e.code
734
735 - def delete(self):
736 """ method: slb.virtual_server.delete 737 Delete the virtual server. 738 """ 739 try: 740 method_call.call_api(self, method = "slb.virtual_server.delete", format = "json", name = self.name) 741 return 0 742 except AxAPIError, e: 743 return e.code
744
745 - def update(self):
746 """ method: slb.virtual_server.update 747 Update the virtual server. 748 """ 749 try: 750 method_call.call_api(self, method = "slb.virtual_server.update", format = "json", post_data = self.getRequestPostDataJson()) 751 return 0 752 except AxAPIError, e: 753 return e.code
754
755 -class VirtualServerStats(AxObject):
756 """ 757 Implementation of the aXAPI slb.virtual_server.fetchAllStatistics/.fetchStatistics method to 758 collect the SLB virtual server statistics data 759 760 Usage: 761 # Virtual server stats with following data fields: all read-only 762 # name Virtual server name. 763 # ***One of the following token (address, subnet, acl_id, acl_name): 764 # address virtual server address, either IPv4 or IPv6 765 # subnet IPv4 subnet 766 # address address of subnet 767 # mask_len the length of this subnet 768 # acl_id IPv4 ACL id 769 # acl name IPv6 ACL name 770 # status Virtual server status 771 # 0: disabled 772 # 1: all up 773 # 2: partition up 774 # 3: function up 775 # 4: down 776 # 5: unknown 777 # cur_conns total number of current connections 778 # tot_conns total number of connections, ulong64 779 # req_pkts total number of request packets received, ulong64 780 # resp_pkts total number of response packets sent, ulong64 781 # req_bytes total number of request bytes received, ulong64 782 # resp_bytes total number of response bytes sent, ulong64 783 # cur_reqs total number of current requests 784 # total_reqs total number of requests, ulong64 785 # total _reqs_succ total number of successful requests, ulong64 786 # vport_stat_list tag for the virtual server ports 787 # port virtual server port number 788 # protocol virtual port protocol 789 # TCP 2 790 # UDP 3 791 # Other 4 792 # RTSP 5 793 # FTP 6 794 # MMS 7 795 # SIP 8 796 # FAST-HTTP 9 797 # TCP-PROXY 10 798 # HTTP 11 799 # HTTPS 12 800 # SSL-PROXY 13 801 # SMTP 14 802 # SIP-TCP 15 803 # SIP-STL 16 804 # DIAMETER 17 805 # DNS-UDP 18 806 # TFTP 19 807 # status virtual port status 808 # 0: disabled 809 # 1: all up 810 # 2: partition up 811 # 3: function up 812 # 4: down 813 # 5: unknown 814 # cur_conns total number of current connections 815 # tot_conns total number of connections, ulong64 816 # req_pkts total number of request packets received, ulong64 817 # resp_pkts total number of response packets sent, ulong64 818 # req_bytes total number of request bytes received, ulong64 819 # resp_bytes total number of response bytes sent, ulong64 820 # cur_reqs total number of current requests 821 # total_reqs total number of requests, ulong64 822 # total_reqs_succ total number of successful requests, ulong64 823 824 # Example: 825 all_vip_stats = VirtualServerStats.getAll() 826 for vip in all_vip_stats: 827 # work vip for stats data 828 print vip 829 # get the stats data for vip1 830 avip = VirtualServerStats.searchByName(name='vip1') 831 print avip 832 """ 833 834 __display__ = ["name", "status", "protocol"] 835 __obj_name__ = 'virtual_server_stat_list' 836 __obj_readonly__ = True 837 __xml_convrt__ = {"virtual_server_stat_list": "virtual_server_stat", "vport_stat_list": "vport_stat"} 838
839 - def __init__(self,**params):
840 AxObject.__init__(self,**params)
841 842 @staticmethod
843 - def getAll():
844 """ method : slb.virtual_server.fetchAllStatistics 845 """ 846 try: 847 res = method_call.call_api(VirtualServerStats(), method = "slb.virtual_server.fetchAllStatistics", format = "json") 848 vip_list = [] 849 for item in res[VirtualServerStats.__obj_name__]: 850 vip_list.append( VirtualServerStats(**item) ) 851 return vip_list 852 except AxAPIError: 853 return None
854 855 @staticmethod
856 - def searchByName(name):
857 try: 858 r = method_call.call_api(VirtualServerStats(), method = "slb.virtual_server.fetchAllStatistics", name = name, format = "json") 859 if len(r[VirtualServerStats.__obj_name__]) > 0: 860 return VirtualServerStats(**r[VirtualServerStats.__obj_name__][0]) 861 else: 862 return None 863 except AxAPIError: 864 return None
865