Note
To access sample scripts and related resources, refer to https://github.com/extremenetworks/ExtremeScripting.Note
Lines beginning with#
are annotations. #Required in all scripts for SLX-OS: from CLI import CLI slot = [0] interfaces = [28, 29, 30, 31] port_channel = 10 vlan_range = "101-105" # Runs show running-config int vlan before the configuration, and assigns this SLX # command to a Python variable named cmd_show_running_vlans. cmd_show_running_vlans = CLI("show running-config vlan") # Configures VLANs. {} is a placeholder for the format (arg1, arg2, ... argN) variables: cmd_configure_vlans = CLI("config \n vlan {}".format(vlan_range)) # Reruns show running-config int vlan, following definition of new VLANs: cmd_show_running_vlans.rerun() # Configures port channel (vLAG): cmd_show_running_port_channels = CLI("show running-config int po") cmd_configure_port_channel = CLI("config \n int po {} \n switchport \n switchport mode trunk \n switchport trunk allowed vlan add {} \n switchport trunk tag native-vlan ; no shut".format(port_channel, vlan_range)) # Reruns show running-config int po, following configuration changes: cmd_show_running_port_channels.rerun() # Adds interfaces to port channel (vLAG) for interface in interfaces: cmd_configure_interface = CLI("config \n int eth {}/{} \n channel-group {} mode active type standard \n no shut".format(slot, interface, port_channel)) cmd_show_running_int_tengig = CLI("show running-config int eth {}/{}".format (slot, interface)) # Runs show running-config: cmd_show_running = CLI("show running-config")
A log upon running create_po.py was as follows:
SLX# python create_po.py !Command: show running-config vlan !Time: Fri Dec 16 18:35:41 2016 vlan 1 ! vlan dot1q tag native !Command: config vlan 101-105 !Time: Fri Dec 16 18:35:41 2016 !Command: show running-config vlan !Time: Fri Dec 16 18:35:41 2016 vlan 1 ! vlan 101 ! vlan 102 ! vlan 103 ! vlan 104 ! vlan 105 ! vlan dot1q tag native !Command: show running-config int po !Time: Fri Dec 16 18:35:41 2016 % No entries found. !Command: config int po 10 switchport switchport mode trunk switchport trunk allowed vlan add 101-105 switchport trunk tag native-vlan ; no shut !Time: Fri Dec 16 18:35:41 2016 !Command: show running-config int po !Time: Fri Dec 16 18:35:42 2016 interface Port-channel 10 switchport switchport mode trunk switchport trunk allowed vlan add 101-105