Nexus
Problem Statement
- N6001 boot up sequence was causing ESX host to lose connectivity
- N6001 brings the uplink ports up 2-3 minutes after the host ports
- NX-OS Software is not able to change the boot up sequence because this is part of the second module (non-removable)
EEM script to trigger Python Policy
event manager applet link_reboot
event syslog pattern "Module 1 current-status is"
action 1 syslog priority critical msg Running linkchange4 down
action 2 cli python bootflash:linkchange4.py down
event manager applet link_up
event track 30 state up
action 1 syslog priority critical msg Running linkchange4 up
action 2 cli python bootflash:linkchange4.py up
Python Script to collect port state, bring them down and bring them up
#!/usr/bin/python
import sys
import os
import re
from cisco import cli
hostlistfile = "hostlist"
try:
sys.argv[1]
except IndexError:
print "Error: Missing argument, need either 'up' or 'down'"
exit()
if sys.argv[1] == "up":
# At this point we should have a file containing ports to bring up.
if os.path.isfile(hostlistfile) == False:
print "No hostlist found, exiting"
exit()
file = open(hostlistfile, "r")
line = file.readline()
while line != "":
stripped = line.rstrip('\n')
cli("config terminal ; interface %s ; no shutdown" % stripped)
line = file.readline()
#We are now done with the hostlist file, lets delete.
os.remove(hostlistfile)
if sys.argv[1] == "down":
# Uplinks are not yet up, lets see which hosts are active, bring those
# down and save to a file.
f = open(hostlistfile, "w")
print "Generating host list dynamically."
result = cli("show interface")
for rline in result[1].split('\n'):
match = re.match(r'^(Ethernet[\S]+).*', rline)
if match:
#Check name against Ethenert2/ we will skip these uplinks.
match2 = re.match(r'Ethernet2/.*', match.group(1))
if match2:
continue
# If we made it this far, check state then adjust
match3 = re.match(r'Ethernet1/.*', match.group(1))
if match3:
match4 = re.match(r'.*(Administratively down|SFP not inserted).*', rline)
if match4 == None:
f.write(match.group(1))
f.write('\n')
#Change state
cli("config t ; interface %s ; shutdown" % match.group(1))
f.close()