Forum Discussion
3 Replies
- youssef1Cumulonimbus
here the documentation you need:
https://devcentral.f5.com/d/icontrol-rest-user-guide-version-131-246
Here, you can folow this lab, it will show you how to use API rest (you can download Postman_collection with request already built for vs, pool, ... creation)
http://clouddocs.f5.com/training/community/programmability/html/class1/module1/lab2.html
Below, an example with curl:
1.1.1.1 is you management IP
- 1 authentication, retrieve token
This token will be re-use on the next steps...
curl -k -X POST -H "Content-Type: application/json" -d '{"username":"restapiuser","password":"restapiuser","loginProviderName": "tmos"}' https://1.1.1.1/mgmt/shared/authn/login
In response you should retrieve a token ...":{"token":"2MBZTX4RV2QKQDXWDRGG4XAETU"....
You have to reuse this token in order to access to F5
- 2 monitor creation
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBZTX4RV2QKQDXWDRGG4XAETU" -d '{"name":"my-monitor-api","send":"GET / HTTP/1.1\r\nHost: mymonitor.mydomain.com\r\nConnection: Close\r\n\r\n","recv":""}' https://1.1.1.1/mgmt/tm/ltm/monitor/http
- 3 pool creation
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBZTX4RV2QKQDXWDRGG4XAETU" -d '{"name":"my-pool-api","monitor":"/Common/my-monitor-api"}' https://1.1.1.1/mgmt/tm/ltm/pool
- 4 http profile creation
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBZTX4RV2QKQDXWDRGG4XAETU" -d '{"name":"my-http-profile-api","insertXforwarderFor":"enabled","serverAgentName":"spirit"}' https://1.1.1.1/mgmt/tm/ltm/profile/http
5 - vs creation
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBZTX4RV2QKQDXWDRGG4XAETU" -d '{"name":"my-vs-api","destination":"1.2.3.4:80","ipProtocol":"tcp","pool":"/Common/my-pool-api","sourceAddressTranslation":{"type":"automap"},"profiles": [{"name":"/Common/tcp", "context":"clientside" },{"name":"/Common/tcp-wan-optimized", "context":"serverside" },"/Common/my-http-profile-api"]}' https://1.1.1.1/mgmt/tm/ltm/virtual
- Jason_NanceNimbostratus
I suggest using the Python F5 SDK instead of making REST calls directly if you don't already have some other framework with its own REST client. The SDK uses the REST API but comes with the benefits of having Python tools available for data management and such:
http://f5-sdk.readthedocs.io/en/latest/index.html
https://devcentral.f5.com/articles/getting-started-with-the-f5-common-python-sdk-27438 https://devcentral.f5.com/articles/getting-started-with-the-python-sdk-part-2-unnamed-resources-and-commands-27602 https://devcentral.f5.com/articles/getting-started-with-the-python-sdk-part-3-working-with-statistics-31387
- fanta_377379Nimbostratus
On top on what Jason Nance posted, I will add this to help you: https://lessonsintech.wordpress.com/2018/06/26/f5-python-sdk-basics/
F5-SDK will really make your life easy to create, delete, modify Pool, node, virtual servers.