Forum Discussion
Examples of JSON for adding an iRule for a virtual server via the REST API
I'm looking for examples of how to do this. I came across the post below, but it wasn't clear that it actually worked.
https://devcentral.f5.com/questions/assign-irule-to-virtual-server-via-icontrol-rest
{"name": "iControl_virtual", "rules": ["/Common/_sys_https_redirect"], "mask": "255.255.255.255", "nat64": "disabled", "destination": "192.168.1.30:80", "enabled": null, "sourceAddressTranslation": {"type": "automap"}, "source": "0.0.0.0/0", "profiles": [ {"kind": "ltm:virtual:profile", "name": "tcp"}, {"kind": "ltm:virtual:profile", "name": "http"} ], "mobileAppTunnel": "disabled", "mirror": "disabled", "ipProtocol": "tcp", "pool": "icontrol_pool", "description": "A Python REST client test virtual server"}
Also, I didn't see that the URI posted to was referenced. What would this be?
Thanks, Joel
- natheCirrocumulus
Joel,
I'm no expert on this but i know you need tmos v11.5 to add irules to virtual servers and in my lab POST doesn't work, only PUT and PATCH. Although it always does a replace so I can see you've got the redirect irule on the VS already so you'll need to re-add this to your code.
For example, in curl i can do this:
curl -sk -u user:pass -H "Content-Type: application/json" https://localhost/mgmt/tm/ltm/virtual/vs_lab -X PUT -d '{"rules":["/Common/test", "/Common/_sys_https_redirect"] }'
See if that works for you.
Hope this helps,
N
- Joel_NewtonCirrus
Thanks, Nathan. I'm running v11.6. Getting the /virtual/(virtual server) URI really helped.
I did get PUT to work with this method. I'm hoping to get POST working, though PUT is probably better for handling adding and removing, since you just have to set the total state you want.
Cheers, Joel
- natheCirrocumulusNo probs glad I could help
- Marga_Garrido_9Nimbostratus
Hi every one!
Any other examples of this? i' so interested to deploy an automatic system to create irules, but it is difficult to find info about how to do it.
Thank in advance.
- Joel_NewtonCirrus
Hi, Marga, your best bet is to figure out what language you want to use (Python, PowerShell, straight curl calls), and then review the docs for it.
 
A lot of work has been done on the Python SDK for working with iControlRest - examples here and here) as has on using PowerShell with iControlRest. There are examples here for using curl.
 
All the best, Joel
 
- Marga_Garrido_9Nimbostratus
Many thanks Joel!
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com