Extreme API with Python

Table Of Contents
Extreme API with Python
Page | 45
Part no.9036931-00 Rev AA February 2021
Below your endpoint is a VLAN entry which is a list of the VLANs. For each entry in the list, you will see
the element id (in this case, the VLAN id), a state container and a config container.
The Openconfig data model is very consistent, which means that once you understand it, you can easily
access any data: it always follows the same pattern.
To create a VLAN, manipulate the config container following the same structure. To delete a VLAN,
simply point to the endpoint.
from restconf import Restconf
import json
import getpass
import argparse
# manage your arguments
def get_params():
parser = argparse.ArgumentParser(prog = 'RestDemo')
parser.add_argument('-i', '--ip',
help='IP Address of the switch',
required=True)
parser.add_argument('-u', '--username',
help='Login username for the remote system')
parser.add_argument('-p', '--password',
help='Login password for the remote system',
default='')
args = parser.parse_args()
return args
def list_vlans(rest):
# you make a GET API call for all the vlans
info = rest.get('data/openconfig-vlan:vlans')
data = info.json()
vlans = data.get('openconfig-vlan:vlans').get('vlan')
for vlan in vlans:
print("Found VLAN {} with VID {}".format(vlan.get('state').get('name'), v
lan.get('vlan-id')))
def main():
args = get_params()