Python Scripting Guide


Userlevel 3
Hi everybody!

I've recently update EXOS to 15.6. and I really would love to write some python scripts. Honestly, I'm not into programming actually. I just write python scripts sometimes.

So, I've read EXOS 15.6 User Guide, but there are few information about python scripting. Аt least for me) Does anybody give me some examples or maybe guides, articles, posts or something about it?

Thanks for help!

26 replies

Userlevel 7
Hi,

A guide will be posted soon here. It'll give a brief introduction to python, how you can use the scripting capability with EXOS, and some other features we are introducing in 15.7 (you sense the teasing here ;)).

In the meantime, I'd encourage you to start learning Python 2.7 and the standard library. That's very easy and powerful. There're so many books, article, it's difficult to point to one specific.

With EXOS 15.6, you can use exsh library to interact with EXOS.

import exsh

exsh.clicmd(cmd, capture=False, xml=False, args=None)

cmd is a valid EXOS CLI cmd.
optional:
capture can be True or False, if True it will return the command output in text.
xml can be True or False. if True it will return the command output in xml.
args are whatever parameter needed for the command

I'll see how we can manage to share on a specific space some little scripts for learning purposes.

So stay tuned for the Guide, it's coming.
Hi eyeV,

One of my findings which you might come and nice to know:

If you want to combine python scripting with Universal Port triggers you can do the following trick which worked for me. Example creating a python script which will run every minute.

1) Create the python script HelloWorld.py

Switch # vi HelloWorld.py

2) Because profile can trigger only CLI, you need to create a profile and just insert the following command (assuming you saved the python file to HelloWorld.py)

Switch # create upm profile HelloWorld
Start typing the profile and end with a . as the first and the only character on a line.
Use - edit upm profile - for block mode capability
run script HelloWorld.py
.

( Note the dot in the end)

3) Add the trigger to run the profile every minute starting from the next minute

create upm timer HelloTimer
configure upm timer "HelloTimer" after 60 every 60
configure upm timer "HelloTimer" profile "HelloWorld"

4) You can delete the timer

delete upm timer "HelloTimer"

Hope it helps

Sotiris
Userlevel 3
Thanks guys! I'm going to dive in!
Userlevel 7
ah, all these spoilers before the release of the guide... 🙂

of course, you can use UPM with Python scripting.
UPM provides environmental variables (for example the port where the event has occurred) and a Python script can use it. Just pass the variable(s) as argument(s) to the python script.
Userlevel 3
What library I can use in python scripting on Extreme switches?

standard library
sys
pexpect
exshexpect
exsh
what else?
Userlevel 7
The standard library is HUGE. You have a lot of modules included. As an example, sys is part of the standard library.
Userlevel 6
eyeV,

code academy is a great place to start learning python. It's free and very thorough.

http://www.codecademy.com/

I have a few script i made that make some task's very easy. Like running ELRP on every created vlan.
Userlevel 3
Stephen Williams wrote:

eyeV,

code academy is a great place to start learning python. It's free and very thorough.

http://www.codecademy.com/

I have a few script i made that make some task's very easy. Like running ELRP on every created vlan.

Thanks. I'm going to start right now. )
Userlevel 7
I'd love to see your scripts, and everybody's scripts.
If you are ok to share your creation, can you pass links to them? I'm trying to find, internally, a way to share all of it, for the community.
Userlevel 3
Grosjean, Stephane wrote:

I'd love to see your scripts, and everybody's scripts.
If you are ok to share your creation, can you pass links to them? I'm trying to find, internally, a way to share all of it, for the community.

Pretty good idea! For me, especially. )
Userlevel 5
Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf
Userlevel 3
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

It's exactly what I need! Thank you!
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

Christina M your link now produces:

404 Not Found

As does the same link on your "how to use python with EXOS" page:
https://gtacknowledge.extremenetworks.com/articles/How_To/How-to-use-Python-on-EXOS

What I'm trying to do is to control EXOS from python application running on a remote machine, so I can quickly enact config changes on the switch at my application runtime. To this end I do not see the value in this Python on EXOS feature, since it's much more cumbersome to have to tftp a script to the switch, telnet in, and "load" it, vs simply telnetting in and executing the commands via CLI as needed.

Given what I'm triyng to do (control exos switch remotely from python code), is the easiest and fastest way to accomplish this via telnet/CLI? Or is there some CLIENT python support I can use?

Someone on another thread mentioned a thing called XMC,which can completely control the switch, and has a REST API, and I was wondering if this would be useful in my case, but I'm having trouble finding documentation on it. Any links or advice would be appreciated. Thanks!
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

I did find this, which is helpfui for running python remotely. I'll look deeper into this.
Userlevel 7
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

If you want to use python remotely, you can either use jsonrpc or RESTConf (openconfig).

https://github.com/extremenetworks/EXOS_Apps/tree/master/JSONRPC
https://github.com/extremenetworks/EXOS_Apps/tree/master/REST
Userlevel 5
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

Python Guide Has been re-uploaded here: https://documentation.extremenetworks.com/pdfs/exos/Python_Getting_Started_Guide.pdf

You can also view our Python and RESTConf documentation here: https://www.extremenetworks.com/support/api-app/
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

Thanks Stephane, Christina. Thanks for all the pointers to the info I was looking for!

Christina, fyi:
1. your link to the "python getting started" doc is broken over at the EXOS API Doc Root, on the "How-to Guides" tab, and also broken on this page.
2. your link to the "EXOS JSONRPC Interface Reference" is broken over at the EXOS API Doc Root, on the API tab. Is looks like a copy-paste err as it links to the RESTAPI docs.

Also, over on this thread, I've been discussing all these option, in case you wanted to review and comment. Thanks.
Userlevel 5
Christina M wrote:

Hi all, the new Python Scripting Guide has been posted at: http://www.extremenetworks.com/wp-content/uploads/2015/02/Python_Getting_Started_Guide.pdf

Hi, Tim. Thanks for the heads up. The former has been fixed and our API writer removed the latter from the table. Please let us know if you see any other issues on the website.
Userlevel 3
I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.
Userlevel 5
eyeV wrote:

I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.

Hi there. I've been working to fix the issue, as others have written in with the same problem. Can you tell me if the attached is still showing the problem you're seeing? http://documentation.extremenetworks.com/Python Getting Started Guide.pdf
Userlevel 3
eyeV wrote:

I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.

Hi. Unfortunately, yes. I can't read it in browser.
Userlevel 5
eyeV wrote:

I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.

This is so odd. I've never seen anything like this before. I'm going to try to rebuild it from scratch. Please check back here later today for a new version.
Userlevel 5
eyeV wrote:

I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.

Hi there. I placed the content in a new Word template to see if that would fix the issue. Can you let me know if this is working for you now?

http://documentation.extremenetworks.com/Python%20Getting%20Started%20Guide%20v2.pdf

Thanks!
Userlevel 7
eyeV wrote:

I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.

Same for me, with Firefox.
Userlevel 3
eyeV wrote:

I have a mysterious problem with that guide. All pages except the first one are simply the gradient... But I can CTRL+C all text. Does anybody has the same problem?

I can read it on iPad for example, but I can't with the standard MacOS PDF viewer. Pretty strange.

Me too. It's really odd...

Reply