iControl REST Cookbook - Virtual Server (ltm virtual)
Hi , you can solve it by using a transaction.
This requires 4 steps:
- open the transaction
- remove the previous profile
- add the new profile
- run the transaction and optionally monitor the progress
Btw, I have scripted this in an Ansible play by using the the URI module with plain access to the REST API.
In my case I´m using a token based authentication. But it will probably work with basic auth as well. So the authentication isnt described below.
These are the steps in detail:
The transaction will be opened as follows:
POST '{}' to path ./mgmt/tm/transaction with header "Content-Type: application/json"
You will get some payload back including the transaction identifier transId. The transaction identifier will be required in the following steps and used by an http-header.
Now you can add operations to the transaction.
At first you delete the current profile:
DELETE to path ./mgmt/tm/ltm/virtual/~<partition-name>~<virtual-name>/profiles/<profile-name> with header "X-F5-REST-Coordination-Id: <transId>"
Now you add the new profile (the clientside context or serverside context wont be relevant in case of your http profile and can be omitted):
POST '{"name":"<profile-name>","partition":"<partition-name>","context":"<context>"}' to path ./mgmt/tm/ltm/virtual/~<partition-name>~<virtual-name>/profiles with headers "X-F5-REST-Coordination-Id: <transId>" and "Content-Type: application/json"
The transaction can be released now (no need to add the transaction ID header as it is contained in the path):
PUT or PATCH '{"state": "VALIDATING"}' to path ./mgmt/tm/transaction/<transId> with header "Content-Type: application/json"
Finally you may want to monitor the transactions execution in a loop until the returned data has a json.state.lower() == 'completed' (no headers required as well):
GET to path ./mgmt/tm/transaction/<transId>
Thats it so far. Transactions work nicely as well in tmsh.
Cheers, Stephan