Extreme API with Python

Table Of Contents
Extreme API with Python
Page | 50
Part no.9036931-00 Rev AA February 2021
3.2.2.3 Using JSON-RPC with Python
As with the RESTCONF API, a Python class is proposed on the Extreme Networks github to facilitate its
use.
HTTPS://github.com/extremenetworks/EXOS_Apps/blob/master/JSONRPC/jsonrpc.py
Note: At the time of writing of this document, the latest version of the JSON-RPC class is 2.0.0.4.
The class uses different methods, depending on the use case. The most common method is using CLI
commands. This is not the only solution, however, and you can also use it to remotely run scripts on a
switch or run a Python application. Scripts that you run remotely on a switch are not present on the
switch but live instead in your system. This method handles the transfer to the switch for you.
This section describes the CLI method, which is the most common method.
Note: The JSON-RPC Python class is included by default with XMC Scripting Engine since XMC 8.2.
First, create a few VLANs on a switch (or VM) using the provided Python class. To make things a bit
different from previous examples, in this example, you manipulate a file as the input for your
application. The file must contain the CLI commands, one per line, that you want to run on a switch.
Name the CLI commands file cmds.txt:
create vlan 10-15
config vlan 10-15 add port 1 tag
show vlan port 1
The following example shows one way to code your application:
from jsonrpc import JsonRPC
import argparse
import getpass
import json
# manage your arguments
def get_params():
parser = argparse.ArgumentParser(prog = 'JSONRPCDemo')
parser.add_argument('-i', '--ip',
help='IP Address of the switch',
required=True)
parser.add_argument('-f', '--filename',
help='Filename with valid EXOS CLI commands',
required=True)
parser.add_argument('-u', '--username',
help='Login username for the remote system')