Event-handler script

The all_ports_down.py script below was deployed—as a temporary workaround—to ensure that if a port-channel is shut down the members are also shut down.

Note

Note

To access this script and related resources, refer to https://github.com/extremenetworks/ExtremeScripting.
#!/usr/local/python/3.5.2/bin/python3
import getopt
import json
import sys
import io
import re
import pdb
from CLI import CLI
int_down_raslog = 'NSM-1020'
int_up_raslog = 'NSM-1019'
shutdown_string = ''
match = None
raslog_triggers = {}
output = ''

# For argument processing:
options, remainder = getopt.gnu_getopt(sys.argv[1:], '', ['raslog-triggers='])

for opt, arg in options:
    if opt in ('--raslog-triggers'):
        print('--raslog-triggers: ', arg)
        output = io.StringIO(arg)
        raslog_triggers = json.load(output)

# Opening a file for logging:
f = open("poout.txt", "a")
f.write("testing:\n")

def po_members(po_num, shutdown_str):
# Determines the physical members of the port-channel and executes 
# a shutdown/no shutdown command as requested for each physical interface:
    print("inside po_members", po_num, shutdown_str)
    f.write("inside po_members" + str(po_num) + str(shutdown_str))
    members = []
# Executing the show port-channel CLI and matching the output:
    poCLI = "show port-channel " + str(po_num) + " | begin Link:"
    output = CLI(poCLI, do_print=False).get_output()
    print("output =\n" + str(output))
    f.write("output = \n" + str(output))

# Iterating over each interface found in the output, and executing the
# appropriate configuration commands:
    for entry in output:
        print(entry)
        str1 = "".join(entry)
        str1 = str1.lstrip()
        print(str1.startswith("Link"))
        if str1.startswith("Link"):
            phy = str1.split("Link: ")[1].split("(0x")[0]
            members.append(phy)
            command = "config term\nint " + phy + "\n" + str(shutdown_str)
            output = CLI(command, do_print=False).get_output()
            print("cli output = " + command + "\n" + str(output))
            f.write("cli output = " + command + "\n" + str(output))
            str1 = ""
    return members

# The following section uses the passed information from the event-handler
# and calls po_members with the correct information:
print('raslog_triggers:\n', str(raslog_triggers))
f.write("raslog_triggers:\n" + str(raslog_triggers) + '\n')
if int_down_raslog in raslog_triggers:
    shutdown_string = 'shutdown'
    match = re.search(r'interface Port-channel (\d+)',
                      raslog_triggers[int_down_raslog], re.IGNORECASE)
elif int_up_raslog in raslog_triggers:
    shutdown_string = 'no shutdown'
    match = re.search(r'interface Port-channel (\d+)',
                      raslog_triggers[int_up_raslog], re.IGNORECASE)

if match:
    po = match.group(1)
    print('Performing operation "' + shutdown_string
          + '" on members for Port-channel ' + po + '\n')
    f.write('Performing operation "' + shutdown_string
            + '" on members for Port-channel ' + po + '\n')
    members = po_members(po, shutdown_string)
    print('\tMembers on Port-channel ' + po + ': ' + str(members) + '\n')
    f.write('\tMembers on Port-channel ' + po + ': ' + str(members) + '\n')

f.close()

Test-run (Event-handler script)

The following command tests the all_ports_down.py script for an NSM-1020 RASLOG:
device# python all_ports_down.py --raslog-triggers {"NSM-1020":"interface Port-channel 10 is administratively down."}
The following command tests the all_ports_down.py script for an NSM-1019 RASLOG:
device# python all_ports_down.py --raslog-triggers {"NSM-1019":"interface Port-channel 10 is administratively up."}
To verify that the script with "NSM-1019" works correctly, enter the following commands:
device# show port-channel detail 
 LACP Aggregator: Po 10  
 Aggregator type: Standard
  Actor System ID - 0x8000,78-a6-e1-45-95-14
  Admin Key: 0010 - Oper Key 0010
  Receive link count: 4 - Transmit link count: 4
  Individual: 0 - Ready: 1
  Partner System ID - 0x0001,00-24-38-8b-f1-00
  Partner Oper Key 0102
 Flag * indicates: Primary link in port-channel 
 Number of Ports: 4
 Minimum links: 1
 Member ports:
   Link: Eth 0/3 (0xC006000) sync: 1   
   Link: Eth 0/4 (0xC008000) sync: 1   *
   Link: Eth 0/5 (0xC00A000) sync: 1   
   Link: Eth 0/6 (0xC00C000) sync: 1  

device# flex-cli show interface brief
Port    Link      Port-State    Dupl    Speed       Tag    MAC             Name
po10    Up        N/A           N/A     40000 Mbit  Yes    78a6.e145.9562
po11    Up        N/A           N/A     30000 Mbit  Yes    78a6.e145.9563
lb1     Down      N/A           N/A     N/A         N/A    N/A             N/A
0/1     Disabled  None          None    None        No     78a6.e145.9519  Ifml
0/2     Disabled  None          None    None        No     78a6.e145.951a
0/3     Up        Forward       Full    10000 Mbit  No     78a6.e145.951b
0/4     Up        Forward       Full    10000 Mbit  No     78a6.e145.951c
0/5     Up        Forward       Full    10000 Mbit  No     78a6.e145.951d
0/6     Up        Forward       Full    10000 Mbit  No     78a6.e145.951e
0/7     Up        Forward       Full    10000 Mbit  No     78a6.e145.951f