Hi,
I have seen examples of using Perl or Python to work with the REST API, I understand the logic in the examples I have seen but I do not code in either of those languages. So what I would like to do is write a BASH script that I can pass parameters to, then get CURL to PUT the updates I want.
The main part I am after is to be able to add nodes to a pool as I spin new machines up, I have read the REST API guild and I can see that it is possible. It shows examples of doing so using PERL, I have tried a few things to get this working with CURL but not having much luck.
It what I want even possible?
Thanks,
Darren
Solved! Go to Solution.
The following curl command will send a put to change the pool nodes.
curl --user admin:admin -X PUT -H "Content-Type: application/json" -d'{"properties":{"basic":{"nodes":["127.0.0.1:8080","127.0.0.1:8081"]}}}' https://stm.example.com:9070/api/tm/2.0/config/active/pools/www.example.com/
"The main part I am after is to be able to add nodes to a pool as I spin new machines up"
You may also be able to use the built in autoscaling functionality of traffic manager to start the nodes in your environment. The provided and example drivers and can be configured to work with various environments.
For More Information See Feature Brief: Stingray's Autoscaling capability
The following curl command will send a put to change the pool nodes.
curl --user admin:admin -X PUT -H "Content-Type: application/json" -d'{"properties":{"basic":{"nodes":["127.0.0.1:8080","127.0.0.1:8081"]}}}' https://stm.example.com:9070/api/tm/2.0/config/active/pools/www.example.com/
"The main part I am after is to be able to add nodes to a pool as I spin new machines up"
You may also be able to use the built in autoscaling functionality of traffic manager to start the nodes in your environment. The provided and example drivers and can be configured to work with various environments.
For More Information See Feature Brief: Stingray's Autoscaling capability
Hi,
Thanks for this, it is really helpful. On your point of if the pool exists could I do a GET, store that in a variable, append a new node IP and then POST it back?
I have also being trying this with Python as I thought it might be easier, I am very new to Python so I might be bitting off more than I can do. I tend to write BASH scripts so that is why I was looking a CURL.
Thanks,
Darren
On your point of if the pool exists could I do a GET, store that in a variable, append a new node IP and then POST it back?
Correct.
That is what I thought, what I am doing now is taking the output from curl and setting it as a variable
<variablename>=$(curl -k --user <usernameassword> -X GET "Content-Type: application/json" https://<uri>:9070/api/tm/1.0/config/active/pools/<name>)
As with you example above where you are PUT to the correct key value e.g. -d'{"properties":{"basic":{"nodes":["127.0.0.1:8080","127.0.0.1:8081"]}}}', can I do the same with the GET? All I am really after is the IP address of the nodes. From there I can append it with the new node I want and post it back.
So I would build a script that would pull the data, store the node values I want, put a new IP address and port, append to the values I have sorted and the PUT it back.
And thanks for all the help with this
As with you example above where you are PUT to the correct key value e.g. -d'{"properties":{"basic":{"nodes":["127.0.0.1:8080","127.0.0.1:8081"]}}}', can I do the same with the GET? All I am really after is the IP address of the nodes. From there I can append it with the new node I want and post it back.
So I would build a script that would pull the data, store the node values I want, put a new IP address and port, append to the values I have sorted and the PUT it back.
You can perform a get to the URL of the pool i.e. https://stm.example.com:9070/api/tm/2.0/config/active/pools/www.example.com/ , but this will contain a JSON formatted response of all the pool settings (more than the node members). You will need to pull the data and "process" the JSON response so you are only using the IP address or host name of the nodes. For this reason, using a scripting language with a JSON interpreter makes things easy.
Hi,
I have taken your advice and have started to work with Python for this, I have managed to do what I want with Python.
Thanks for all the help with this.
Cheers,
Darren