Forum Discussion
Use F5 Python SDK to Create Node with Pool in Separate Partition
I have seen multiple samples on creating a pool and loading a member in that pool. I have looked at the "; for creating nodes but so far I am not getting the idea. Is there a way using Python Rest or Python SDK to create a node in the common partition with no pool? After the node is loaded I will then take that node and use it in a pool/s but the pool/s are in different partition.
- cgaines22_14499Nimbostratus
This code will add a node to the Common Partition. Once the node is added in common it needs to be added to two different Partitions. For example below adding it to one different Partition. I have read this before but when running "update" the old information is removed and the new is added. How can I append the new to the old using the SDK?
from import ManagementRoot
mgmt = ManagementRoot("bigip.example.com", "admin", "somepassword")
mynode = mgmt.tm.ltm.nodes.node.create(name='10.5.183.191', address='10.5.183.191', description='12345avc', partition='Common')
pool_a = mgmt.tm.ltm.pools.pool.load(name='pool1', partition='CL-COM_SELFSERV')
pool_a.members = '10.5.183.192:8080'
pool_a.update()
So when adding new member to a pool it wipes out the existing members. I then tried
pool_a.members.append('10.5.183.192:8080')
but received error:
Traceback (most recent call last): File "", line 1, in pool_a.members.append('10.5.183.192:8080') File "C:\Python27\lib\site-packages\f5\bigip\mixins.py", line 125, in getattr raise AttributeError(error_message) AttributeError: 'f5.bigip.tm.ltm.pool.Pool'>' object has no attribute 'members'
- Ed_SummersNimbostratus
Up front: I'm very new to the SDK. My efforts so far have only focused on querying the device and reading state. I haven't practiced much in the realm of creating or modifying objects.
The pool members are a sub-collection under the pool. You can get the sub-collection:
pool_a.members_s.get_collection()
which will return a list of member objects. It looks like you're trying to pass just a string, where the collection of members is actually a list of member objects. Rather than botch the nomenclature, I found a decent starting example in the docs. Look about half-way down in the coding example on this link for an example of creating new pool members:
Managing LTM Pools and Members via the F5 SDK
Sorry I can't give you a more concrete example but hopefully this will help give you a start until someone with more experience on the SDK can fill in any other details.
- Jason_NanceNimbostratus
To add an existing node to an existing pool:
pool = mgmt.tm.ltm.pools.pool.load(partition='Common', name='mypool') pool.members_s.members.create(partition='Common', name='mynodename:80')
The secret sauce is in the overloaded name argument - it is really "node_name:service_port".
The above adds an existing node called "mynodename" to the pool and sets its service port to 80.
- JQUINONES82NBNimbostratus
Thank you!
To add an existing node to an existing pool:
pool = mgmt.tm.ltm.pools.pool.load(partition='Common', name='mypool') pool.members_s.members.create(partition='Common', name='mynodename:80')
The secret sauce is in the overloaded name argument - it is really "node_name:service_port".
The above adds an existing node called "mynodename" to the pool and sets its service port to 80.
- JQUINONES82NBNimbostratus
Thank you!
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