Forum Discussion

bmoreira2000's avatar
Icon for Nimbostratus rankNimbostratus
Feb 17, 2021

How to add members to a pool - ControlRestAPI

I'm trying to add three members to a pool object, i have the following code and the following rest api output method.


curl -k -X POST \
    -u "${USER}:${PASS}" \
    "https://bip.server/mgmt/tm/ltm/pool/~Common~${HOST_FILTER}/members/" \
    -H 'Accept: */*' \
    -H 'Content-Type: application/json' \
    -d '{ 
        "kind": "tm:ltm:pool:members:memberscollectionstate", "selfLink": "https://localhost/mgmt/tm/ltm/pool/~Common~'${HOST_FILTER}'/members?ver=", "items": [ { "kind": "tm:ltm:pool:members:membersstate", "name": "serverswarm0:'${TMB_RESULT}'", "partition": "Common", "fullPath": "/Common/serverswarm0.servers:'${TMB_RESULT}'", "generation": 270491, "selfLink": "https://localhost/mgmt/tm/ltm/pool/~Common~'${HOST_FILTER}'/members/~Common~serverswarm0:'${TMB_RESULT}'?ver=", "address": "", "connectionLimit": 0, "dynamicRatio": 1, "ephemeral": "false", "fqdn": { "autopopulate": "disabled" }, "inheritProfile": "enabled", "logging": "disabled", "monitor": "default", "priorityGroup": 0, "rateLimit": "disabled", "ratio": 1, "session": "monitor-enabled", "state": "up" }, 
        { "kind": "tm:ltm:pool:members:membersstate", "name": "serverswarm:'${TMB_RESULT}'", "partition": "Common", "fullPath": "/Common/serverswarm1:'${TMB_RESULT}'", "generation": 270491, "selfLink": "https://localhost/mgmt/tm/ltm/pool/~Common~'${HOST_FILTER}'/members/~Common~serverswarm1:'${TMB_RESULT}'?ver=", "address": "", "connectionLimit": 0, "dynamicRatio": 1, "ephemeral": "false", "fqdn": { "autopopulate": "disabled" }, "inheritProfile": "enabled", "logging": "disabled", "monitor": "default", "priorityGroup": 0, "rateLimit": "disabled", "ratio": 1, "session": "monitor-enabled", "state": "up" } ] 


Output Method:

{"code":403,"message":"Operation is not supported on property /ltm/pool/~Common~test_host/members.","errorStack":[],"apiError":1}


1 Reply

  • Seems like we can only add one pool member per POST /mgmt/tm/ltm/pool/<poolName>/members call.


    This works (adding "CentOS-internal20:8080" to the pool "Pool-CentOS80").

    $ curl -sku $PASS https://$HOST/mgmt/tm/ltm/pool/Pool-CentOS80/members \
      -X POST -H "Content-type: application/json" \
      -d '{"name":"CentOS-internal20:8080", "partition":"Common"}'

    But this does not (note: the JSON text in the -d option is verified valid).

    $ curl -sku $PASS https://$HOST/mgmt/tm/ltm/pool/Pool-CentOS80/members \
      -X POST -H "Content-type: application/json" \
      -d '[{"name":"CentOS-internal20:8080", "partition":"Common"}, {"name":"CentOS-internal20:8081", "partition":"Common"}]'
    {"code":400,"message":"Found invalid JSON body in the request....

    So you need to call the POST multiple times.


    An alternative way is to overwrite the existing pool members by PATCHing the pool itself (PATCH /mgmt/tm/ltm/pool/<pool>).


    For example, my pool "Pool-CentOS80" has two members: "CentOS-internal20:80" and "CentOS-internal30:80". e.g.,

    $ curl -sku $PASS https://$HOST/mgmt/tm/ltm/pool/Pool-CentOS80?expandSubcollections=true \
      | jq -r '.membersReference.items[].name'

    (for readability sake, only pool member names are extracted using jq).


    To add "CentOS-internal20:8080" and "CentOS-internal20:8081" to the pool, PATCH it with the "four" pool members: e.g.,

    $ curl -sku $PASS https://$HOST/mgmt/tm/ltm/pool/Pool-CentOS80 \
    -X PATCH -H "Content-type: application/json" -d '{
      "membersReference": {
        "items": [
          {"name":"CentOS-internal20:80", "partition":"Common"}, // exiting one
          {"name":"CentOS-internal30:80", "partition":"Common"}, // exiting one
          {"name":"CentOS-internal20:8080", "partition":"Common"}, // new
          {"name": "CentOS-internal20:8081", "partition":"Common"} // new

    (the payload part is formatted with comments by hand for readability (note: No comment allowed in a JSON text)).


    Now I have four.

    $ curl -sku $PASS https://$HOST/mgmt/tm/ltm/pool/Pool-CentOS80?expandSubcollections=true \
      | jq -r '.membersReference.items[].name'

    I hope this helps.