Using iControlRest to modify LTM pools

Problem this snippet solves:

I was recently asked how to use the REST API to add nodes to an existing LTM pool. The use case is one where the customer would spin up a new server in Amazon and wanted - by means of an API call - to add it to a pool.

Easy enough. All of the sample calls I have seen to date reference creating the pool simultaneous to creating its members using a POST request.

from the other https://devcentral.f5.com/questions/rest-api-pool-member-creation article:

curl -sk -u 'admin:admin' -H "Content-Type: application/json" -X POST https://x.x.x.x/mgmt/tm/ltm/pool -d '{"name":"test-pool","members":{"name":"Server-Bob:443","address":"10.0.0.1"}}'

To modify, simply use a PUT or PATCH request as follows:

curl -sk -u 'admin:admin' -H "Content-Type: application/json" -X PUT https://10.128.10.5/mgmt/tm/ltm/pool/test-pool -d '{"members":{"name":"Server-Steve:443","address":"10.0.1.1"},{"name":"Server-Bob:443","address":"10.0.0.1"}}'

Note that when you modify the pool, you must specify EVERY member EVERY time. If you only put in one item on the update, all other members will be erased. The same holds true for datagroup updates and any other collection update.

Updated: If you would like to add a member to an existing pool you can do so by specifying the name of the pool in the post to which a new member will be added. This will prepend to the new member to the existing pool. Examples below:

If you POST to tm/ltm/pool//members, it is an addition to the pool members. If you PUT/PATCH to tm/ltm/pool, the whole array you supply in the json input will replace existing members. If you DELETE to tm/ltm/pool//members/, the individual pool_member will be removed.

Code :

# no snippet code
Published Mar 09, 2015
Version 1.0

Was this article helpful?

2 Comments

  • I can't get the PUT to work for modifying an existing pool. It says there are updates below, but there are not. "Updated: If you would like to add a member to an existing pool you can do so by specifying the name of the pool in the post to which a new member will be added. This will prepend to the new member to the existing pool. Examples below:" I get the following error:
    
    
    
    tim:~ tim$ curl -sk -u ':' -H "Content-Type: application/json" -X PUT https://ny-bigip01.bananna.com/mgmt/tm/ltm/pool/test-pool -d '{"members":{"name":"api02.bananna.com:80","address":"10.96.81.80"}}'
    {"code":400,"message":"Found unexpected json string at configuration item /ltm/pool/test-pool/members/name. The json string is \"api02.bananna.com:80\".","errorStack":[]}
    
  • Missing an open/close bracket. This is what worked for me:

     

    curl -sk -u 'admin:admin' -H "Content-Type: application/json" -X PUT https://10.128.10.5/mgmt/tm/ltm/pool/test-pool -d '{"members":[{"name":"Server-Steve:443","address":"10.0.1.1"},{"name":"Server-Bob:443","address":"10.0.0.1"}]}'