cancel
Showing results for 
Search instead for 
Did you mean: 

Can't import api from exos

Can't import api from exos

Mirco
New Contributor
Hey everybody!

I'm working on a project with an Extreme Networks Summit X440-8p running firmware-version 16.1.1.4. I want to write a python script, but I'm stuck at the beginning.

The Python Scripting Guide (http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf) tells me I have to import api from exos with the following line:

"from exos import api"

Unfortunately, every time I want to execute my script (which just has a print command at the moment), there's an error:

"* X440-8p.81 # run script print_test
Traceback (most recent call last):
File "/config/print_test.py", line 1, in
from exos import api
File "/exos/tools/lib/python2.7/site-packages/exos/api/__init__.py", line 21, in
File "/exos/tools/lib/python2.7/site-packages/exos/api/ems.py", line 10, in
ImportError: No module named _exos_ext_ems".

What am I doing wrong? It's exactly how the scripting guide tells me to import the api. This site tells me the same: http://documentation.extremenetworks.com/python/

Has anything changed since it looks like this site is for software-version 15.7.1 whereas I'm running 16.1.1.4?

Thanks in advance!
Mirco
22 REPLIES 22

Dave_Hammers
Extreme Employee
The REST APIs are based on OpenConfig data models. The EXOS implementation is available starting with 22.3 and continues to include more models over time. The REST models are published on github so as more models are supported, they can be downloaded to previous EXOS releases.

That said, the REST models are not a complete set of data elements to manage a switch. If you wanted some data elements outside of the defined data models the JSONRPC would help.

JSONRPC is CLI-centric therefore proprietary to EXOS. Because everything can be done via CLI, JSONRPC offers the same configuration/mgmt coverage as SSH/Telnet/Console.

The difference for data retrieval 'show' commands is JSONRPC returns the internal data structures used to format the CLI display. The data structures are proprietary by quite often self explanatory. If you're developing in Python, it beats screen scraping.

The other method offered by JSONRPC is the ability to push a Python script down to a switch and run it without having to first transfer the script to the switch.

REST API - based on standardized OpenConfig models but not complete
JSONRPC - proprietary but complete EXOS mgmt

Tim_Black
New Contributor II
As described in my thread over here, I'm interested in learning which EXOS API is currently the most feature rich, and the most extensible for remote control and introspection of switch configuration and information. I'm using these switches in various topologies for AVB media transport, so in addition to controlling things like enabling/disabling ports, inline-power and vlans, like Mirco here, I will also be wanting to show msrp, mvrp, streams, and gptp info.

I believe today the answer is to either:
1. use jsonrpc.cli() and parse the json response in the remote python application.
2. do same with restapi.

Stephane, et al, is this correct?

Jsonrpc will be my choice, since json is already a very pythonic structure, and will integrate more rapidly in my python-based system. However, other than this interface preference an application environment might have, would there be any reason to choose your REST API, or are they both equally capable in terms of switch control and introspection bc they are both just wrappers around the CLI? Thanks.

Stephane_Grosj1
Extreme Employee
yep, I should have been more precise in the doc, the list of commands is a dictionary. You can see the function tried to execute your argument as a dictionary, you have as many Error as letters in your command (space included).

Mirco
New Contributor
Hi Stephane,

thanks a lot - it worked! I thought we would need a string because it's stated in the python scripting guide:
exos.api.exec_cli(cmds, timeout=0)

Send a list of commands to the CLI and return the output. This call will block until all commands have completed. This is a non-interactive, session-less version of the CLI. It doesn’t prompt or page, meaning some CLI commands are not valid in it (example: dis clipaging).

Parameters:
cmds (str): a list of commands.
timeout (int): timeout value, defaults to 0.

Returns:
A string of the CLI output (str).
So, we're now getting the formatted CLI output - is there a way to get it as XML like in the other python environment? As Dave stated, the CLI output could change from release to release, so it would be great to get XML instead of formatted CLI output.

Mirco
New Contributor
Hi Dave, thanks again for your support! Back from vacation  Actually, we're interested in the four following commands:

'show msrp'
'show mvrp'
'show msrp streams'
'show network-clock gptp'

The majority of information given through these commands are clear, but it would be great to have a documentation/explanation about those outputs, just to be sure we're interpreting it correctly!

Thanks!
Mirco
GTM-P2G8KFN