Use
POST
to create an iRule and
PATCH
to modify the content (script). e.g.,
Creating an iRule "test" (under /Common):
curl -sku admin:secret -X POST -H "Content-Type: application/json" \
-d '{"name": "test" }' \
https://mgmtPort/mgmt/tm/ltm/rule
Output:
{"kind":"tm:ltm:rule:rulestate","name":"test","partition":"Common","fullPath":"/Common/test","generation":1745,"selfLink":"https://localhost/mgmt/tm/ltm/rule/~Common~test?ver=12.1.2"}
Add the script to the rule "test":
curl -sku admin:secret -X PATCH -H "Content-Type: application/json" \
-d '{"apiAnonymous":"when CLIENT_ACCEPTED {log local0. \"hello world\"}" }' \
https://mgmtPort/mgmt/tm/ltm/rule/test
Output:
{"kind":"tm:ltm:rule:rulestate","name":"test","fullPath":"test","generation":1746,"selfLink":"https://localhost/mgmt/tm/ltm/rule/test?ver=12.1.2","apiAnonymous":"when CLIENT_ACCEPTED {log local0. \"hello world\"}"}
Verify on the LTM:
tmsh list ltm rule test
ltm rule test {
when CLIENT_ACCEPTED {log local0. "hello world"}
}
This overrides the existing content:
curl -sku admin:secret -X PATCH -H "Content-Type: application/json" \
-d '{"apiAnonymous":"when HTTP_REQUEST {log local0. \"Bonjour monde\"}" }' \
https://mgmtPort/mgm/tm/ltm/rule/test
Verify:
tmsh list ltm rule test
ltm rule test {
when HTTP_REQUEST {log local0. "Bonjour monde"}
}