Koragg332
Mar 20, 2022Altostratus
Manipulate state of pool members via Python SDK
Hello all. I would like to ask you for help regarding the Python SDK for F5. I'm trying to achive the manipulation of state of pool members via API calls, but I"m not able to figured out what is the...
- Mar 21, 2022
I modified your script so that the relevant poolmemeber of the pool can be listed
Then perform the desired action,from f5.bigip import ManagementRoot # # Choice Poolmemeber def cpm(): print("\nChoice Pool Memeber:\n") index = 1 # ListPoolm = {} for poolm in pool_1.members_s.get_collection(): print(str(index) + ". " + poolm.name) ListPoolm[index] = poolm.name index += 1 choice = input("Which Poolmember do you want to action? ") return ListPoolm[int(choice)] # Action For Poolmember def act(): member = pool_1.members_s.members.load(partition='Common', name=cpm()) # action = input("enabled, disabled, forced_offline, Your input (press enter to skip): ") # if action == 'enabled': # enables member member.state = 'user-up' member.session = 'user-enabled' elif action == 'disabled': # disables member member.session = 'user-disabled' elif action == 'forced_offline': # forces online member member.state = 'user-down' member.session = 'user-disabled' if action is not None: member.update() else: print('readonly mode, no changes applied') if __name__ == "__main__": LB01 = ManagementRoot("testlb01", "weakuser", "weakpassword") pool_1 = LB01.tm.ltm.pools.pool.load (name="test-pool", partition="Common") # act() # via single for loop, I can extract the necessary info about pool members: for item in pool_1.members_s.raw["items"]: print("Node name: " + item["name"]) print("Node IP: " + item["address"]) print("Node full path: " + item["fullPath"]) # if item["session"] == "monitor-enabled": print("Node state: enable") elif item["session"] == "user-disabled": print("Node state: disable") # print("Node reachability: " + item["state"]) print("\n")
I hope I can help you - Mar 24, 2022
Hi oscarnet.
Your reply is what I wanted, just simplified:
#BRING POOL MEMBER UP:
pool_1.state = "user-up"
pool_1.session = "user-enabled"
pool_1.update()# BRING POOL MEMBER DOWN:
pool_1.state = "user-down"
pool_1.session = "user-disabled"
pool_1.update()Thank you very much for help.
Best Regards
Michal