Forum Discussion
kwondra34_26054
Nimbostratus
Jun 23, 2016F5 iControl REST - API calls required to get Load Balancer, Virtual Server URL, IP, Port, Pool Name/Status/Members
Hi everyone,
I am attempting to use the F5 REST API to create a csv containing the following fields (potentally others if they are available, but these will suffice):
- Virtual Server (URL/Name)...
JG
Cumulonimbus
Jul 15, 2016Here's my 2c: A quickly-put-together Python script, as seems to be something many of us will need at one time or another. It probably can be made more efficient, but it does the job as it is - very close to what you want; and hey, I'm not a Python fan myself, at least not yet.
!/usr/bin/python
This script displays some information about all virtual servers and
associated server pool and pool members. The output has ';' as the field
delimiter.
-------------------------------------------------------------------------
from f5.bigip import ManagementRoot
This gets rid of the warning message about SSL certificate issues.
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
mgmt = ManagementRoot("mgmt_IP_address", "admin", 'admin')
vservers = mgmt.tm.ltm.virtuals.get_collection()
pools = mgmt.tm.ltm.pools.get_collection()
print "Virtual Server Name;Virtual Server Destination;Virtual Server Partition;Pool Name;Pool LB Mode;Pool Member Name (address)(state)"
for vs in vservers:
s = ''
s += vs.name + ';'
if hasattr(vs, 'destination'):
s += vs.destination + ';'
else:
s += ';'
vs_partition = vs.partition
s += vs_partition + ';'
if hasattr(vs, 'pool'):
pool_name_from_vs = vs.pool
for pool in pools:
if ( pool_name_from_vs == pool.fullPath ):
s += pool.name + ';'
s += pool.loadBalancingMode + ';'
if hasattr(pool, 'session'):
s += pool.session + ';'
if hasattr(pool, 'state'):
s += pool.state + ';'
for member in pool.members_s.get_collection():
s += member.name + '(' + member.address + ')'
s += '(' + member.state + '),'
s = s[:-1]
else:
s += ";;"
print s
continue
print s
[Edit: Changed pool.name to pool.fullPath.]
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects