ExtremeCloud IQ- Site Engine & Extreme Management Center

Expand all | Collapse all

Python Scripts Executing from Netsight - Clarification Needed

  • 1.  Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-03-2017 19:01
    I got my python book and started learning python at the beginning of the week.

    I want to write a script that can be executed from Netsight ( EMC 8.04 ). What I actually want to do is locate ports on switches to which PoE powered wireless access points are connected and cycle the PoE power in order to reboot hung access points.

    There is no documentation that I can find specific to Python scripts as opposed to TCL scripts on Netsight and my assumption was that I would just write a script that was suitable to be loaded directly onto a switch and that the Netsight interface would take care of uploading the script and executing it.

    I noticed that there didn't seem to be any information about adding the same kind of metadata for the definition of script arguments.

    I have a script that I can manually upload onto a switch and execute but if I try to execute it from Netsight by selecting the Run option and picking a switch to run it on, it fails with a complaint that the exsh module couldn't be found.

    I have realized that a python script in Netsight is not uploaded to the switch but rather executed on the server. I guess that would be workable but there is no documented method for providing arguments to the scripts.

    Is this a feature that hasn't been completed yet?
    I am trying to work out a method of being able to upload and execute a python script on a switch such that it can be leveraged from Netsight, or understand how others are leveraging python on XOS and getting scripts out onto devices on as needed basis.

    Do I need to use a generic python server script to push out my XOS python scripts, run them at the switch and then delete them?


  • 2.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-04-2017 20:28
    Hi,

    you do not use Python from EMC the same way than you write a script running directly on a switch.

    as for Python in 8.0.4, you can use the same metadata than TCL, and declare variables the same way too (do not quote them). To let the user modify the variables, you need to use them in the following way:

    emc_vars["yourVar"]

    You also have access to all the TCL variables:

    myVar = emc_vars["deviceIP"]

    if you use the port variable, it will prompt the user to select a list of ports.

    ports = emc_vars["port"]

    to execute CLI command:

    cli_results = emc_cli.send("show vlan")
    cli_output = cli_results.getOutput()

    Hope it helps.


  • 3.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 14:40
    Ok Stephane, I had a little play with this.

    I just did a basic script to walks the keys in emc_vars dictionary and copied in some lines from a real script with custom variables defined. Seems a little weird to have a TCL style "set var" command at the top of some python but "whatever!".

    I am still thinking about using the server scripts to load switch scripts and execute them but I guess for now I will see where I get with pure server scripts.

    Regardless, you have cured me of TCLishness - pure python for me from here on.

    Thanks for your help.

    Ed.
    #@MetaDataStart
    #@DetailDescriptionStart
    #############################################################################
    # Extreme Networks(R) CLI Scripting Library
    #
    # Script : Trap Suppression
    # Revision : 1.0
    # Last Updated : October 16 2017
    #
    # Used to disable certain trap OIDs in a mib-view in order to suppress specific traps
    # usually because they are endemic or we just don't care about them or don't want to
    # overload the Alarm systems.
    #
    # Current relevant traps are:
    # 1.3.6.1.4.1.1916.0.6 extremeOverheat
    # 1.3.6.1.4.1.1916.0.7 extremeFanFailed
    # 1.3.6.1.4.1.1916.0.8 extremeFanOK
    # 1.3.6.1.4.1.1916.1.4.13.2.0.1 extremePortMauChangeTrap
    #
    #####################################################################
    #@DetailDescriptionEnd
    #############################################################################################
    # Define identity management configuration parameters in this section.
    #############################################################################################
    #@SectionStart (description = Script configuration properties)
    #@VariableFieldLabel ( description = "Trap OID List",
    # type = String,
    # scope = global,
    # required = yes,
    # readonly = no
    #)
    set var trapOidList 1.3.6.1.4.1.1916.0.7:exclude,1.3.6.1.4.1.1916.0.8:exclude
    #@VariableFieldLabel (description = "Target MIB View"
    # type = String,
    # scope = global
    # )
    set var targetMibView AccessSwitchTraps
    #@SectionEnd
    #@MetaDataEnd
    import os
    print('Hello world! ' + os.getcwd())
    for key, value in emc_vars.items() :
    print (key, value)
    print("trapOidList is " + emc_vars["trapOidList"])
    print("targetMibView is " + emc_vars["targetMibView"])[/code]=====================================================================

    Script output was as follows:
    Date and Time: 2017-11-06T10:31:43.730
    EMC User: 1101286
    EMC User Domain:
    IP: 10.130.254.20
    Hello world! /usr/local/Extreme_Networks/NetSight/wildfly/bin
    (u'date', u'2017-11-06')
    (u'log4j.configuration', u'file:./log4j.properties')
    (u'serverVersion', u'8.0.3')
    (u'isExos', u'true')
    (u'devicePwd', u'blindmickeymcgrew')
    (u'USE_NETSNMP', u'true')
    (u'enterasys.tomcat.http.port', u'8080')
    (u'enterasys.tomcat.https.port', u'8443')
    (u'javax.script.name', u'Python')
    (u'managementPorts', u'')
    (u'deviceName', u'Highland ES IDF1.20')
    (u'deviceId', 297)
    (u'javax.script.engine_version', u'2.7.0')
    (u'deviceVR', u'VR-Default')
    (u'javax.script.language', u'python')
    (u'STATUS', 1)
    (u'serverIP', u'10.254.231.12')
    (u'scriptOwner', u'')
    (u'auditLogEnabled', u'')
    (u'deviceType', u'EXOS Stack-V80')
    (u'interSwitchPorts', u'1:25,1:32,1:38,1:45,4:6,3:16,3:19,3:22,3:26,2:2,3:27,2:5,3:34,2:25,2:32')
    (u'WmInfoHistory.ProcessEndSystemEvents', u'true')
    (u'enterasys.mysqlrealm.rpt.password', u'enterasys')
    (u'enterasys.tomcat.ciphers', u'TLS_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384,ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-AES128-SHA256,ECDHE-RSA-AES128-SHA256')
    (u'targetMibView', u'AccessSwitchTraps')
    (u'accessPorts', u'1:24,2:48,1:26,1:27,1:28,1:29,1:30,1:31,1:33,1:34,1:35,1:36,1:37,1:39,1:40,1:41,1:42,1:43,1:44,1:46,1:47,1:48,4:1,4:2,4:3,4:4,4:5,4:7,4:8,4:9,4:10,4:11,4:12,4:13,4:14,4:15,4:16,4:17,4:18,4:19,4:20,4:21,4:22,4:23,4:24,3:1,4:25,3:2,4:26,3:3,4:27,3:4,4:28,3:5,4:29,3:6,4:30,3:7,4:31,3:8,4:32,3:9,4:33,3:10,4:34,3:11,4:35,3:12,4:36,3:13,4:37,3:14,4:38,3:15,4:39,4:40,3:17,4:41,3:18,4:42,4:43,3:20,4:44,3:21,4:45,4:46,3:23,4:47,3:24,4:48,3:25,2:1,2:3,3:28,2:4,3:29,3:30,2:6,3:31,2:7,3:32,2:8,3:33,2:9,2:10,3:35,2:11,3:36,2:12,3:37,2:13,3:38,2:14,3:39,2:15,3:40,2:16,3:41,2:17,3:42,2:18,3:43,2:19,3:44,2:20,3:45,2:21,3:46,2:22,3:47,2:23,3:48,2:24,1:1,1:2,2:26,1:3,2:27,1:4,2:28,1:5,2:29,1:6,2:30,1:7,2:31,1:8,1:9,2:33,1:10,2:34,1:11,2:35,1:12,2:36,1:13,2:37,1:14,2:38,1:15,2:39,1:16,2:40,1:17,2:41,1:18,2:42,1:19,2:43,1:20,2:44,1:21,2:45,1:22,2:46,1:23,2:47')
    (u'enterasys.jboss.log4j.logfile', u'../../appdata/logs/server.log')
    (u'domain', u'')
    (u'enterasys.embeddednac.enable', u'false')
    (u'nmsMobile.demoMode', u'false')
    (u'enterasys.mysqlrealm.password', u'enterasys')
    (u'endsystem.detail.mapping', u'moref=custom1,uuid=custom1')
    (u'enterasys.webservices.queryendsystems', u'true')
    (u'trapOidList', u'1.3.6.1.4.1.1916.0.7:exclude,1.3.6.1.4.1.1916.0.8:exclude')
    (u'enterasys.mysqlrealm.rpt.username', u'netsight')
    (u'enterasys.mysqlrealm.username', u'netsight')
    (u'deviceASN', u'4269997588')
    (u'deviceSysOid', u'1.3.6.1.4.1.1916.2.93')
    (u'enterasys.datasource.connectionurl', u'jdbc:mysql://127.0.0.1:4589/netsight?jdbcCompliantTruncation=false&useUnicode=true&characterEncoding=UTF-8&useSSL=false')
    (u'java.security.manager', u'')
    (u'deviceLogin', u'netsight')
    (u'serverName', u'10.254.18.218')
    (u'deviceSoftwareVer', u'15.6.3.1')
    (u'ports', u'1:24,2:48,1:25,1:26,1:27,1:28,1:29,1:30,1:31,1:32,1:33,1:34,1:35,1:36,1:37,1:38,1:39,1:40,1:41,1:42,1:43,1:44,1:45,1:46,1:47,1:48,4:1,4:2,4:3,4:4,4:5,4:6,4:7,4:8,4:9,4:10,4:11,4:12,4:13,4:14,4:15,4:16,4:17,4:18,4:19,4:20,4:21,4:22,4:23,4:24,3:1,4:25,3:2,4:26,3:3,4:27,3:4,4:28,3:5,4:29,3:6,4:30,3:7,4:31,3:8,4:32,3:9,4:33,3:10,4:34,3:11,4:35,3:12,4:36,3:13,4:37,3:14,4:38,3:15,4:39,3:16,4:40,3:17,4:41,3:18,4:42,3:19,4:43,3:20,4:44,3:21,4:45,3:22,4:46,3:23,4:47,3:24,4:48,3:25,2:1,3:26,2:2,3:27,2:3,3:28,2:4,3:29,2:5,3:30,2:6,3:31,2:7,3:32,2:8,3:33,2:9,3:34,2:10,3:35,2:11,3:36,2:12,3:37,2:13,3:38,2:14,3:39,2:15,3:40,2:16,3:41,2:17,3:42,2:18,3:43,2:19,3:44,2:20,3:45,2:21,3:46,2:22,3:47,2:23,3:48,2:24,1:1,2:25,1:2,2:26,1:3,2:27,1:4,2:28,1:5,2:29,1:6,2:30,1:7,2:31,1:8,2:32,1:9,2:33,1:10,2:34,1:11,2:35,1:12,2:36,1:13,2:37,1:14,2:38,1:15,2:39,1:16,2:40,1:17,2:41,1:18,2:42,1:19,2:43,1:20,2:44,1:21,2:45,1:22,2:46,1:23,2:47')
    (u'java.security.policy', u'../server/default/conf/server.policy')
    (u'oneView.responsetime.app.redline', u'1000')
    (u'oneView.responsetime.tcp.redline', u'1000')
    (u'vendor', u'Extreme')
    (u'USE_IPV6', u'true')
    (u'enterasys.datasource.rpt.connectionurl', u'jdbc:mysql://127.0.0.1:4589/netsightrpt?jdbcCompliantTruncation=false&useUnicode=true&characterEncoding=UTF-8&useSSL=false')
    (u'javax.script.filename', u'/usr/local/Extreme_Networks/NetSight/appdata/scripting/overrides/hworld.py')
    (u'dashboard.cache.time', u'2')
    (u'javax.script.engine', u'python')
    (u'deviceIP', u'10.130.254.20')
    (u'jboss.bind.address', u'10.254.231.12')
    (u'userDomain', u'')
    (u'OneView.DisplayNacConfigurationTab', u'true')
    (u'userName', u'1101286')
    (u'scriptTimeout', u'60')
    (u'time', u'10:31:43 EST')
    (u'family', u'Summit Series')
    (u'username', u'root')
    trapOidList is 1.3.6.1.4.1.1916.0.7:exclude,1.3.6.1.4.1.1916.0.8:exclude
    targetMibView is AccessSwitchTraps[/code]



  • 4.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 15:47
    EXOS does have the ability to pass script from a server and run them without actually transferring the script file to the switch first.

    EMC currently does not support this but it can be done independent of EMC.

    If you are interested, I can put an example together.



  • 5.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    Take a look at https://github.com/extremenetworks/ExtremeScripting/tree/master/EXOS/Python/rmtscript

    Your switches must be running EXOS 21.1 or later for this to work.
    It also requires:
    - a python environment on your server
    - the requests python package installed on your server


  • 6.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-08-2017 19:53
    If you've had a chance to look at the example, do you have any feedback?


  • 7.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-28-2017 14:36
    https://github.com/extremenetworks/EXOS_Apps/tree/master/JSONRPC includes a number of remote access topics using the EXOS JSONRPC interface and provides a more comprehensive Python jsonrpc.py class for python automation developers.

    There is a client app jsonrpc_client.py that can be used as a JSONRPC CLI shell and/or a remote script tool. It also serves as an example for Python developers implementing their own EXOS JSONRPC applications.

    jsonrpc_client.py supports
    • Command line options for multiple IP addresses, or specify a file with multiple IP addresses
    • Command line option for a single CLI to send to multiple switches or specify a file with multiple EXOS commands
    • Command line option for a EXOS script file to send to multiple swithes
    • Interactive option for EXOS CLI to send to multiple IP addresses
    • interactive option to enter EXOS script names and their command line parameters


  • 8.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 14:40
    Regarding "Seems a little weird to have a TCL style "set var" command at the top of some python but "whatever!"."

    Yes. That should be changed in a future release.

    nice password :)



  • 9.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 15:47
    I am definitely interested Dave - just depends on how much work it is for you.

    We need some more resources so that this tremendously powerful toolset gets better utilized ( and it's also a lot more fun than endless typing ).


  • 10.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 15:47
    Stay tuned, more to come... even better! :)


  • 11.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 15:47
    Hi Dave,

    I'd be interested in an example as well.

    Did you allude to the JSON-RPC interface to EXOS?

    Edit: I've been reading the thread from the top down, the example has been provided and my question answered (yes, it is JSON-RPC) below. Thanks. :-)

    Thanks,
    Erik


  • 12.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    Hi Dave,

    What is the cause for CLI returning "request() got an unexpected keyword argument 'json'"


  • 13.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    Could you provide a little more information about what you are doing?

    CLI doesn't process scripts, so I'm a bit confused by the mention of CLI with the python call request().


  • 14.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    I followed the instruction -> https://github.com/extremenetworks/ExtremeScripting/tree/master/EXOS/Python/rmtscript

    If i call "sample.py -a -b def", then I get the error from above


  • 15.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    On your server, you ran:
    # python rmtscript.py -i


  • 16.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    Correct.

    My Version is Python 2.7.6



  • 17.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-06-2017 19:57
    I can only guess that the requests python module on your server is older than 2.4.2

    python
    Python 2.7.5 (default, Nov 6 2016, 00:28:07)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>> print requests.__version__
    2.6.0
    >>>[/code]


  • 18.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-08-2017 19:53
    Hi Dave:

    We are still back on 15.6.3 FW at my place ( 2,000 managed devices and probably about 70% is stacks of 2, 3 or 4 ). A lot of politics are holding me back from upgrading so I can't use the RPC-JSON functions any time soon. I am going to load so recent FW on to a test switch so that I can play with it.

    Thanks,

    Ed.


  • 19.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-08-2017 19:53
    FWIW, I just spoke with the XMC (Netsight) manager. This may get incorporated into the eXtreme Management Center (XMC) 8.2 release. So if you do upgrade, it may be the feature you were originally looking for..


  • 20.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-08-2017 19:53
    I had a quick look through the example Dave. Bear in mind that I am brand new to python, have never worked with JSON and haven't done very much programming at all over the last few years.

    Given all of that it looked quite straightforward, a testament to python's clarity. I am not sure I will take this approach though. My original observation was based on a belief that I couldn't run a decent python script from the server with parameters that could be adjusted by a non-programmer and therefore that I would need to use TCL on the server to run python on the switch ( I definitely wanted to move away from doing much in TCL ). I was wrong about that.

    If I can use python on the server, that is preferred for me. We don't have a collection of existing python switch scripts that we would want to leverage. I am going to use python on the switch but it will be for port related scripting.

    In any event, it's nice to have several options.


  • 21.  RE: Python Scripts Executing from Netsight - Clarification Needed

    Posted 11-08-2017 19:53
    A lot of things are coming for Python in ExtremeManagement. Stay tuned.