Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

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 "https://localhost/mgmt/tm/ltm/node/example?ver=11.5.3"; 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.

0
Rate this Question
Comments on this Question
Comment made 26-Jan-2017 by cgaines22 4

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?

Get Started

from f5.bigip import ManagementRoot

Connect to the BigIP and configure the basic objects

mgmt = ManagementRoot("bigip.example.com", "admin", "somepassword")

Add New Node

mynode = mgmt.tm.ltm.nodes.node.create(name='10.5.183.191', address='10.5.183.191', description='12345avc', partition='Common')

Now figure out how to add this node in different pools
Load an existing pool using "load" command
"CL-COM_SELFSERV" is Partition, "pool1" is existing pool

pool_a = mgmt.tm.ltm.pools.pool.load(name='pool1', partition='CL-COM_SELFSERV')

Members (.191 was in pool already and want to add .192 and it removed .191. I need both to stay.

pool_a.members = '10.5.183.192:8080'

Complete update to pool (When using "update" It removes everything and then adds in new member.

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 "<pyshell#5>", 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: '<class 'f5.bigip.tm.ltm.pool.Pool'>' object has no attribute 'members'

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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.

1
Comments on this Answer
Comment made 18-Jul-2018 by JQUINONES82NB 167

Thank you!

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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.

0