Forum Discussion
Use iControl API to query for node list for IP verification and hostname resolve.
I would like to write a script using python that will pull a node list from F5 of node names ONLY included in all partitions. The output could be a text file with the list or my script will parse the names that would be processed reachability and name resolution. Could someone point me in the right direction as far as where to start?
Currently I log into the F5 gui and navigate to the "Nodes:Nodes List", display all nodes, then select all the content, copy and paste it into an excel spreadsheet. From there I select the node names which are IP's, paste them into a txt file, then process the list via a powershell script that pings the IP and resolves for hostname.
I would just like to stream line the process of fetching the node names.
Let me know if you need any more detail.
Thanks
APT
8 Replies
- Arnaud_Lemaire
Employee
Hello,
to start you can take this example which is doing pool listing : https://devcentral.f5.com/wiki/iControl.pyControlGetPools.ashx
and change everywhere LocalLB.Pool by LocalLB.NodeAddressV2
that will give you the Node listing part.
- mimlo_61970
Cumulonimbus
Also, you are going to need to specify each partition and get the list for it seperately. Management.Folder.get_list will give you all of the partitions(or just create a static list in python with their names), and System.Session.set_active_folder to change the folder you are in.
I'd also recommend bigsuds over pycontrol. If I have time later I will see if I can put together a sample script.
- mimlo_61970
Cumulonimbus
See below. You'll need to download bigsuds and install it. I don't have nodes in multiple partitions so I cannot confirm that part, but it should work. the script will leave you with a python list(all_nodes) that contains the IP address of all the nodes on the device(in the given partition list)
import bigsuds hostname = "hostname" username="username" Password="password" b = bigsuds.BIGIP( hostname = hostname, username = username, password = password, ) b2 = b.with_session_id() folders = ['/Common', '/SecondPartition'] all_nodes = [] for f in folders: b2.System.Session.set_active_folder(f) node_list = b2.LocalLB.NodeAddressV2.get_list() node_address = b2.LocalLB.NodeAddressV2.get_address(node_list) all_nodes.extend(node_address)
- aj1
Nimbostratus
Hi,
I am using bigsuds and creating pools directly which in turn creates the nodes (since i cannot seem to create nodes and then pools because it complains about the nodes already existing if you try to create a pool out of already existing nodes !). The problem is that the Pool Member IP field in the structure {'address':'10.10.10.1', 'port':80} of the LocalLB.Pool.create_v2 method becomes the name of the node. So when i check the config utility, the node name and address are the same - 10.10.10.1
How can resolve this issue? Would really appreciate any help. Change the node names after creating the pools, if thats possible.
Thanks!
- mimlo_61970
Cumulonimbus
You can create pools out of existing nodes. The 'address' should be the Web UI 'name'
b.LocalLB.Pool.create_v2([pool_name],[lb_method],[pool_members])
where pool_members = {'address' : '/Common/nodename' , 'port' : 443}
- aj1
Nimbostratus
Awesome. That works ! Thank you mimlo.
- PeteWhite
Employee
You can use set_recursive_query_state so that get_list() returns nodes from all folders.
- StephanManthey
Nacreous
In case you are considering a plain tmsh based solution the following approach may help as well:
tmsh -q -c "cd /; list ltm node recursive one-line" ltm node Common/CommonNode_181 { address 10.131.131.181 } ltm node partitionA/partionA_Node_182 { address 10.131.131.182 partition partitionA } ltm node partitionB/partionB_Node_183 { address 10.131.131.183 partition partitionB } tmsh -q -c "cd /; list ltm node recursive one-line" | awk '{print $3}' Common/CommonNode_181 partitionA/partionA_Node_182 partitionB/partionB_Node_183 tmsh -q -c "cd /; list ltm node recursive one-line" | awk -F '[ /]' '{print $4}' CommonNode_181 partionA_Node_182 partionB_Node_183
Thank, Stephan
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