ExtremeSwitching (EXOS)

Expand all | Collapse all

Python Scripting Guide

  • 1.  Python Scripting Guide

    Posted 02-06-2015 05:06
    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!



  • 2.  RE: Python Scripting Guide

    Posted 02-06-2015 06:44
    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.


  • 3.  RE: Python Scripting Guide

    Posted 02-06-2015 10:42
    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


  • 4.  RE: Python Scripting Guide

    Posted 02-06-2015 11:28
    Thanks guys! I'm going to dive in!


  • 5.  RE: Python Scripting Guide

    Posted 02-06-2015 11:44
    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.


  • 6.  RE: Python Scripting Guide

    Posted 02-06-2015 11:53
    What library I can use in python scripting on Extreme switches?

    standard library
    sys
    pexpect
    exshexpect
    exsh
    what else?


  • 7.  RE: Python Scripting Guide

    Posted 02-06-2015 12:02
    The standard library is HUGE. You have a lot of modules included. As an example, sys is part of the standard library.



  • 8.  RE: Python Scripting Guide

    Posted 02-06-2015 13:37
    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.



  • 9.  RE: Python Scripting Guide

    Posted 02-06-2015 13:37
    Thanks. I'm going to start right now. )


  • 10.  RE: Python Scripting Guide

    Posted 02-06-2015 13:41
    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.


  • 11.  RE: Python Scripting Guide

    Posted 02-06-2015 13:41
    Pretty good idea! For me, especially. )


  • 12.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    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


  • 13.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    It's exactly what I need! Thank you!


  • 14.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    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!


  • 15.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    I did find this, which is helpfui for running python remotely. I'll look deeper into this.


  • 16.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    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



  • 17.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    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/



  • 18.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    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.


  • 19.  RE: Python Scripting Guide

    Posted 02-11-2015 13:58
    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.


  • 20.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    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.


  • 21.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    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


  • 22.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    Hi. Unfortunately, yes. I can't read it in browser.


  • 23.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    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.


  • 24.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    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!


  • 25.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    Same for me, with Firefox.


  • 26.  RE: Python Scripting Guide

    Posted 02-11-2015 15:42
    Me too. It's really odd...


  • 27.  RE: Python Scripting Guide

    Posted 02-11-2015 15:51
    Yep, same issue if reading from the browser. But if I download it, and open it, no problem.