Forum Discussion
Query to retrieve VIP name from Node IP input
- Jun 06, 2018
This should do it, though it is fairly resource-intensive if you have a lot of virtual servers / pools / nodes:
!/usr/bin/env python3 from f5.bigip import ManagementRoot from getpass import getpass from pprint import pprint hostname = 'my.f5.ltm.net' username = 'foo' node_ips = ['192.168.1.1', 192.168.1.2', '192.168.1.3'] mgmt = ManagmentRoot(hostname, username, getpass()) Get node names that have IPs in the list nodes = [] for node in mgmt.tm.ltm.nodes.get_collection(): if node.address in node_ips: fullPath is /PARTITION/NAME nodes.append(node.fullPath) Get pool names which nodes in list belong pools = [] for pool in mgmt.tm.ltm.pools.get_collection(): members = pool.members_s.get_collection() for member in members: Member fullpath is '/PARTITION/NODENAME:SERVICE_PORT' if member.fullPath.split(':')[0] in nodes: pools.append(pool.fullPath) break Get virtual server names which pools in list belong virtuals = [] for virtual in mgmt.tm.ltm.virtuals.get_collection(): if hasattr(virtual, 'pool') and virtual.pool in pools: virtuals.append(virtual.fullPath) pprint(virtuals)
This should do it, though it is fairly resource-intensive if you have a lot of virtual servers / pools / nodes:
!/usr/bin/env python3
from f5.bigip import ManagementRoot
from getpass import getpass
from pprint import pprint
hostname = 'my.f5.ltm.net'
username = 'foo'
node_ips = ['192.168.1.1', 192.168.1.2', '192.168.1.3']
mgmt = ManagmentRoot(hostname, username, getpass())
Get node names that have IPs in the list
nodes = []
for node in mgmt.tm.ltm.nodes.get_collection():
if node.address in node_ips:
fullPath is /PARTITION/NAME
nodes.append(node.fullPath)
Get pool names which nodes in list belong
pools = []
for pool in mgmt.tm.ltm.pools.get_collection():
members = pool.members_s.get_collection()
for member in members:
Member fullpath is '/PARTITION/NODENAME:SERVICE_PORT'
if member.fullPath.split(':')[0] in nodes:
pools.append(pool.fullPath)
break
Get virtual server names which pools in list belong
virtuals = []
for virtual in mgmt.tm.ltm.virtuals.get_collection():
if hasattr(virtual, 'pool') and virtual.pool in pools:
virtuals.append(virtual.fullPath)
pprint(virtuals)
That notation (
w.x.y.z%something) is called a route domain. There's a couple ways to deal with it depending on your situation but it can be a bit iffy if you have duplicate IPs in use on a different route domains (one of the primary reasons to use route domains).
The easy/cheesy option is to use a little script to generate the
node_ips list for you with the route domains included:
!/usr/bin/env python3
from f5.bigip import ManagementRoot
from getpass import getpass
from pprint import pprint
hostname = 'my.f5.ltm.net'
username = 'foo'
Node IPs without route domain
node_ips_wo_rd = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
node_ips = []
mgmt = ManagmentRoot(hostname, username, getpass())
Pull back all nodes that have an IP in the list (regardless of route
domain) and print out a list with the route domain included
This will be slow for LTMs with lots of nodes
for node in mgmt.tm.ltm.nodes.get_collection():
if node.address.split('%')[0] in node_ips_wo_rd:
node_ips.append(node.address)
print('node_ips = [{}]'.format(', '.join(["'{}'".format(x) for x in node_ips])))
That will print out something like:
node_ips = ['192.168.1.1%400', '192.168.1.2%300', '192.168.1.2%301', '192.168.1.3']
...which you can clean up (such as if you have duplicate IPs on different route domains and don't want them all) and then copy/paste into the other script.
If that doesn't fit the need let me know what's up and we can come up with a different option.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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