Forum Discussion

Amador_130070's avatar
Amador_130070
Icon for Nimbostratus rankNimbostratus
Jul 29, 2014

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

  • 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.

     

  • 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.

     

  • 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's avatar
    aj1
    Icon for Nimbostratus rankNimbostratus

    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!

     

  • 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's avatar
    aj1
    Icon for Nimbostratus rankNimbostratus

    Awesome. That works ! Thank you mimlo.

     

  • 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