10-Nov-2023 00:47 - edited 29-Nov-2023 00:23
The F5 XC Distributed Cloud GUI in the background sends API requests with JSON body to the system and those requests can be easily reviewed.
If someone wonders how to do some tasks that the XC GUI does the same way but with automation through the API and JSON then this article will help them. Also at the end I have shown how to retrive XC json data with API.
Reviewing the API requests that are generated by the XC GUI.
There are 3 ways to review the API requests that the GUI generates.
The XC JSON created objects from the API are a form of a backup configuration. Even if the objects were created from the GUI then API GET requests can be used to retrive their JSON data and this can be saved to a backup file in the form of snapshot.
I have used Python with requests library and the url and API key are added as user input arguments. The script can be used to get information like the XC LB or service policies. As example "/api/config/namespaces/default/service_policys". The script will first call an API endpoint to get for example all the load balancer or service policy names and then it will use the names get the config for each individual service policy or load balancer, using a for loop. There is time.sleep(1) to add 1 second slowness between each api request.
The code can have the full url like https://{tenant_name}.console.ves.volterra.io/api/config/namespaces/{namespace}service_policys and the api token be added during script execution or the arguments can be input at the start of script execution by commenting out url = sys.argv[1] and api_token = sys.argv[2] and executing the script like python3 service_policy.py {argument1} {argument2}.
The api token by default is hidden using the getpass library for extra security.
See Github for the code:
Nikoolayy1/xc_api_script: XC API script to retrieve basic json config (github.com)
In some cases using Terraform for XC will be best as XC has strong Terraform support as seen at the link below. Ansible can also be used but XC does not have many developed Ansible modules, so in many cases the Ansible URI module will need to be used and the Ansible URI module (ansible.builtin.uri module – Interacts with webservices — Ansible Documentation) in the backgroung is just the python requests or http.client module, as Ansible is python in the background, so better use python directly in that case.
XC Terraform:
Terraform | F5 Distributed Cloud Tech Docs
F5 Distributed Cloud WAAP deployment with Terrafor... - DevCentral
Using Terraform and F5® Distributed Cloud Mesh to ... - DevCentral
Example Ansible code (even if I said python is better in this case 😀)
xc_api_script/xc_ansible at main · Nikoolayy1/xc_api_script (github.com)