cancel
Showing results for 
Search instead for 
Did you mean: 
Helena_101649
Nimbostratus
Nimbostratus

Problem this snippet solves:

This is a list of curl commands using REST api calls to create a virtual server and other operations. Tested with BIGIP v.12.1.2.

How to use this snippet:

Firstly obtain an authentication token to be included in the curl statements.

curl -sk -H "Content-Type: application/json" -X POST https://hostname/mgmt/shared/authn/login -d '{"username": user,"password": password,"loginProviderName": "tmos"}'

Check response for the token.

Create pool with 2 members:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" -X POST https://hostname/mgmt/tm/ltm/pool -d '{"partition":"partition-name","name":"pool-name","members":[{"name":"server-name1:port1","address":"ip-address1"},{"name":"server-name2:port2","address":"ip-address2"}],"monitor":"monitor-name" }'

Create virtual server with existing pool:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" -X POST https://hostname/mgmt/tm/ltm/virtual -d '{"partition":"partition-name","name": "vs-name", "destination":"vs-ip:vs-port","pool":"pool-name"}'

Add member to existing pool:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" -X POST https://hostname/mgmt/tm/ltm/pool/~partition-name~pool-name/members -d '{"partition":"partition-name","name":"server-name:port","address":"ip-address"}'

Disable pool member:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" https://hostname/mgmt/tm/ltm/pool/~partition-name~pool-name/members/server-ip:port -X PUT -d '{"session":"user-disabled"}'

Enable pool member

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" https://hostname/mgmt/tm/ltm/pool/~partition-name~pool-name/members/server-ip:port -X PUT -d '{"session":"user-enabled"}'

Force pool member offline:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" https://hostname/mgmt/tm/ltm/pool/~partition-name~pool-name/members/server-ip:port -X PUT -d '{"session":"user-disabled","state":"user-down"}'

Delete pool member from pool:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" -X DELETE https://hostname/mgmt/tm/ltm/pool/~partition-name~pool-name/members/server-ip:port

Delete Virtual server:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-type: application/json" -X DELETE https://hostname/mgmt/tm/ltm/virtual/~partition-name~vs-name

Delete Pool:

curl -sk -H "X-F5-Auth-Token:token" -H "Content-type: application/json" -X DELETE https://hostname/mgmt/tm/ltm/pool/~partition-name~pool-name

Code :

#no snippet code
Comments
wjw_313334
Nimbostratus
Nimbostratus

Then how to disable/enable status of vitrual server

 

donfouts_363600
Nimbostratus
Nimbostratus

I agree with WJW - there are a lot of things left out... where did you find this in the f5 docs? from what I have found there is no easy place to learn how to draft these API calls.

 

any reference material would be great.

 

Helena_101649
Nimbostratus
Nimbostratus
Helena_101649
Nimbostratus
Nimbostratus

And for the question about how to disable/enable status of vitrual server, this is the syntax that works in my lab:

 

Disable VS:

 

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" -X PATCH -d '{"disabled": true}'

 

Enable VS:

 

curl -sk -H "X-F5-Auth-Token:token" -H "Content-Type: application/json" -X PATCH -d '{"enabled": true}'

 

The syntax '{"enable": false}' does not work in my case.

 

wjw_313334
Nimbostratus
Nimbostratus

Thanks Helena, it works and the syntax are as followings:

 

Disable VS:

 

curl -sku user:passwd -H "Content-Type: application/json" -X PATCH -d '{"disabled": true}' |jq .

 

Enable VS:

 

curl -sku user:passwd -H "Content-Type: application/json" -X PATCH -d '{"enabled": true}' |jq .

 

Version history
Last update:
‎24-Oct-2017 07:58
Updated by:
Contributors