Showing results for 
Search instead for 
Did you mean: 

HowTo: List all of the draining nodes in Stingray using Python and REST

This question cropped up on our discussion forum: Re: How to use RESTful Control API with Python? - enable, disable, or drain node: How can I list the nodes that are draining in a Stingray configuration, much like the 'Draining' page in the UI.


You can get the list of nodes that are draining per-pool from /api/tm/1.0/config/active/pools/poolname; look at the properties->basic->draining value.  There's no single action to get a list of all of the nodes that are draining in all pools.  The UI reads each pool one at a time and merges the 'draining' lists from each; you will need to do the same.


The following Python code illustrates how you could do this:



import requests

import json

url = 'https://stingray:9070/api/tm/1.0/config/active/pools/';

client = requests.Session()

client.auth = ('admin', 'admin')

client.verify = 0

response = client.get(url)

pools = json.loads(response.content)

draining = []

for node in pools['children']:

   response = client.get(url+node['name'])

   data = json.loads(response.content)

   draining += data['properties']['basic']['draining']

print "Draining Nodes: " + ", ".join( set( draining ))


Read more


Version history
Revision #:
1 of 1
Last update:
‎04-17-2013 12:21:AM
Updated by:
Labels (1)