A python client to interact with the Riverbed Stingray REST API.
- Initial Release
- Requires Stingray API version 2.0
http://pyray.readthedocs.org/en/latest/
- Add Nodes Module
- Add test coverage
Quick sample of pyray:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
The HTTPClient method has a few optional and helpful parameters that will help troubleshoot issues or connectivity.
The client has an optional debug flag that will log the request as well as a curl command you can run against. For security reasons, username and password are not displayed in any logging.:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password', debug=True)
To allow insecure SSL connectivity for invalid certs:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password', insecure=True)
You can also change the port if that is configured:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password', port='1234')
To list all the pools configured:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pools = cl.pools.get()
for pool in pools:
print pool
To get a specific pool:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
To delete a specific pool:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
cl.pools.delete(name='pool1')
To get draining nodes:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
draining_nodes = pool.draining_nodes
for node in draining_nodes:
print node
To get all the configured nodes:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
for node in pool.nodes:
print node
Lets say you want to drain a group of nodes in a pool:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
pool.drain_nodes(nodes=['1.2.3.4:80'])
or quickly drain all nodes:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
pool.drain_nodes(nodes=pool.nodes)
To undrain nodes in a pool:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
pool.undrain_nodes(nodes=['1.2.3.4:80'])
or quickly undrain all draining nodes:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
pool.undrain_nodes(nodes=pool.draining_nodes)
To add a node:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
pool.add_node('1.1.1.2', 80)
or to remove a node:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
pool.remove_node('1.1.1.2', 80)
To get node details for all the nodes in a pool accross all traffic managers:
from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
pool = cl.pools.get(name='pool1')
nodes = pool.get_details()
for node, details in nodes.iteritems():
print node
print node['statistics']['current_conn']
For the full node details:
{u'statistics':
{u'bytes_from_node': 23776,
u'bytes_to_node': 3659117,
u'current_conn': 0,
u'current_requests': 0,
u'errors': 4,
u'failures': 1,
u'idle_conns': 0,
u'new_conn': 38,
u'node_port': 80,
u'pooled_conn': 0,
u'response_max': 0,
u'response_mean': 0,
u'response_min': 0,
u'state': u'draining',
u'total_conn': 38
}
}