For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

REST API calls to create a virtual server

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
Published Oct 24, 2017
Version 1.0

5 Comments