pyray

A python client to interact with the Riverbed Stingray REST API.


Keywords
pyray
License
BSD-3-Clause
Install
pip install pyray==0.1.0

Documentation

pyray

https://badge.fury.io/py/pyray.png https://travis-ci.org/intr1nsic/pyray.png?branch=master

A python client to interact with the Riverbed Stingray REST API.

  • Initial Release
  • Requires Stingray API version 2.0

Documentation

http://pyray.readthedocs.org/en/latest/

Features

  • Add Nodes Module
  • Add test coverage

Usage

Quick sample of pyray:

from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')

Connectivity

The HTTPClient method has a few optional and helpful parameters that will help troubleshoot issues or connectivity.

Debug

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')

Generic Pool Queries

All pools

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

Get a specific 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')

Delete a specific pool

To delete a specific pool:

from pyray import client
cl = client.HTTPClient('https://1.1.1.1', 'admin', 'password')
cl.pools.delete(name='pool1')

Get all nodes draining in the pool

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

Get all configured nodes in a pool

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

Making changes to a pool

Drain

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)

Undrain

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)

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)

Query node details in a pool

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
    }
}