User guide
Web Services, CLI Scripting, and OpenFlow Using Python
OmniSwitch AOS Release 8 Switch Management Guide May 2014 page 10-15
Using Python
Python is an easy to learn, powerful, general-purpose scripting language. It combines easily readable code
with an object-oriented programming approach for fast and easy development on many platforms. Addi-
tional information on Python as well as installation instructions can be found from the Python website:
http://www.python.org.
A Python library has been created which can be used by any Python Consumer communicating with the
AOS Web Service Provider. The library is available in source form and provides a tool allowing develop-
ers to learn how to write code that communicates with the OmniSwitch Web Service Provider. In addi-
tion, this library can also be used as a standalone query tool using the command line.
Library Use
Invoking the library from third-party code is as simple as importing the relevant classes:
from consumer import AOSAPI, AOSConnection
The library itself relies on the dependency injection pattern, allowing the implementer to replace only bits
of the library with their own code, should they need to do so. The two example components imported
above allow a connection to be established to an AOS device.
Connection Example
A typical connection to an AOS device should look like this:
def do_something():
try:
api = AOSAPI(AOSConnection(
username = 'admin',
password = 'switch',
hostaddress = '192.168.1.1',
secure = False,
obeyproxy = False,
prettylinks = True,
useport = 80,
aosheaders = None,
debug = True))
api.login()
# Additional code goes here
api.logout()
except HTTPError, e:
api.logout()
print "Error: " + e.msg
Query Example
Augmenting the code above to perform a query is straightforward. Simply call api.query() and check its
success() property as in the example below:
results = api.query('mib', 'chasEntTemperatureTable', {
'mibObject0':'chasEntTempCurrent',
'mibObject1':'chasEntTempThreshold',