查看设备版本号及主备状态
from f5.bigip import ManagementRoot
mgmt = ManagementRoot(ip, 'X', 'X')
fail = mgmt.tm.sys.failover.load()
failOverStat = fail.apiRawValues['apiAnonymous'].rstrip()
print("%s: Ver %s, %s" % (ip, mgmt.tmos_version, failOverStat))
可以这么理解:CLI:tmsh show sys failover
—- https://host/mgmt/tm/sys/failover —- mgmt.tm.sys.failover。
调试API调用
from f5.bigip import ManagementRoot
mgmt = ManagementRoot(ip, 'X', 'X') # set on instantiation
mgmt.debug = True # turn on after instantiation
print(x) # x为列表,当前为空[]
mgmt.tm.ltm.pools.pool.exists(name='testpool')
for x in mgmt.debug_output:
print(x) # 根据执行的情况,每条语句或者api对应一条curl语句,可以直接复制单独测试
mgmt.debug = False # turn off
注意F5 SDK调用API不是使用的curl,只是为了方便排查,才将debug结果格式化成curl命令格式。具体的排查结果可以查看Debugging API calls with the python sdk。
查看VS或者Pool状态
import datetime
from f5.bigip import ManagementRoot
from f5.utils.responses.handlers import Stats
mgmt = ManagementRoot(IP, X, X)
vs_collection = mgmt.tm.ltm.virtuals.get_collection()
print("---vs---")
for vs in vs_collection:
starttime = datetime.datetime.now()
vs_stats = Stats(vs.stats.load())
endtime = datetime.datetime.now()
print("VS: %s, availabilityState: %s, enabledState: %s, statusReason: %s, loadTime: %s" % (vs.name, vs_stats.stat.status_availabilityState['description'], vs_stats.stat.status_enabledState['description'], vs_stats.stat.status_statusReason['description'], (endtime - starttime).seconds))
pool_collection = mgmt.tm.ltm.pools.get_collection()
print("---pool---")
for pool in pool_collection:
starttime = datetime.datetime.now()
pool_stats = Stats(pool.stats.load())
endtime = datetime.datetime.now()
print("Pool: %s, availabilityState: %s, enabledState: %s, statusReason: %s, loadTime: %s" % (pool.name, pool_stats.stat.status_availabilityState['description'], pool_stats.stat.status_enabledState['description'], pool_stats.stat.status_statusReason['description'], (endtime - starttime).seconds))