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
Hi Mirco,

EXOS has 2 python environments. one for writing scripts and the other for writing python apps.

Python that run with 'run script ' use the exsh library.

The python call you want is:

cliResult = exsh.clicmd(cmd, capture=True, xml=False)

If you wanted to capture the data in XML format instead of formatted CLI output:

xmlResult = exsh.clicmd(cmd, capture=False, xml=True)

Sometimes XML is easier to use to extract data instead of parsing the CLI output. CLI output format could change from release to release.

Here is a quick example with a pretty print script named xmlpp.py:

import xml.dom.minidom

xmlResult = exsh.clicmd('show ports statistics no-refresh', xml=True).replace('
','\n')
for line in xmlResult.splitlines():
a = xml.dom.minidom.parseString(line)
print a.toprettyxml(indent=' ' * 4)

run script xmlpp.py



MORE


1

1

0
1869
1500
1868
1

1-34
0
608062
937
1869
0
334260
935
1868






MORE


2

2

0
0
1500
0
0

1-34
0
0
0
0
0
0
0
0






MORE


3

3

0
0
1500
0
0

1-34
0
0
0
0
0
0
0
0



etc ...

DaveH



Mirco
New Contributor
Hello Stephen,

thanks for your reply and for looking into this issue!

I know that I can run simple scripts without loading the API but our aim isn't just printing something.

Actually, we want to read various parameters such as stream information (bandwidth etc.), and write them to a file, which we can read on a PC to display those data. We thought about using CLI-commands to achieve this. Therefore, we need the API.

Thanks again, hope you'll get back soon 🙂

Mirco

StephenW
Extreme Employee
Marco,

I will look into the problem with loading the API, but you don't need to use the API to do simple python scripts. You can print "hello" by using the text below and run the python script.

print ("hello")
output:
Switch# run script testhello

GTM-P2G8KFN