Forum Discussion

Thiyagu's avatar
Thiyagu
Icon for Cirrus rankCirrus
Jan 26, 2021

Need help with f5 SDK for a program to identify the node for the provided IP address and subsequently removing the config

Hello All,

I'm working on a F5 SDK python script to to identify the node for the provided IP address and subsequently removing the node from the member and removing the node from the load balancer configuration.

 

I have tried the below script and it works as expected till to identify the pool member however it is not working to delete the pool member and host.

 

Could you please help to fix the issue?

 

from f5.bigip import ManagementRoot

import pprint

import argparse

 

# Define unique variables

user = 'admin'

password = 'x.x.x..x'

f5_ip = '10.10.10.10'

partition = 'LAB-QA'

 

# Connect to the F5

mgmt = ManagementRoot(f5_ip, user, password)

ltm = mgmt.tm.ltm

 

###################

## Gain information

###################

 

# What nodes are on this F5?

nodes = ltm.nodes.get_collection()

 

# What pools are on this F5?

pools = ltm.pools.get_collection()

 

###################

## Checks

###################

 

# Does a node exist on the F5?

my_node = 'HOST_LAB_QA'

test = ltm.nodes.node.exists(partition=partition, name=my_node)

print("Is {} on the F5? {}".format(my_node, test))

 

# Is my node in a pool?

for pool in ltm.pools.get_collection():

   # Take note of how this call works

   for member in pool.members_s.get_collection():

       if my_node in member.name:

           print("{} is in the pool {}".format(my_node, pool.name))

           pool_memeber = mgmt.tm.ltm.pools.member.name

 

# Delete if a pool-member exists for the node to remove

   pool_memeber.delete()

 

1 Reply

  • Hello Thiyagu.

     

    You are assigning 'member.name' to pool_memeber.

    After that you are deleting this object, but this no makes sense.

     

    First you need to load the whole pool object using "load" and then you can delete it.

    # Delete a pool if it exists
    if mgmt.tm.ltm.pools.pool.exists(name='mypool', partition='Common'):
        pool_b = mgmt.tm.ltm.pools.pool.load(name='mypool', partition='Common')
        pool_b.delete()

    The pool object you are loading in the previous code is the same object you can get from your code this way.

    for pool in ltm.pools.get_collection():
       for member in pool.members_s.get_collection():
           if my_node in member.name:
               print("{} is in the pool {}".format(my_node, pool.name))
           # Deleting the pool.
           pool.delete()

    Regards,

    Darío.