python 獲取指定pool下的成員狀態資訊
阿新 • • 發佈:2019-02-09
b = BIGIP( hostname = a[0], username = a[1], password = a[2], fromurl = True, wsdls = ['LocalLB.Pool']) pools = b.LocalLB.Pool.get_list() version = b.LocalLB.Pool.get_version() print "Version is: %s\n" % version print "Pools:" for x in pools: print "\t%s" % x import sys import pycontrol.pycontrol as pc import time import csv import ssl ssl._create_default_https_context = ssl._create_unverified_context #pool='YXPT_ust_pool' b = pc.BIGIP( hostname = '10.4.170.160', username = 'aaaaa', password = '123456', fromurl = True, wsdls=['LocalLB.PoolMember']) pools = b.LocalLB.PoolMember print pools print dir(pools) print dir(pools) #a= pools.get_object_status(pool_names=[pool]) # print type(a) print pools.get_object_status() C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/f5/get_f5_member_status.py <pycontrol.pycontrol.InterfaceInstance object at 0x03BB5E10> ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get_all_statistics', 'get_connection_limit', 'get_dynamic_ratio', 'get_monitor_association', 'get_monitor_instance', 'get_monitor_status', 'get_object_status', 'get_priority', 'get_ratio', 'get_session_enabled_state', 'get_session_status', 'get_statistics', 'get_version', 'name', 'remove_monitor_association', 'reset_statistics', 'set_connection_limit', 'set_dynamic_ratio', 'set_monitor_association', 'set_monitor_state', 'set_priority', 'set_ratio', 'set_session_enabled_state', 'suds', 'typefactory'] ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get_all_statistics', 'get_connection_limit', 'get_dynamic_ratio', 'get_monitor_association', 'get_monitor_instance', 'get_monitor_status', 'get_object_status', 'get_priority', 'get_ratio', 'get_session_enabled_state', 'get_session_status', 'get_statistics', 'get_version', 'name', 'remove_monitor_association', 'reset_statistics', 'set_connection_limit', 'set_dynamic_ratio', 'set_monitor_association', 'set_monitor_state', 'set_priority', 'set_ratio', 'set_session_enabled_state', 'suds', 'typefactory'] No handlers could be found for logger "suds.client" Traceback (most recent call last): File "C:/Users/tlcb/PycharmProjects/untitled/f5/get_f5_member_status.py", line 22, in <module> print pools.get_object_status() File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__ return client.invoke(args, kwargs) File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke result = self.send(soapenv) File "C:\Python27\lib\site-packages\suds\client.py", line 649, in send result = self.failed(binding, e) File "C:\Python27\lib\site-packages\suds\client.py", line 702, in failed r, p = binding.get_fault(reply) File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 265, in get_fault raise WebFault(p, faultroot) suds.WebFault: Server raised fault: 'Could not find element by name: pool_names' Process finished with exit code 1 import sys import pycontrol.pycontrol as pc import time import csv import ssl ssl._create_default_https_context = ssl._create_unverified_context pool='YXPT_ust_pool' b = pc.BIGIP( hostname = '10.4.170.160', username = 'aaaaa', password = '123456', fromurl = True, wsdls=['LocalLB.PoolMember']) pools = b.LocalLB.PoolMember print pools print dir(pools) print dir(pools) #a= pools.get_object_status(pool_names=[pool]) # print type(a) a= pools.get_object_status(pool_names=[pool]) print type(a) for x in a: print '11111111111111111111' print x print type(x) for y in x: print '22222222222222222222' print y print type(y) print dir(y) print '3333333333333333333333' print type(y.member) print type(y.object_status) print y.member.address+'=>'+str(y.member.port)+'=>'+y.object_status.availability_status+'=>'+y.object_status.enabled_status+'=>'+y.object_status.status_description C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/f5/get_f5_member_status.py <pycontrol.pycontrol.InterfaceInstance object at 0x03BE3E50> ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get_all_statistics', 'get_connection_limit', 'get_dynamic_ratio', 'get_monitor_association', 'get_monitor_instance', 'get_monitor_status', 'get_object_status', 'get_priority', 'get_ratio', 'get_session_enabled_state', 'get_session_status', 'get_statistics', 'get_version', 'name', 'remove_monitor_association', 'reset_statistics', 'set_connection_limit', 'set_dynamic_ratio', 'set_monitor_association', 'set_monitor_state', 'set_priority', 'set_ratio', 'set_session_enabled_state', 'suds', 'typefactory'] ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get_all_statistics', 'get_connection_limit', 'get_dynamic_ratio', 'get_monitor_association', 'get_monitor_instance', 'get_monitor_status', 'get_object_status', 'get_priority', 'get_ratio', 'get_session_enabled_state', 'get_session_status', 'get_statistics', 'get_version', 'name', 'remove_monitor_association', 'reset_statistics', 'set_connection_limit', 'set_dynamic_ratio', 'set_monitor_association', 'set_monitor_state', 'set_priority', 'set_ratio', 'set_session_enabled_state', 'suds', 'typefactory'] <type 'list'> 11111111111111111111 [(LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.160.52" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_RED" enabled_status = "ENABLED_STATUS_DISABLED" status_description = "Pool member has been marked down by a monitor" } }, (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.160.190" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_GREEN" enabled_status = "ENABLED_STATUS_ENABLED" status_description = "Pool member is available" } }, (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.160.191" port = 7021 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_GREEN" enabled_status = "ENABLED_STATUS_ENABLED" status_description = "Pool member is available" } }, (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.161.159" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_RED" enabled_status = "ENABLED_STATUS_DISABLED" status_description = "Forced down" } }, (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.161.160" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_RED" enabled_status = "ENABLED_STATUS_ENABLED" status_description = "Pool member has been marked down by a monitor" } }] <type 'list'> 22222222222222222222 (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.160.52" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_RED" enabled_status = "ENABLED_STATUS_DISABLED" status_description = "Pool member has been marked down by a monitor" } } <type 'instance'> ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__', 'member', 'object_status'] 3333333333333333333333 <type 'instance'> <type 'instance'> 10.4.160.52=>7011=>AVAILABILITY_STATUS_RED=>ENABLED_STATUS_DISABLED=>Pool member has been marked down by a monitor 22222222222222222222 (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.160.190" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_GREEN" enabled_status = "ENABLED_STATUS_ENABLED" status_description = "Pool member is available" } } <type 'instance'> ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__', 'member', 'object_status'] 3333333333333333333333 <type 'instance'> <type 'instance'> 10.4.160.190=>7011=>AVAILABILITY_STATUS_GREEN=>ENABLED_STATUS_ENABLED=>Pool member is available 22222222222222222222 (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.160.191" port = 7021 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_GREEN" enabled_status = "ENABLED_STATUS_ENABLED" status_description = "Pool member is available" } } <type 'instance'> ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__', 'member', 'object_status'] 3333333333333333333333 <type 'instance'> <type 'instance'> 10.4.160.191=>7021=>AVAILABILITY_STATUS_GREEN=>ENABLED_STATUS_ENABLED=>Pool member is available 22222222222222222222 (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.161.159" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_RED" enabled_status = "ENABLED_STATUS_DISABLED" status_description = "Forced down" } } <type 'instance'> ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__', 'member', 'object_status'] 3333333333333333333333 <type 'instance'> <type 'instance'> 10.4.161.159=>7011=>AVAILABILITY_STATUS_RED=>ENABLED_STATUS_DISABLED=>Forced down 22222222222222222222 (LocalLB.PoolMember.MemberObjectStatus){ member = (Common.IPPortDefinition){ address = "10.4.161.160" port = 7011 } object_status = (LocalLB.ObjectStatus){ availability_status = "AVAILABILITY_STATUS_RED" enabled_status = "ENABLED_STATUS_ENABLED" status_description = "Pool member has been marked down by a monitor" } } <type 'instance'> ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__', 'member', 'object_status'] 3333333333333333333333 <type 'instance'> <type 'instance'> 10.4.161.160=>7011=>AVAILABILITY_STATUS_RED=>ENABLED_STATUS_ENABLED=>Pool member has been marked down by a monitor Process finished with exit code 0