def ha_failover_check_frame_log(times=1): """ """ sw_info = anturlar.SwitchInfo() #fid_now = sw_info.ls_now() ip_addr = sw_info.ipaddress() go_or_not = sw_info.synchronized() cons_out = anturlar.fos_cmd(" ") username = '******' pwrd = 'password' #counter = 1 new_connect = True liabhar.count_down(10) while times > 0: cofra.ha_failover(1) print("\n\n\n") print("@"*60) print("HA Failovers remaining -- %s " % times) print("@"*60) anturlar.connect_tel_noparse(ip_addr,'root','password') times -= 1 flog_status = maps_tools.frameview_status() print("$"*80) print("$"*80) print(flog_status) print("$"*80) print("$"*80) if 'Enabled' in flog_status: print("Framelog is Enabled") elif 'Disabled' in flog_status: print("Framelog is Disabled") sys.exit() else: print("Framelog State is UnKnown") return(flog_status)
def ha_failover_check_frame_log(times=1): """ """ sw_info = anturlar.SwitchInfo() #fid_now = sw_info.ls_now() ip_addr = sw_info.ipaddress() go_or_not = sw_info.synchronized() cons_out = anturlar.fos_cmd(" ") username = '******' pwrd = 'password' #counter = 1 new_connect = True liabhar.count_down(10) while times > 0: cofra.ha_failover(1) print("\n\n\n") print("@"*60) print("HA Failovers remaining -- %s " % times) print("@"*60) anturlar.connect_tel_noparse(ip_addr,'root','password') times -= 1 flog_status = maps_tools.frameview_status() print("$"*80) print("$"*80) print(flog_status) print("$"*80) print("$"*80) if 'Enabled' in flog_status: print("Framelog is Enabled") elif 'Disabled' in flog_status: print("Framelog is Disabled") sys.exit() else: print("Framelog State is UnKnown") return(flog_status)
def fcr_state_persist_enabled_switch_disable(fcr, si): anturlar.fos_cmd("switchdisable") print('\n\nSleeping: 10') liabhar.count_down(10) anturlar.fos_cmd("switchenable") liabhar.count_down(3) fcrstate = fcr_state(fcr) if fcrstate == True: print("\n\nENABLE/DISABLE TEST PASSED") else: print("\n\nENABLE/DISABLE TEST FAILED") print("Please check switch logs") sys.exit()
def fcr_state_persist_enabled_switch_disable(fcr, si): anturlar.fos_cmd("switchdisable") print('\n\nSleeping: 10') liabhar.count_down(10) anturlar.fos_cmd("switchenable") liabhar.count_down(3) fcrstate = fcr_state(fcr) if fcrstate == True: print("\n\nENABLE/DISABLE TEST PASSED") else: print("\n\nENABLE/DISABLE TEST FAILED") print("Please check switch logs") sys.exit()
def def_zone_reset(fid1, fid2): si = anturlar.SwitchInfo() sleep = liabhar.count_down(3) g = [fid1, fid2] for i in g: anturlar.fos_cmd("setcontext %s" % i) a = str(si.ae_ports()) b = a.strip('[') b = b.strip(']') index = (b[0]) port = (b[1]) reg_ex = [b"no] "] ### Needs to be square brackets to send as a list z = anturlar.fos_cmd_regex( "defzone --allaccess", reg_ex, 9) #### use regex because return is something other than "root:" anturlar.fos_cmd("yes") sleep y = anturlar.fos_cmd_regex("cfgsave", reg_ex, 9) anturlar.fos_cmd("yes") sleep for i in port: anturlar.fos_cmd(" portdisable %s" % port) sleep anturlar.fos_cmd(" portenable %s" % port) sleep anturlar.fos_cmd("switchshow") sys.exit()
def def_zone_reset(fid1, fid2): si = anturlar.SwitchInfo() sleep = liabhar.count_down(3) g = [fid1, fid2] for i in g: anturlar.fos_cmd("setcontext %s" % i) a = str(si.ae_ports()) b = a.strip('[') b = b.strip(']') index = (b[0]) port = (b[1]) reg_ex = [b"no] "] ### Needs to be square brackets to send as a list z = anturlar.fos_cmd_regex("defzone --allaccess", reg_ex, 9) #### use regex because return is something other than "root:" anturlar.fos_cmd("yes") sleep y = anturlar.fos_cmd_regex("cfgsave", reg_ex, 9) anturlar.fos_cmd("yes") sleep for i in port: anturlar.fos_cmd(" portdisable %s" % port) sleep anturlar.fos_cmd(" portenable %s" % port) sleep anturlar.fos_cmd("switchshow") sys.exit()
def add_remove_flow(repeat, fname, scr, dst, ingrp, egrp, feat): """ add and remove a flow from the current switch and FID --should add find one of the ports on the switch and add the flow to that port - --discover which port is the same as the scrdev or dstdev and add -- since this is a add and remove the flow test case the lun, ftype and bidir could be random """ ####cmd = "supportsave -n -u %s -p %s -h %s -l ftp -d %s" % (variables, variables) cmd_create = "flow --create %s -fea %s -srcdev %s -dstdev %s" % ( fname, feat, scr, dst) if ingrp != "na": cmd_create = "%s -ingrport %s" % (cmd_create, ingrp) if egrp != "na": cmd_create = "%s -egrport %s " % (cmd_create, egrp) cmd_delete = "flow --delete %s " % (fname) cons_out = anturlar.fos_cmd(cmd_create) while repeat > 0: #print(repeat,"\n") cons_out = anturlar.fos_cmd(cmd_create) cons_out = anturlar.fos_cmd("flow --show") liabhar.count_down(3600) cons_out = anturlar.fos_cmd(cmd_delete) cons_out = anturlar.fos_cmd("flow --show") print("\n\n", cons_out) liabhar.count_down(300) repeat = repeat - 1 return 0
def add_remove_flow(repeat, fname, scr, dst, ingrp, egrp, feat): """ add and remove a flow from the current switch and FID --should add find one of the ports on the switch and add the flow to that port - --discover which port is the same as the scrdev or dstdev and add -- since this is a add and remove the flow test case the lun, ftype and bidir could be random """ ####cmd = "supportsave -n -u %s -p %s -h %s -l ftp -d %s" % (variables, variables) cmd_create = "flow --create %s -fea %s -srcdev %s -dstdev %s" % ( fname,feat,scr,dst) if ingrp != "na": cmd_create = "%s -ingrport %s" % ( cmd_create, ingrp ) if egrp != "na": cmd_create = "%s -egrport %s " % ( cmd_create, egrp ) cmd_delete = "flow --delete %s " % (fname) cons_out = anturlar.fos_cmd(cmd_create) while repeat > 0: #print(repeat,"\n") cons_out = anturlar.fos_cmd(cmd_create) cons_out = anturlar.fos_cmd("flow --show") liabhar.count_down(3600) cons_out = anturlar.fos_cmd(cmd_delete) cons_out = anturlar.fos_cmd("flow --show") print("\n\n",cons_out) liabhar.count_down(300) repeat = repeat - 1 return 0
def check_gen_all_stats(): """ start the gen_all SIM ports test and capture the number of runs the percent of run, the frames generated brom IngrPort and frames generated to EgrPort """ sw_info = anturlar.SwitchInfo() sw_info_ls = sw_info.ls() fid_now = sw_info.ls_now() sw_ip = sw_info.ipaddress() fv = anturlar.FlowV() fv.toggle_all() #### default is to turn all ports to SIM ports fv.genAll("on") f = "%s%s%s" % ("logs/Gen_all_stats_test_case_file", sw_ip, ".txt") clear = 0 if clear == 1: ff = liabhar.FileStuff(f, 'w+b') #### reset the log file else: ff = liabhar.FileStuff(f, 'a+b') #### open for appending st = "Runs Percent Ingrport Egrport \n" header = "%s%s%s%s" % ("\nGEN ALL CAPTURE FILE \n", " sw_info ipaddr ", sw_ip, "\n==============================\n\n") ff.write(header) ff.write(st) d = 0 while d <= 1000: stats = fv.genAllStats() print(stats) print("run number %s" % d) ff.write(stats) liabhar.count_down(60) d += 1 ff.close()
def check_gen_all_stats(): """ start the gen_all SIM ports test and capture the number of runs the percent of run, the frames generated brom IngrPort and frames generated to EgrPort """ sw_info = anturlar.SwitchInfo() sw_info_ls = sw_info.ls() fid_now = sw_info.ls_now() sw_ip = sw_info.ipaddress() fv = anturlar.FlowV() fv.toggle_all() #### default is to turn all ports to SIM ports fv.genAll("on") f = "%s%s%s"%("logs/Gen_all_stats_test_case_file",sw_ip,".txt") clear = 0 if clear == 1 : ff = liabhar.FileStuff(f, 'w+b') #### reset the log file else: ff = liabhar.FileStuff(f, 'a+b') #### open for appending st = "Runs Percent Ingrport Egrport \n" header = "%s%s%s%s" % ("\nGEN ALL CAPTURE FILE \n", " sw_info ipaddr ",sw_ip, "\n==============================\n\n") ff.write(header) ff.write(st) d=0 while d <= 1000: stats = fv.genAllStats() print(stats) print("run number %s" % d) ff.write(stats) liabhar.count_down(60) d += 1 ff.close()
def firmwaredownload(frmdwn, frmup): """ uses cofra firmwaredownload to do testing for update to newest code the test will load first firmware and return to the other on a second download command """ capture_cmd = anturlar.fos_cmd("ipaddrshow") #match = re.search('(?P<ipaddress>[\s+\S+]+:([\d\.]){7,15}(?=\\r\\n))', capture_cmd) match = re.search('(?P<pre>([\s+\w+]+):\s?(?P<ip>[0-9\.]{1,15}))', capture_cmd) if match: myip = (match.group('ip')) #return(myip) else: print("\n\n NO IP FOUND \n\n") #return (0) while True: #f = cofra.doFirmwareDownload(frmdwn) capture_cmd = anturlar.fos_cmd("version") f = cofra.DoFirmwaredownloadChoice(frmdwn, frmup) liabhar.count_down(600) anturlar.connect_tel_noparse(myip, 'root', 'password') #en = anturlar.SwitchInfo() capture_cmd = anturlar.fos_cmd("version") f = cofra.DoFirmwaredownloadChoice(frmdwn, frmup) anturlar.connect_tel_noparse(myip, 'root', 'password') #en = anturlar.SwitchInfo() return (0)
def firmwaredownload(frmdwn, frmup): """ uses cofra firmwaredownload to do testing for update to newest code the test will load first firmware and return to the other on a second download command """ capture_cmd = anturlar.fos_cmd("ipaddrshow") #match = re.search('(?P<ipaddress>[\s+\S+]+:([\d\.]){7,15}(?=\\r\\n))', capture_cmd) match = re.search('(?P<pre>([\s+\w+]+):\s?(?P<ip>[0-9\.]{1,15}))', capture_cmd) if match: myip = (match.group('ip')) #return(myip) else: print("\n\n NO IP FOUND \n\n") #return (0) while True: #f = cofra.doFirmwareDownload(frmdwn) capture_cmd = anturlar.fos_cmd("version") f = cofra.DoFirmwaredownloadChoice(frmdwn,frmup) liabhar.count_down(600) anturlar.connect_tel_noparse(myip, 'root', 'password') #en = anturlar.SwitchInfo() capture_cmd = anturlar.fos_cmd("version") f = cofra.DoFirmwaredownloadChoice(frmdwn, frmup) anturlar.connect_tel_noparse(myip, 'root', 'password') #en = anturlar.SwitchInfo() return(0)
def ha_failover(times=1): """ do HA failover on directors do hareboot on pizza box """ #### steps #### 1. Determine Pizza box or Director #### 2. save username and password #### 3. HA Failover or HA reboot #### 4. wait some time #### 5. reconnect sw_info = anturlar.SwitchInfo() print(sw_info) ip_addr = sw_info.ipaddress() chassis = sw_info.am_i_director #sys.exit() while times > 0: print("\n\n\n") print("@" * 60) print("HA Failovers remaining -- %s " % times) print("@" * 60) times -= 1 liabhar.count_down(10) if chassis: capture = anturlar.fos_cmd("echo Y | hafailover") else: capture = anturlar.fos_cmd("hareboot") liabhar.count_down(300) tn = anturlar.connect_tel_noparse(ip_addr, 'root', 'password') switch_sync = sw_info.synchronized() print("\n\n") print("@" * 60) print("VALUE OF switch_sync is -- %s " % switch_sync) print("@" * 60) while switch_sync is False: liabhar.count_down(120) switch_sync = sw_info.synchronized() print("\n\n") print("@" * 60) print("The VALUE OF switch_sync is -- %s " % switch_sync) print("@" * 60) return (tn)
def ha_failover( times=1): """ do HA failover on directors do hareboot on pizza box """ #### steps #### 1. Determine Pizza box or Director #### 2. save username and password #### 3. HA Failover or HA reboot #### 4. wait some time #### 5. reconnect sw_info = anturlar.SwitchInfo() print(sw_info) ip_addr = sw_info.ipaddress() chassis = sw_info.am_i_director #sys.exit() while times > 0: print("\n\n\n") print("@"*60) print("HA Failovers remaining -- %s " % times) print("@"*60) times -= 1 liabhar.count_down(10) if chassis: capture = anturlar.fos_cmd("echo Y | hafailover") else: capture = anturlar.fos_cmd("hareboot") liabhar.count_down(300) tn = anturlar.connect_tel_noparse(ip_addr,'root','password') switch_sync = sw_info.synchronized() print("\n\n") print("@"*60) print("VALUE OF switch_sync is -- %s " % switch_sync) print("@"*60) while switch_sync is False: liabhar.count_down(120) switch_sync = sw_info.synchronized() print("\n\n") print("@"*60) print("The VALUE OF switch_sync is -- %s " % switch_sync) print("@"*60) return(tn)
def ports_toggle(portlist="", t=2, wait=10): """ port disable / port enable for the number of times passed in """ #### this is for pizza box #### need to add chassis #### if portlist == "": si = anturlar.SwitchInfo() portlist = si.all_ports() for x in range(1, t): for a in portlist: cons_out = anturlar.fos_cmd("portdisable %s"%a) liabhar.count_down(wait) for a in portlist: cons_out = anturlar.fos_cmd("portenable %s"%a) liabhar.count_down(10) liabhar.count_down(wait)
def ports_toggle(portlist="", t=2, wait=10): """ port disable / port enable for the number of times passed in """ #### this is for pizza box #### need to add chassis #### if portlist == "": si = anturlar.SwitchInfo() portlist = si.all_ports() for x in range(1, t): for a in portlist: cons_out = anturlar.fos_cmd("portdisable %s" % a) liabhar.count_down(wait) for a in portlist: cons_out = anturlar.fos_cmd("portenable %s" % a) liabhar.count_down(10) liabhar.count_down(wait)
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@" * 40) print("@" * 40) ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) cons_info = sw_matrix_tools.console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet #### if you want to connect to the console it is available in anturlar and an example below #### #### ###################################################################################################################### ###################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) cons_out = anturlar.fos_cmd( "setcontext %s " % pa.fid) #### change to the fid given on the command cons_out = anturlar.fos_cmd( "firmwareshow") #### send any command with anturlar.fos_cmd print("\r\n") liabhar.JustSleep(30) #### sleep without printing anything print("now closing telnet session ") anturlar.close_tel() #### close the telnet session liabhar.JustSleep(30) ####################################################################################################################### ####################################################################################################################### #### #### connect via console example #### #### ####################################################################################################################### ####################################################################################################################### #tn = anturlar.connect_console(console_ip,console_port) #### use the console ip and console port info #cons_out = anturlar.fos_cmd("switchshow") #### send a command via the console # ##cons_out = cofra.power_cycle(power_pole_info) #### power cycle the switch using the # #### Switch Matrix info #liabhar.JustSleep(30) #### wait for the switch to boot # # #cons_out = anturlar.send_cmd_console("\r\n") #### send some commands to the console # #### #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) #### #cons_out = anturlar.send_cmd_console("firmwareshow") #### ####################################################################################################################### ####################################################################################################################### #### #### do anything else you want to try #### #### ####################################################################################################################### ####################################################################################################################### dt = liabhar.dateTimeStuff( ) #### create the object for date and time stuff date_is = dt.current() #### get the current time print(date_is) print("Leaving the script\r\n\r\n") liabhar.count_down(30) #### count down to the next command
def main(): global tn ############################################################################### #### #### #### ############################################################################### pa = parse_args(sys.argv) #print(pa) #print(pa.chassis_name) #print(pa.ipaddr) #print(pa.quiet) #print(pa.verbose) #print(pa.firmware) #print(porttype) #print("@"*40) #sys.exit() ########################################################################## ########################################################################## ### ### hold the ip address from the command line ### if pa.ipaddr: pa.chassis_name = console_info_from_ip(pa.ipaddr, pa.chassis_name) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] tn = anturlar.connect_tel_noparse(pa.ipaddr,user_name,usr_psswd) fi = anturlar.FabricInfo() si = anturlar.SwitchInfo() #fcr = anturlar.FcrInfo() if pa.fabwide: ipaddr_switch = fi.ipv4_list() elif pa.csvall: ipaddr_switch = get_ip_from_file(pa.chassis_name) elif pa.fcrwide: anturlar.fos_cmd("setcontext %s" % fcr.base_check()) ipaddr_switch = fcr.fcr_fab_wide_ip() else: ipaddr_switch = [pa.ipaddr] anturlar.close_tel() #### pass ip(s)to login procedure #### and write the file for i in ipaddr_switch: try: tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd) except OSError: print("Switch %s not available" % i) # f_ports = si.f_ports() # e_ports = si.e_ports() # print(f_ports) # print(e_ports) # sys.exit() #fabric_check = fi.fabric_members() cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) dt = liabhar.dateTimeStuff() #### create the object for date and time stuff date_is = dt.current_no_dash_at_end() #### get the current time for file naming purposes #print("\n\nDate is %s" % date_is) effectivezone = fi.zone_info(123) print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") print(effectivezone) sys.exit() liabhar.count_down(1) #### count down to the next command #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2") f = "%s%s%s%s"%("logs/Extensive_Zoning_test_case_file_orig","_"+i+"_",date_is,".txt") f1 = "%s%s%s%s"%("logs/Extensive_Zoning_test_case_file_compare","_"+i+"_",date_is,".txt") f2 = "%s%s%s%s"%("logs/Extensive_original_zone","_"+i+"_",date_is,".txt") #### open f2 write original zone "cfgshow" so we can put the switch back to original zone cfg ff = liabhar.FileStuff(f2, 'w+b') header = "%s%s%s%s" % ("\nORIGINAL ZONING CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch, "\n==============================\n\n") #### write a header line at top of file ff.write(header) ff.write(anturlar.fos_cmd("cfgshow")) ff.close() #### open f (Write original extensive zoning switchconfig, nsshow, nsallshow and config show for comparison later) ff = liabhar.FileStuff(f, 'w+b') ff.write(anturlar.fos_cmd("nsshow")) ff.write(anturlar.fos_cmd("nsallshow")) ff.write(anturlar.fos_cmd("configshow")) ff.close() # g = open(f, "r") # lines = g.readlines() # g.close() # ff = liabhar.FileStuff(f, 'w+b') # for l in lines: # if " date = " not in l: # ff.write(l) # ff.close() # f = ('logs/PortFlapper.txt') # try: # with open(f, 'w') as file: # file.write("F-Ports = %s\n" % str(fports)) # file.write("E-Ports = %s\n" % str(eports)) # except IOError: # print("\n\nThere was a problem opening the file:" , f) # sys.exit() # file.close() print(eports) ################ if...else statement to use eport or fport for i in eports: slot = i[0] port = i[1] if slot: anturlar.fos_cmd("portdisable %s/%s" % (slot, port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s/%s" % (slot, port)) liabhar.count_down(15) else: anturlar.fos_cmd("portdisable %s" % (port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s" % (port)) liabhar.count_down(15) fabric_check1 = fi.fabric_members() if fabric_check != fabric_check1: print ("WTF") #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" ) liabhar.email_sender_html("*****@*****.**","*****@*****.**","portflapper failed","portflapper failed","") sys.exit() liabhar.email_sender_html("*****@*****.**","*****@*****.**","portflapper passed","portflapper passed","") anturlar.close_tel() return(True) # else: # print("\n"+"@"*40) # print('\nTHIS IS A NOS SWITCH> SKIPPING') # print("\n"+"@"*40) # pass anturlar.close_tel() sys.exit()
def main(): global tn ################################################################################################################### # # start with parsing the command line # # use the procedures parent_parser and parse_args # to determine the command line switches # ################################################################################################################### pa = parse_args() print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print(pa.iterations) print(pa.porttype) print(pa.email) print("@" * 40) print("@" * 40) # sys.exit() ################################################################################################################### ################################################################################################################### # # if user enter ip address then get the chassisname from the # SwitchMatrix file # # then get the info from the SwitchMatrix file using the Chassis Name # # # Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, # Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, # KVM IP,KVM Port,Web Username,Web Password,Admin Password # ################################################################################################################### ################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) # cons_info = sw_matrix_tools.console_info(pa.chassis_name) # console_ip = cons_info[0] # console_port = cons_info[1] # console_ip_bkup = cons_info[2] # console_port_bkup = cons_info[3] # power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ################################################################################################################### # # connect via telnet: # if you want to connect to the console it is available in anturlar and an example is available below # # ################################################################################################################### # Config_up_down_compare.main() # cons_out = anturlar.fos_cmd("firmwareshow") # send any command with anturlar.fos_cmd # print("\r\n") # liabhar.JustSleep(5) # sleep without printing anything # print(cons_out) # print("now closing telnet session ") # #anturlar.close_tel() #### close the telnet session ################################################################################################################### # # connect via console example and other "send command" commands # # ################################################################################################################### # tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) # connect to console w/o parser info # cons_out = anturlar.fos_cmd("firmwareshow") # cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) # hange to the fid given on the command # tn = anturlar.connect_console(console_ip,console_port) # use the console ip and console port info # cons_out = anturlar.fos_cmd("switchshow") # send a command via the console # cons_out = cofra.power_cycle(power_pole_info) # powercycle switch w switchmatrix.csv file # liabhar.JustSleep(30) # wait for the switch to boot # cons_out = anturlar.send_cmd_console("\r\n") # end some commands to the console # cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) # send some commands to the console # cons_out = anturlar.send_cmd_console("firmwareshow") # send some commands to the console # capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2") # send a cfgupload file to a ftp server # liabhar.count_down(5) #### set and observe a count down timer ################################################################################################################### ################################################################################################################### # # This starts the template for configshow output comparison (after some type of switch operation). # First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a # file ################################################################################################################### ################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) # cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) dt = liabhar.dateTimeStuff() # create the object for date and time stuff date_is = dt.current_no_dash_at_end() # get the current time for file naming purposes # print("\n\nDate is %s" % date_is) liabhar.count_down(3) # count down to the next command # configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("172.16.114.67","ftp1",/ # ipaddr_switch,"ftp2") f = "%s%s%s%s" % ("logs/Configupload_test_case_file_ORIG", "_" + ipaddr_switch + "_", date_is, ".txt") ff = liabhar.FileStuff(f, 'w+b') # open the log file for writing header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ", ipaddr_switch, "\n==============================\n\n") # write a header line at top of file ff.write(header) ff.write(anturlar.fos_cmd("configshow")) # ff.write("THE END") ff.close() # close this file for comparison later # g = open(f, "r") # lines = g.readlines() # g.close() # ff = liabhar.FileStuff(f, 'w+b') # for l in lines: # if " date = " not in l: # ff.write(l) # ff.close() ################################################################################################################## ################################################################################################################## # # do anything else you want to try (small sample of examples): # anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") # anturlar.fos_cmd("cfgenable") # anturlar.fos_cmd("switchdisable") # anturlar.fos_cmd("switchenable") # # In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80;\ # tstimezone America/Denver") # Then grab output of configshow, drop into a file and compare that with original # ################################################################################################################## ################################################################################################################## # tn = cofra.clear_stats() # print(pa.porttype) # #sys.exit() # porttype = pa.porttype # print(porttype) # PortFlapper.main(porttype) ############################################################################################# si = anturlar.SwitchInfo() fi = anturlar.FabricInfo() fabric_check = fi.fabric_members() f_ports = si.f_ports() e_ports = si.e_ports() print("\n\n\n\n") print(f_ports) print(e_ports) print("\n\n\n\n") if pa.porttype == "eports": ports = e_ports else: ports = f_ports # try: # tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd) # except OSError: # print("Switch %s not available" % i) g = pa.iterations while g > 0: for i in ports: slot = i[0] port = i[1] if slot: anturlar.fos_cmd("portdisable %s/%s" % (slot, port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s/%s" % (slot, port)) liabhar.count_down(15) else: anturlar.fos_cmd("portdisable %s" % port) liabhar.count_down(15) anturlar.fos_cmd("portenable %s" % port) liabhar.count_down(15) fabric_check1 = fi.fabric_members() if fabric_check != fabric_check1: print("WTF") # email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" ) liabhar.email_sender_html(pa.email, pa.email, "portflapper failed", "portflapper failed", "") anturlar.close_tel() sys.exit(0) else: c = "%s%s%s%s" % ("logs/Configupload_test_case_file_COMPARE", "_" + ipaddr_switch + "_", date_is, ".txt") cc = liabhar.FileStuff(c, 'w+b') # open the log file for writing header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ", ipaddr_switch, "\n==============================\n\n") # write a header line at top of file cc.write(header) cc.write(anturlar.fos_cmd("configshow")) # ff.write("THE END") cc.close() # x = open(c, "r") # lines = x.readlines() # x.close() # cc = liabhar.FileStuff(f, 'w+b') # for l in lines: # if " date = " not in l: # cc.write(l) # cc.close() diff_f = liabhar.file_diff(f, c) print(diff_f) g = g - 1 print(g) if not diff_f: liabhar.email_sender_html(pa.email, pa.email, "PF_configshow_compare failed a checkpoint", "PF_configshow_compare failed" "a checkpoint. Support Save and trace dump transferred", "") cofra.DoSupportsave("172.16.114.67", "ftp1", "ftp2", pa.chassis_name) anturlar.close_tel() sys.exit(0) # diff_f = liabhar.file_diff(f, f1) print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) print("Result ") print(diff_f) liabhar.email_sender_html(pa.email, pa.email, "PF_configshow_compare passed", "PF_configshow_compare passed", "") return True
def flow_to_each_SIM(): """ find all the SIM ports in the fabric and create a flow from each SIM port to all the Other SIM ports Since this test case finds all the switches in the fabric it might not be good to run in fabric mode steps 1. get the ip list of switches in the fabric 2. for each switch get a list of SIM ports 3. create a flow for each SIMport to all other SIM ports 4. start all of the flows if not started 5. if there are only 2 switches only send to the other switch if there are more than 2 switches then send to a random port which could also be on the same switch """ sw_info = anturlar.SwitchInfo() fid_now = sw_info.ls_now() cons_out = anturlar.fos_cmd(" ") #sw_ip = sw_info.ipaddress() f = anturlar.FabricInfo(fid_now) ip_list = f.ipv4_list() ip_count = len(ip_list) ip_c = ip_count combine_port_list = [] list_for_j = [] list_for_i = [] temp_list = [] for ip in ip_list: anturlar.connect_tel_noparse(ip, 'root', 'password') s = anturlar.SwitchInfo() cons_out = anturlar.fos_cmd(" ") cons_out = anturlar.fos_cmd("setcontext %s" % (fid_now)) ports = s.sim_ports(False) #print("\n\n\n",ports, "\n\n\n") #combine_port_list.append(ports) combine_port_list = combine_port_list + ports if ip_c == 2: list_for_i = ports #print("\n\n\nI list \n") #print(list_for_i) liabhar.count_down(10) ip_c = 1 if ip_c == 1: list_for_j = ports #print("\n\n\nJ list \n") #print(list_for_j) liabhar.count_down(10) flow_name_base = "Send_to_each_" count = 0 #### need index address for simport #### now create a flow to each simport #print(combine_port_list) for ip in ip_list: anturlar.connect_tel_noparse(ip, 'root', 'password') s = anturlar.SwitchInfo() cons_out = anturlar.fos_cmd(" ") cons_out = anturlar.fos_cmd("setcontext %s " % (fid_now)) cons_out = anturlar.fos_cmd( "flow --deact sys_gen_all_simports -fea all") #### randomize the list #combine_port_list = liabhar.randomList(combine_port_list) random.shuffle(combine_port_list) j_port_list = combine_port_list #print("\n\n\nPORT LIST RANDOMIZED \n", combine_port_list) #print("\n\n\nNEW LIST RANDOMIZED \n", new_combine_port_list) if len(ip_list) == 2: #print("\n\n\nyes only two switches\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") liabhar.count_down(10) random.shuffle(list_for_i) #print("start I list ") for i in list_for_i: random.shuffle(list_for_j) generate_port = i[0] generate_addr = i[1] #print("\n\ngenerator port and address %s %s \n\n" %(generate_port, generate_addr)) #### this loops on the same list of combined port list #### one idea was to select a random element from the list each time #### for j in list_for_j: target_port = j[0] target_addr = j[1] #print("\n\ntarget port and address %s %s \n\n" %( target_port, target_addr)) if generate_port not in target_port: flow_name = ("%s%s" % (flow_name_base, count)) count += 1 #print(flow_name, " " , generate_port," ", generate_addr, "to this port " ,target_port," ", target_addr) cmd_create = "flow --create %s -srcdev %s -dstdev %s -ingrport %s -fea gen,mon" % ( flow_name, generate_addr, target_addr, generate_port) cons_out = anturlar.fos_cmd(cmd_create) if "maximum limit" in cons_out: count -= 1 break if "Port does not" in cons_out: break if "PID or WWN do not" in cons_out: break if "Exceeds maximum flow limit" in cons_out: count -= 1 break temp_list = list_for_i list_for_i = list_for_j list_for_j = temp_list else: for i in combine_port_list: random.shuffle(j_port_list) generate_port = i[0] generate_addr = i[1] #### this loops on the same list of combined port list #### one idea was to select a random element from the list each time #### for j in j_port_list: target_port = j[0] target_addr = j[1] if generate_port not in target_port: flow_name = ("%s%s" % (flow_name_base, count)) count += 1 print(flow_name, " ", generate_port, " ", generate_addr, "to this port ", target_port, " ", target_addr) cmd_create = "flow --create %s -srcdev %s -dstdev %s -ingrport %s -fea gen,mon" % ( flow_name, generate_addr, target_addr, generate_port) cons_out = anturlar.fos_cmd(cmd_create) if "maximum limit" in cons_out: count -= 1 break if "Port does not" in cons_out: break if "PID or WWN do not" in cons_out: break if "Exceeds maximum flow limit" in cons_out: count -= 1 break
def main(): global tn # variable for telnet session pa = parse_args() # print(pa) # print(pa.chassis_name) # print(pa.ipaddr) # print(pa.quiet) # print(pa.verbose) # print(pa.firmware) # print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### # # if user enter ip address then get the chassisname from the SwitchMatrix file # then get the info from the SwitchMatrix file using the Chassis Name # # # if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) # cons_info = console_info(pa.chassis_name) # console_ip = cons_info[0] # console_port = cons_info[1] # console_ip_bkup = cons_info[2] # console_port_bkup = cons_info[3] # power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) # steps_to_run = pa.steps ################################################################################################################### # if the user does not enter a value for which steps to run prompt for user input value # # if not steps_to_run: # pa.start = user_start() # steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### # # configure some settings that are not defualt to confirm they remain after disruptions # # cons_out = send_cmd("creditrecovmode --cfg onLrThresh") # cons_out = send_cmd("creditrecovmode --fe_crdloss off") # cons_out = send_cmd("creditrecovmode --be_crdloss off") # cons_out = send_cmd("creditrecovmode --be_losync off") # cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### # # capture the configuration file if the user selected 1 or 3 # # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") # switch_info_orig = capture_switch_info("compare_orig", fid_to_compare) ###### File to compare before operations # switchdata_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) ################################################################################################################### # path to the first file to compare # switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # liabhar.JustSleep(10) ################################################################################################################### # this is how to reconnect with telnet # print("reconnect via telnet") # tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ################################################################################################################### ################################################################################################################### ################################################################################################################### # # do configupload or other test steps here # make other changes here before configupload or other commands # ################################################################################################################ # # hafailover or hareboot on pizza box # call the failover function from cofra and send the number of failovers # capture_switch_info("switch_info_orig", pa.fid) # Original File1 # if steps_to_run == 1: # print('\n\nFile written') # sys.exit(0) g = pa.iterations tn = cofra.ha_failover(g) liabhar.count_down(30) capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch diff_f = liabhar.file_diff(orig, compare, "HA_FAILOVER_DIFFERENCES") print(diff_f) # g = g-1 if not diff_f: liabhar.email_sender_html( pa.email, pa.email, "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint.\ Look in logs for HA_FAILOVER_DIFFERENCES file", "") cofra.DoSupportsave(ftp_ip, ftp_username, ftp_password, pa.chassis_name) print("Support Save captured") sys.exit(0) # g = pa.iterations # print(g) # while g > 0: # tn = cofra.ha_failover(g) # liabhar.count_down(60) # capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations # orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch # compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch # diff_f = liabhar.file_diff(orig, compare) # print(diff_f) # # g = g-1 # if not diff_f: # liabhar.email_sender_html(pa.email, pa.email, # "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint", "") # cofra.DoSupportsave("172.16.114.67", "ftp1", "ftp2", pa.chassis_name) # sys.exit(1) # g = g - 1 ################################################################################################################### # # power cycle slots # # ss = anturlar.SwitchInfo() # slot_list = ss.blades(True) # skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # # # # other interuptions # # ################################################################################################################### ################################################################################################################### ################################################################################################################### # if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) # liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") ################################################################################################################### liabhar.cls() print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(orig, compare) print(diff_f) print('\n\n') print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) ################################################################################################################### # put additional commands here before disconnecting from telnet # # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) liabhar.email_sender_html(pa.email, pa.email, "HA_Failover passed", "HA_Failover passed", "")
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) #print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) #print(pa.firmware) print(pa.cmdprompt) print("@"*40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 ### later we will capture info for all fids ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: #pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrtthreshold 7") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture teh configuration file if the user selected 1 or 3 #### if steps_to_run == 1 or steps_to_run == 3: switch_info = capture_switch_info("compare_orig", fid_to_compare) ################################################################################################################### #### path to the first file to compare #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### #### pp = cofra.SwitchUpdate() ################################################################################################################### #### #### #### #### cd = cofra.cfgupload(pa.ftp_ipaddress, pa.ftp_username,pa.ftp_password,pa.config_path) liabhar.count_down(120) mc = make_changes() cdd = cofra.cfgdownload(pa.ftp_ipaddress, pa.ftp_username,pa.ftp_password,cd) liabhar.count_down(360) ################################################################################################################### #### #### #### #### #### #### #### other actions here #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: # liabhar.JustSleep(10) liabhar.count_down(60) switch_info = capture_switch_info("compare", fid_to_compare) ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() #### compare the two files print("#"*80) print("#"*80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#"*80) print("#"*80) diff_f = liabhar.file_diff(switch_data_0,switch_data_1) print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) ################################################################################################################### #### #### disconnecting from telnet #### ################################################################################################################### anturlar.close_tel()
def main(): global tn ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) #print(pa) print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.delay_before_on) print(pa.delay_before_next_off) print(pa.count_power_cycles) print("@" * 40) ################################################################################################################### ################################################################################################################### #### #### get the info from the SwitchMatrix file using the Chassis Name #### #### the only args required are chassisname #### power_pole_info = pwr_pole_info(pa.chassis_name) ################################################################################################################### ################################################################################################################### #### # ####################################################################################################################### # #### # #### # #### ####################################################################################################################### ####################################################################################################################### #### this step is the same for director or pizza box #### #### turn each port off then turn each port on (otherwise the delay between did not power cycle the switch) #### ####################################################################################################################### liabhar.count_down(20) cycles = 0 while cycles < pa.count_power_cycles: pass for pp in range(0, len(power_pole_info), 2): print('POWERPOLE') print(power_pole_info[pp]) print(power_pole_info[pp + 1]) #pwr_cycle(power_pole_info[pp],power_pole_info[pp+1], "off" ,10) #time.sleep(4) try: for pp in range(0, len(power_pole_info), 2): print('POWERPOLE') print(power_pole_info[pp]) print(power_pole_info[pp + 1]) pwr_cycle(power_pole_info[pp], power_pole_info[pp + 1], "off", 10) time.sleep(4) liabhar.count_down(pa.delay_before_on) for pp in range(0, len(power_pole_info), 2): print('POWERPOLE') print(power_pole_info[pp]) print(power_pole_info[pp + 1]) pwr_cycle(power_pole_info[pp], power_pole_info[pp + 1], "on", 10) time.sleep(4) except: if '' == power_pole_info[0]: print("\n" * 20) print("NO POWER POLE INFO FOUND ") print("HA " * 10) print("you have to walk to power cycle the switch") print("I will wait ") liabhar.JustSleep(30) else: print("POWER TOWER INFO") print(power_pole_info[0]) print(power_pole_info) liabhar.JustSleep(30) cycles += 1 print("power cycle %s of %s" % (cycles, pa.count_power_cycles)) liabhar.JustSleep(6) liabhar.count_down(pa.delay_before_next_off) ####################################################################################################################### ####################################################################################################################### #### #### #### ####################################################################################################################### dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is)
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@"*40) print("@"*40) ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) cons_info = sw_matrix_tools.console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet #### if you want to connect to the console it is available in anturlar and an example below #### #### ###################################################################################################################### ###################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) #### change to the fid given on the command cons_out = anturlar.fos_cmd("firmwareshow") #### send any command with anturlar.fos_cmd print("\r\n") liabhar.JustSleep(30) #### sleep without printing anything print("now closing telnet session ") anturlar.close_tel() #### close the telnet session liabhar.JustSleep(30) ####################################################################################################################### ####################################################################################################################### #### #### connect via console example #### #### ####################################################################################################################### ####################################################################################################################### #tn = anturlar.connect_console(console_ip,console_port) #### use the console ip and console port info #cons_out = anturlar.fos_cmd("switchshow") #### send a command via the console # ##cons_out = cofra.power_cycle(power_pole_info) #### power cycle the switch using the # #### Switch Matrix info #liabhar.JustSleep(30) #### wait for the switch to boot # # #cons_out = anturlar.send_cmd_console("\r\n") #### send some commands to the console # #### #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) #### #cons_out = anturlar.send_cmd_console("firmwareshow") #### ####################################################################################################################### ####################################################################################################################### #### #### do anything else you want to try #### #### ####################################################################################################################### ####################################################################################################################### dt = liabhar.dateTimeStuff() #### create the object for date and time stuff date_is = dt.current() #### get the current time print(date_is) print("Leaving the script\r\n\r\n") liabhar.count_down(30) #### count down to the next command
def main(): global tn ############################################################################### #### #### #### ############################################################################### pa = parse_args(sys.argv) #print(pa) #print(pa.chassis_name) #print(pa.ipaddr) #print(pa.quiet) #print(pa.verbose) #print(pa.firmware) #print("@"*40) #sys.exit() ########################################################################## ########################################################################## ### ### hold the ip address from the command line ### if pa.ipaddr: pa.chassis_name = console_info_from_ip(pa.ipaddr, pa.chassis_name) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] tn = anturlar.connect_tel_noparse(pa.ipaddr,user_name,usr_psswd) fi = anturlar.FabricInfo() si = anturlar.SwitchInfo() fcr = anturlar.FcrInfo() if pa.fabwide: ipaddr_switch = fi.ipv4_list() elif pa.csvall: ipaddr_switch = get_ip_from_file(pa.chassis_name) elif pa.fcrwide: anturlar.fos_cmd("setcontext %s" % fcr.base_check()) ipaddr_switch = fcr.fcr_fab_wide_ip() else: ipaddr_switch = [pa.ipaddr] anturlar.close_tel() #### pass ip(s)to login procedure #### and write the file for i in ipaddr_switch: try: tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd) except OSError: print("Switch %s not available" % i) nos = si.nos_check() if not nos: print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") ports = fcr.all_ex_ports_with_edge_fid() devices = fcr.fcr_proxy_dev() #backbone_ip = fcr.fcr_backbone_ip() print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") f = ('logs/EX_PortFlapper.txt') try: with open(f, 'w') as file: file.write("EX-Ports = %s\n" % str(ports)) file.write("Proxy Devices = %s\n" % str(devices)) #file.write("Backbone_IPs = %s\n" % str(backbone_ip)) except IOError: print("\n\nThere was a problem opening the file:" , f) sys.exit() file.close() for i in ports: slot = i[0] port = i[1] if slot: anturlar.fos_cmd("portdisable %s/%s" % (slot, port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s/%s" % (slot, port)) liabhar.count_down(15) else: anturlar.fos_cmd("portdisable %s" % (port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s" % (port)) liabhar.count_down(15) devices_check = fcr.fcr_proxy_dev() if devices_check != devices: print ("WTF") #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" ) liabhar.email_sender_html("*****@*****.**","*****@*****.**","portflapper failed","portflapper failed","") sys.exit() liabhar.email_sender_html("*****@*****.**","*****@*****.**","portflapper passed","portflapper passed","") sys.exit() else: print("\n"+"@"*40) print('\nTHIS IS A NOS SWITCH> SKIPPING') print("\n"+"@"*40) pass anturlar.close_tel() sys.exit()
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@"*40) print("@"*40) ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) cons_info = sw_matrix_tools.console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet: #### if you want to connect to the console it is available in anturlar and an example below #### #### ###################################################################################################################### ###################################################################################################################### #### Config_up_down_compare.main() # cons_out = anturlar.fos_cmd("firmwareshow") #### send any command with anturlar.fos_cmd # print("\r\n") # liabhar.JustSleep(5) #### sleep without printing anything # print("now closing telnet session ") # #anturlar.close_tel() #### close the telnet session ####################################################################################################################### ####################################################################################################################### #### #### connect via console example and other "send command" commands #### #### ####################################################################################################################### ####################################################################################################################### #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) #### connect to console w/o parser info #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) #### change to the fid given on the command #tn = anturlar.connect_console(console_ip,console_port) #### use the console ip and console port info #cons_out = anturlar.fos_cmd("switchshow") #### send a command via the console #cons_out = cofra.power_cycle(power_pole_info) #### powercycle switch via switchmatrix.csv file #liabhar.JustSleep(30) #### wait for the switch to boot #cons_out = anturlar.send_cmd_console("\r\n") #### send some commands to the console #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) #### send some commands to the console #cons_out = anturlar.send_cmd_console("firmwareshow") #### send some commands to the console #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2") #### send a cfgupload file to a ftp server #liabhar.count_down(5) #### set and observe a count down timer ####################################################################################################################### ####################################################################################################################### #### #### This starts the template for configshow output comparison (after some type of switch operation). #### First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file. #### ####################################################################################################################### ####################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) dt = liabhar.dateTimeStuff() #### create the object for date and time stuff date_is = dt.current_no_dash_at_end() #### get the current time for file naming purposes #print("\n\nDate is %s" % date_is) liabhar.count_down(5) #### count down to the next command #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2") f = "%s%s%s%s"%("logs/Configupload_test_case_file",ipaddr_switch,date_is,".txt") ff = liabhar.FileStuff(f, 'w+b') #### open the log file for writing header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch,"\n==============================\n\n") #### write a header line at top of file ff.write(header) #cons_out = anturlar.fos_cmd (configup_cmd) ff.write(anturlar.fos_cmd("configshow")) ff.close() #### close this file for comparison later ####################################################################################################################### ####################################################################################################################### #### #### do anything else you want to try (small sample of examples): #### anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### anturlar.fos_cmd("cfgenable") #### anturlar.fos_cmd("switchdisable") #### anturlar.fos_cmd("switchenable") #### #### In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### Then grab output of configshow, drop into a file and compare that with original #### ####################################################################################################################### ####################################################################################################################### anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") date_is = dt.current_no_dash_at_end() f1 = "%s%s%s%s"%("logs/Configupload_test_case_file",ipaddr_switch,date_is,".txt") ff = liabhar.FileStuff(f1, 'w+b') #### reset the log file header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch, "\n==============================\n\n") ff.write(header) #cons_out = anturlar.fos_cmd (configup_cmd) ff.write(anturlar.fos_cmd("configshow")) ff.close() diff_f = liabhar.file_diff(f,f1) print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) #return(cons_out) return(True)
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) #print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) #print(pa.firmware) print(pa.cmdprompt) print("@"*40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: #pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture the configuration file if the user selected 1 or 3 #### switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch if steps_to_run == 1 or steps_to_run == 3: #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") #switch_info_orig = capture_switch_info("compare_orig", fid_to_compare) ###### File to compare before operations switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) ################################################################################################################### #### path to the first file to compare #switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### #### this is how to reconnect with telnet #print("reconnect via telnet") #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### hafailover or hareboot on pizza box #### call the failover function from cofra and send the number of failovers #### g = pa.iterations while g > 0: tn = cofra.ha_failover(g) liabhar.count_down(120) #switch_info_compare = capture_switch_info("compare", fid_to_compare) ###### File to compare after operations switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print(diff_f) g = g-1 if not diff_f: liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed a checkpoint","NS_portflapper failed a checkpoint","") sys.exit() ################################################################################################################### #### #### power cycle slots #### #ss = anturlar.SwitchInfo() #slot_list = ss.blades(True) #### skip if switch is a pizza box #if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) #else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # #### #### #### other interuptions #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) #liabhar.count_down(360) #cons_out = anturlar.fos_cmd("setcontext 128") #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() print("#"*80) print("#"*80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#"*80) print("#"*80) diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) ################################################################################################################### #### put additional commands here before disconnecting from telnet #### #cons_out = anturlar.fos_cmd("mapsdb --show all") #print(cons_out) cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) liabhar.email_sender_html("*****@*****.**","*****@*****.**","HA_Failover passed","HA_Failover passed","")
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print(pa.iterations) #print(pa.zone_name_size) print("@" * 40) print("@" * 40) #sys.exit() ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) cons_info = sw_matrix_tools.console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet: #### if you want to connect to the console it is available in anturlar and an example is available below #### #### ###################################################################################################################### ###################################################################################################################### #### Config_up_down_compare.main() #cons_out = anturlar.fos_cmd("firmwareshow") #### send any command with anturlar.fos_cmd #print("\r\n") #liabhar.JustSleep(5) #### sleep without printing anything #print(cons_out) # print("now closing telnet session ") # #anturlar.close_tel() #### close the telnet session ####################################################################################################################### ####################################################################################################################### #### #### connect via console example and other "send command" commands #### #### ####################################################################################################################### ####################################################################################################################### #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) #### connect to console w/o parser info #cons_out = anturlar.fos_cmd("firmwareshow") #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) #### change to the fid given on the command #tn = anturlar.connect_console(console_ip,console_port) #### use the console ip and console port info #cons_out = anturlar.fos_cmd("switchshow") #### send a command via the console #cons_out = cofra.power_cycle(power_pole_info) #### powercycle switch via switchmatrix.csv file #liabhar.JustSleep(30) #### wait for the switch to boot #cons_out = anturlar.send_cmd_console("\r\n") #### send some commands to the console #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) #### send some commands to the console #cons_out = anturlar.send_cmd_console("firmwareshow") #### send some commands to the console #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2") #### send a cfgupload file to a ftp server #liabhar.count_down(5) #### set and observe a count down timer ####################################################################################################################### ####################################################################################################################### #### #### This starts the template for configshow output comparison (after some type of switch operation). #### First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file. #### ####################################################################################################################### ####################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) dt = liabhar.dateTimeStuff( ) #### create the object for date and time stuff date_is = dt.current_no_dash_at_end( ) #### get the current time for file naming purposes #print("\n\nDate is %s" % date_is) liabhar.count_down(3) #### count down to the next command #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2") f = "%s%s%s%s" % ("logs/CLITIZoneOperations_test_case_file", "_" + ipaddr_switch + "_", date_is, ".txt") ff = liabhar.FileStuff(f, 'w+b') #### open the log file for writing #header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch,"\n==============================\n\n") #### write a header line at top of file header = "%s%s%s%s" % ("\nCLITIZoneOperations CAPTURE FILE \n", " sw_info ipaddr ", ipaddr_switch, "\n==============================\n\n") ff.write(header) ff.write(anturlar.fos_cmd("nsshow")) ff.write(anturlar.fos_cmd("nsallshow")) ff.close() g = open(f, "r") lines = g.readlines() g.close() ff = liabhar.FileStuff(f, 'w+b') for l in lines: if " date = " not in l: ff.write(l) ff.close() #### close this file for comparison later ####################################################################################################################### ####################################################################################################################### #### #### do anything else you want to try (small sample of examples): #### anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### anturlar.fos_cmd("cfgenable") #### anturlar.fos_cmd("switchdisable") #### anturlar.fos_cmd("switchenable") #### #### In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### Then grab output of configshow, drop into a file and compare that with original #### ####################################################################################################################### ####################################################################################################################### # tn = cofra.clear_stats() # print(pa.porttype) # #sys.exit() # porttype = pa.porttype # print(porttype) # PortFlapper.main(porttype) ############################################################################################# si = anturlar.SwitchInfo() fi = anturlar.FabricInfo() # fabric_check = fi.fabric_members() cfgsz = anturlar.fos_cmd("cfgsize") # cfgshow = anturlar.fos_cmd("cfgshow") cfgtransshow = anturlar.fos_cmd("cfgtransshow") if "token" in cfgtransshow: print("Outstanding transaction in progress. Use cfgtransshow to view.") sys.exit() # print(fabric_check) # print(cfgsz) # print(cfgshow) # print(cfgtransshow) character = "$-^_" characters = ["$", "-", "^", "_"] size = random.randint(0, 61) ti_zonename = (''.join( random.choice(string.ascii_letters + string.digits + character) for _ in range(size)) + "_TI") ti_zonename = "$" + ti_zonename print(ti_zonename) while ti_zonename[0] in character: print("Can't have special characters at the beginning of a zone name") ti_zonename = (''.join( random.choice(string.ascii_letters + string.digits + character) for _ in range(size)) + "_TI") print(ti_zonename) sys.exit() # a = ("time zone --create -t ti %s -p \"1,1:2,2\"" % ti_zonename) # print(a) anturlar.fos_cmd("zone --create -t ti %s -p \"1,1;2,2\"" % ti_zonename) #anturlar.fos_cmd("echo Y | cfgsave") # anturlar.fos_cmd("echo Y | cfgsave") # anturlar.fos_cmd("cfgshow") sys.exit() # f_ports = si.f_ports() # e_ports = si.e_ports() # print("\n\n\n\n") # print(f_ports) # print(e_ports) # print("\n\n\n\n") # if pa.porttype == "eports": # ports = e_ports # else: # ports = f_ports # i = ipaddr_switch # try: # tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd) # except OSError: # print("Switch %s not available" % i) nos = si.nos_check() if not nos: for i in ports: slot = i[0] port = i[1] if slot: anturlar.fos_cmd("portdisable %s/%s" % (slot, port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s/%s" % (slot, port)) liabhar.count_down(15) else: anturlar.fos_cmd("portdisable %s" % (port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s" % (port)) liabhar.count_down(15) fabric_check1 = fi.fabric_members() if fabric_check != fabric_check1: print("WTF") #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" ) liabhar.email_sender_html("*****@*****.**", "*****@*****.**", "NS_portflapper failed", "NS_portflapper failed", "") sys.exit() anturlar.close_tel() #return(True) else: print("\n" + "@" * 40) print('\nTHIS IS A NOS SWITCH> SKIPPING') print("\n" + "@" * 40) pass #anturlar.close_tel() #################################################################################################################### #anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #tn = cofra.ha_failover(pa.iterations) #tn = cofra.power_cycle_iterations(power_pole_info, pa.iterations) tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) date_is = dt.current_no_dash_at_end() f1 = "%s%s%s%s" % ("logs/NameServer_test_case_file", "_" + ipaddr_switch + "_", date_is, ".txt") ff = liabhar.FileStuff(f1, 'w+b') #### reset the log file #header = "%s%s%s%s" % ("\NAMESERVER CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch,"\n==============================\n\n") #header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch, "\n==============================\n\n") header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", " sw_info ipaddr ", ipaddr_switch, "\n==============================\n\n") ff.write(header) ff.write(anturlar.fos_cmd("nsshow")) ff.write(anturlar.fos_cmd("nsallshow")) ff.close() g = open(f1, "r") lines = g.readlines() g.close() ff = liabhar.FileStuff(f1, 'w+b') for l in lines: if " date = " not in l: ff.write(l) ff.close() diff_f = liabhar.file_diff(f, f1) print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) print("Result ") print(diff_f) liabhar.email_sender_html("*****@*****.**", "*****@*****.**", "NS_portflapper passed", "NS_portflapper passed", "") return (True)
def flow_to_each_SIM(): """ find all the SIM ports in the fabric and create a flow from each SIM port to all the Other SIM ports Since this test case finds all the switches in the fabric it might not be good to run in fabric mode steps 1. get the ip list of switches in the fabric 2. for each switch get a list of SIM ports 3. create a flow for each SIMport to all other SIM ports 4. start all of the flows if not started 5. if there are only 2 switches only send to the other switch if there are more than 2 switches then send to a random port which could also be on the same switch """ sw_info = anturlar.SwitchInfo() fid_now = sw_info.ls_now() cons_out = anturlar.fos_cmd(" ") #sw_ip = sw_info.ipaddress() f = anturlar.FabricInfo(fid_now) ip_list = f.ipv4_list() ip_count = len(ip_list) ip_c = ip_count combine_port_list = [] list_for_j = [] list_for_i = [] temp_list = [] for ip in ip_list: anturlar.connect_tel_noparse(ip,'root','password') s = anturlar.SwitchInfo() cons_out = anturlar.fos_cmd(" ") cons_out = anturlar.fos_cmd("setcontext %s" % (fid_now)) ports = s.sim_ports(False) #print("\n\n\n",ports, "\n\n\n") #combine_port_list.append(ports) combine_port_list = combine_port_list + ports if ip_c == 2: list_for_i = ports #print("\n\n\nI list \n") #print(list_for_i) liabhar.count_down(10) ip_c = 1 if ip_c == 1: list_for_j = ports #print("\n\n\nJ list \n") #print(list_for_j) liabhar.count_down(10) flow_name_base = "Send_to_each_" count = 0 #### need index address for simport #### now create a flow to each simport #print(combine_port_list) for ip in ip_list: anturlar.connect_tel_noparse(ip,'root','password') s = anturlar.SwitchInfo() cons_out = anturlar.fos_cmd(" ") cons_out = anturlar.fos_cmd("setcontext %s " % (fid_now)) cons_out = anturlar.fos_cmd("flow --deact sys_gen_all_simports -fea all") #### randomize the list #combine_port_list = liabhar.randomList(combine_port_list) random.shuffle(combine_port_list) j_port_list = combine_port_list #print("\n\n\nPORT LIST RANDOMIZED \n", combine_port_list) #print("\n\n\nNEW LIST RANDOMIZED \n", new_combine_port_list) if len(ip_list) == 2: #print("\n\n\nyes only two switches\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") liabhar.count_down(10) random.shuffle(list_for_i) #print("start I list ") for i in list_for_i: random.shuffle(list_for_j) generate_port = i[0] generate_addr = i[1] #print("\n\ngenerator port and address %s %s \n\n" %(generate_port, generate_addr)) #### this loops on the same list of combined port list #### one idea was to select a random element from the list each time #### for j in list_for_j: target_port = j[0] target_addr = j[1] #print("\n\ntarget port and address %s %s \n\n" %( target_port, target_addr)) if generate_port not in target_port: flow_name = ("%s%s" % (flow_name_base,count)) count +=1 #print(flow_name, " " , generate_port," ", generate_addr, "to this port " ,target_port," ", target_addr) cmd_create = "flow --create %s -srcdev %s -dstdev %s -ingrport %s -fea gen,mon" % (flow_name, generate_addr,target_addr, generate_port) cons_out = anturlar.fos_cmd(cmd_create) if "maximum limit" in cons_out: count -= 1 break if "Port does not" in cons_out: break if "PID or WWN do not" in cons_out: break if "Exceeds maximum flow limit" in cons_out: count -= 1 break temp_list = list_for_i list_for_i = list_for_j list_for_j = temp_list else: for i in combine_port_list: random.shuffle(j_port_list) generate_port = i[0] generate_addr = i[1] #### this loops on the same list of combined port list #### one idea was to select a random element from the list each time #### for j in j_port_list: target_port = j[0] target_addr = j[1] if generate_port not in target_port: flow_name = ("%s%s" % (flow_name_base,count)) count +=1 print(flow_name, " " , generate_port," ", generate_addr, "to this port " ,target_port," ", target_addr) cmd_create = "flow --create %s -srcdev %s -dstdev %s -ingrport %s -fea gen,mon" % (flow_name, generate_addr,target_addr, generate_port) cons_out = anturlar.fos_cmd(cmd_create) if "maximum limit" in cons_out: count -= 1 break if "Port does not" in cons_out: break if "PID or WWN do not" in cons_out: break if "Exceeds maximum flow limit" in cons_out: count -= 1 break
def main(): pa = parse_args(sys.argv) if os.path.exists("ini/%s" % pa.filename): pass print("found the file") else: print("Could not find the file %s " % pa.filename) this_platform = liabhar.platform() if pa.verbose >= 2: print("V"*80) print("Platform type is \n") print(this_platform) print("\n") print("A"*80) print("PLATFORM IS : %s " % this_platform) traff_to_start = get_switch_info(pa.filename) if pa.verbose >= 2: print("V"*80) print("traffic command to start") print(traff_to_start) print("B"*80) for s in traff_to_start: print("SERVER COMMANDS ") print(s) print(type(s)) t = s.split(',') print(t) serv_ip = t[2] serv_usr = t[3] serv_pwd = t[4] maim_pain = t[6] size = t[7] cmd_options = "" if t[8]: cmd_options = cmd_options + " -A" + t[8] if t[9]: cmd_options = cmd_options + " -b" + t[9] if t[10]: cmd_options = cmd_options + " -B" + t[10] if t[11]: cmd_options = cmd_options + " -c" + t[11] if t[12]: cmd_options = cmd_options + " -C" + t[12] if t[13]: cmd_options = cmd_options + " -d" + t[13] if t[14]: cmd_options = cmd_options + " -D" + t[14] if t[15]: cmd_options = cmd_options + " -E" + t[15] if t[16]: cmd_options = cmd_options + " -g" + t[16] if t[17]: cmd_options = cmd_options + " -G" + t[17] if t[18]: cmd_options = cmd_options + " -i" + t[18] if t[19]: cmd_options = cmd_options + " -I" + t[19] if t[20]: cmd_options = cmd_options + " -j" + t[20] if t[21]: cmd_options = cmd_options + " -J" + t[21] if t[22]: cmd_options = cmd_options + " -l" + t[22] if t[23]: cmd_options = cmd_options + " -L" + t[23] if t[24]: cmd_options = cmd_options + " -m" + t[24] if t[25]: cmd_options = cmd_options + " -M" + t[25] if t[26]: cmd_options = cmd_options + " -n" if t[27]: cmd_options = cmd_options + " -N" + t[27] if t[28]: cmd_options = cmd_options + " -o" if t[29]: cmd_options = cmd_options + " -O" + t[29] if t[30]: cmd_options = cmd_options + " -P" + t[30] if t[31]: cmd_options = cmd_options + " -q" + t[31] if t[32]: cmd_options = cmd_options + " -Q" + t[32] if t[33]: cmd_options = cmd_options + " --scsi" + t[33] if t[34]: cmd_options = cmd_options + " -r" + t[34] if t[35]: cmd_options = cmd_options + " -R" + t[35] if t[36]: cmd_options = cmd_options + " -s" + t[36] if t[37]: cmd_options = cmd_options + " -S" + t[37] if t[38]: cmd_options = cmd_options + " -t" + t[38] if t[39]: cmd_options = cmd_options + " -T" + t[39] if t[40]: cmd_options = cmd_options + " -u" if t[41]: cmd_options = cmd_options + " -U" + t[41] if t[42]: cmd_options = cmd_options + " -v" + t[42] if t[43]: cmd_options = cmd_options + " -V" + t[43] if t[44]: cmd_options = cmd_options + " -w" + t[44] if t[45]: cmd_options = cmd_options + " -W" + t[45] if t[46]: cmd_options = cmd_options + " -y" + t[46] if t[47]: cmd_options = cmd_options + " -Y" + t[47] if t[48]: cmd_options = cmd_options + " -%T" + t[48] strt_cmd = maim_pain + " " + size + cmd_options print("server info to connect with \n") print("IP address : %s " % serv_ip ) print("User Name : %s " % serv_usr) print("Password : %s " % serv_pwd) print("MEDUSA Command : %s " % maim_pain) print("Size : %s " % size) print("command Options : %s " % cmd_options) print("start command is : %s " % strt_cmd) #time.sleep(60.2) ########################################################################### #### commenting out for debug purpose #### #### #if t[2] != "Username": # traffic_tools.traff_get_port_list(serv_ip, serv_usr, serv_pwd, strt_cmd) ########################################################################### print("\n"*4) print(t[2]) if t[2] != "Username": os_ver = anturlar.remote_os_ver(serv_ip,9) if pa.verbose >= 2: print("V"*80) print("Version of Traffic switch") print(os_ver) print("C"*80) print("wait and then start the traffic") #liabhar.count_down(30) p = Process(target=traffic_tools.traff_get_port_list, args=(serv_ip, serv_usr, serv_pwd, strt_cmd, os_ver, pa.verbose)) p.daemon = True p.start() #p.join() time.sleep(35.2) time_traffic_run = 0 while True : liabhar.count_down(300) time_traffic_run += 300 print("Traffic has been running for %s seconds " % time_traffic_run ) print("\n"*5)
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@" * 40) print("@" * 40) ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) cons_info = sw_matrix_tools.console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet: #### if you want to connect to the console it is available in anturlar and an example below #### #### ###################################################################################################################### ###################################################################################################################### #### Config_up_down_compare.main() # cons_out = anturlar.fos_cmd("firmwareshow") #### send any command with anturlar.fos_cmd # print("\r\n") # liabhar.JustSleep(5) #### sleep without printing anything # print("now closing telnet session ") # #anturlar.close_tel() #### close the telnet session ####################################################################################################################### ####################################################################################################################### #### #### connect via console example and other "send command" commands #### #### ####################################################################################################################### ####################################################################################################################### #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) #### connect to console w/o parser info #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) #### change to the fid given on the command #tn = anturlar.connect_console(console_ip,console_port) #### use the console ip and console port info #cons_out = anturlar.fos_cmd("switchshow") #### send a command via the console #cons_out = cofra.power_cycle(power_pole_info) #### powercycle switch via switchmatrix.csv file #liabhar.JustSleep(30) #### wait for the switch to boot #cons_out = anturlar.send_cmd_console("\r\n") #### send some commands to the console #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) #### send some commands to the console #cons_out = anturlar.send_cmd_console("firmwareshow") #### send some commands to the console #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2") #### send a cfgupload file to a ftp server #liabhar.count_down(5) #### set and observe a count down timer ####################################################################################################################### ####################################################################################################################### #### #### This starts the template for configshow output comparison (after some type of switch operation). #### First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file. #### ####################################################################################################################### ####################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) dt = liabhar.dateTimeStuff( ) #### create the object for date and time stuff date_is = dt.current_no_dash_at_end( ) #### get the current time for file naming purposes #print("\n\nDate is %s" % date_is) liabhar.count_down(5) #### count down to the next command #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2") f = "%s%s%s%s" % ("logs/Configupload_test_case_file", ipaddr_switch, date_is, ".txt") ff = liabhar.FileStuff(f, 'w+b') #### open the log file for writing header = "%s%s%s%s" % ( "\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ", ipaddr_switch, "\n==============================\n\n" ) #### write a header line at top of file ff.write(header) #cons_out = anturlar.fos_cmd (configup_cmd) ff.write(anturlar.fos_cmd("configshow")) ff.close() #### close this file for comparison later ####################################################################################################################### ####################################################################################################################### #### #### do anything else you want to try (small sample of examples): #### anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### anturlar.fos_cmd("cfgenable") #### anturlar.fos_cmd("switchdisable") #### anturlar.fos_cmd("switchenable") #### #### In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### Then grab output of configshow, drop into a file and compare that with original #### ####################################################################################################################### ####################################################################################################################### anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") date_is = dt.current_no_dash_at_end() f1 = "%s%s%s%s" % ("logs/Configupload_test_case_file", ipaddr_switch, date_is, ".txt") ff = liabhar.FileStuff(f1, 'w+b') #### reset the log file header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ", ipaddr_switch, "\n==============================\n\n") ff.write(header) #cons_out = anturlar.fos_cmd (configup_cmd) ff.write(anturlar.fos_cmd("configshow")) ff.close() diff_f = liabhar.file_diff(f, f1) print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) print("Result ") print(diff_f) #return(cons_out) return (True)
def main(): pa = parse_args(sys.argv) if os.path.exists("ini/%s" % pa.filename): pass print("found the file") else: print("Could not find the file %s " % pa.filename) this_platform = liabhar.platform() if pa.verbose >= 2: print("V" * 80) print("Platform type is \n") print(this_platform) print("\n") print("A" * 80) print("PLATFORM IS : %s " % this_platform) traff_to_start = get_switch_info(pa.filename) if pa.verbose >= 2: print("V" * 80) print("traffic command to start") print(traff_to_start) print("B" * 80) for s in traff_to_start: print("SERVER COMMANDS ") print(s) print(type(s)) t = s.split(',') print(t) serv_ip = t[2] serv_usr = t[3] serv_pwd = t[4] maim_pain = t[6] size = t[7] cmd_options = "" if t[8]: cmd_options = cmd_options + " -A" + t[8] if t[9]: cmd_options = cmd_options + " -b" + t[9] if t[10]: cmd_options = cmd_options + " -B" + t[10] if t[11]: cmd_options = cmd_options + " -c" + t[11] if t[12]: cmd_options = cmd_options + " -C" + t[12] if t[13]: cmd_options = cmd_options + " -d" + t[13] if t[14]: cmd_options = cmd_options + " -D" + t[14] if t[15]: cmd_options = cmd_options + " -E" + t[15] if t[16]: cmd_options = cmd_options + " -g" + t[16] if t[17]: cmd_options = cmd_options + " -G" + t[17] if t[18]: cmd_options = cmd_options + " -i" + t[18] if t[19]: cmd_options = cmd_options + " -I" + t[19] if t[20]: cmd_options = cmd_options + " -j" + t[20] if t[21]: cmd_options = cmd_options + " -J" + t[21] if t[22]: cmd_options = cmd_options + " -l" + t[22] if t[23]: cmd_options = cmd_options + " -L" + t[23] if t[24]: cmd_options = cmd_options + " -m" + t[24] if t[25]: cmd_options = cmd_options + " -M" + t[25] if t[26]: cmd_options = cmd_options + " -n" if t[27]: cmd_options = cmd_options + " -N" + t[27] if t[28]: cmd_options = cmd_options + " -o" if t[29]: cmd_options = cmd_options + " -O" + t[29] if t[30]: cmd_options = cmd_options + " -P" + t[30] if t[31]: cmd_options = cmd_options + " -q" + t[31] if t[32]: cmd_options = cmd_options + " -Q" + t[32] if t[33]: cmd_options = cmd_options + " --scsi" + t[33] if t[34]: cmd_options = cmd_options + " -r" + t[34] if t[35]: cmd_options = cmd_options + " -R" + t[35] if t[36]: cmd_options = cmd_options + " -s" + t[36] if t[37]: cmd_options = cmd_options + " -S" + t[37] if t[38]: cmd_options = cmd_options + " -t" + t[38] if t[39]: cmd_options = cmd_options + " -T" + t[39] if t[40]: cmd_options = cmd_options + " -u" if t[41]: cmd_options = cmd_options + " -U" + t[41] if t[42]: cmd_options = cmd_options + " -v" + t[42] if t[43]: cmd_options = cmd_options + " -V" + t[43] if t[44]: cmd_options = cmd_options + " -w" + t[44] if t[45]: cmd_options = cmd_options + " -W" + t[45] if t[46]: cmd_options = cmd_options + " -y" + t[46] if t[47]: cmd_options = cmd_options + " -Y" + t[47] if t[48]: cmd_options = cmd_options + " -%T" + t[48] strt_cmd = maim_pain + " " + size + cmd_options print("server info to connect with \n") print("IP address : %s " % serv_ip) print("User Name : %s " % serv_usr) print("Password : %s " % serv_pwd) print("MEDUSA Command : %s " % maim_pain) print("Size : %s " % size) print("command Options : %s " % cmd_options) print("start command is : %s " % strt_cmd) #time.sleep(60.2) ########################################################################### #### commenting out for debug purpose #### #### #if t[2] != "Username": # traffic_tools.traff_get_port_list(serv_ip, serv_usr, serv_pwd, strt_cmd) ########################################################################### print("\n" * 4) print(t[2]) if t[2] != "Username": os_ver = anturlar.remote_os_ver(serv_ip, 9) if pa.verbose >= 2: print("V" * 80) print("Version of Traffic switch") print(os_ver) print("C" * 80) print("wait and then start the traffic") #liabhar.count_down(30) p = Process(target=traffic_tools.traff_get_port_list, args=(serv_ip, serv_usr, serv_pwd, strt_cmd, os_ver, pa.verbose)) p.daemon = True p.start() #p.join() time.sleep(35.2) time_traffic_run = 0 while True: liabhar.count_down(300) time_traffic_run += 300 print("Traffic has been running for %s seconds " % time_traffic_run) print("\n" * 5)
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 fid_to_compare = pa.fid ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: # pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrthreshold 7") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture teh configuration file if the user selected 1 or 3 #### if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") switch_info = capture_switch_info("compare_orig", fid_to_compare) ################################################################################################################### #### path to the first file to compare # switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch switch_data_0 = "/home/runfromhere/logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### REBOOT and RECONNECT WAIT 60 SECONDS and CONTINUE #### print("START Switch Update Class") liabhar.JustSleep(10) pp = cofra.SwitchUpdate() # tn = pp.reboot_reconnect() # liabhar.count_down(60) ################################################################################################################### #### #### hafailover or hareboot on pizza box #### call the failover function from cofra and send the number of failovers #### print("START HA FAILOVER") liabhar.JustSleep(10) tn = cofra.ha_failover(100) liabhar.count_down(600) ################################################################################################################### #### #### power cycle slots #### ss = anturlar.SwitchInfo() slot_list = ss.blades(True) #### skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # #### #### #### other interuptions #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") switch_info = capture_switch_info("compare", fid_to_compare) ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() #### compare the two files print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) print("Result ") print(diff_f) ################################################################################################################### #### put additional commands here before disconnecting from telnet #### # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) print(type(steps_to_run)) print(steps_to_run)
def chck_a(): #global tn si = anturlar.SwitchInfo() does_allow_xisl = si.allow_xisl() show_all_ports = si.all_ports() show_all_ports_fc = si.all_ports_fc_only() base_y_n = si.base_check() blade_8G = si.blade_search_8GB() blades = si.blades() blade_blank = si.blank_type() fid_now = si.currentFID() chass_name = si.chassisname() dport = si.d_ports() dflt_switch = si.default_switch() dir_y_n = si.director() disbled_ports = si.disabled_ports() eports = si.e_ports() exports = si.ex_ports() vexports = si.vex_ports() fports = si.f_ports() fans = si.fan_count() fcr_y_n = si.fcr_enabled() gports = si.g_ports() lic_lst = si.getLicense() sw_ip = si.ipaddress() lport = si.loopback() ls_lst = si.ls() ls_crnt = si.ls_now() nports = si.n_ports() pdports = si.persistent_disabled_ports() sensors_lst_t = si.sensor_t_f_ps("t") sensors_lst_t = si.sensor_t_f_ps("f") sensors_lst_t = si.sensor_t_f_ps("ps") sfpinfo = si.sfp_info() sports = si.sim_ports() swstate = si.switch_state() sw_id = si.switch_id() sw_name = si.switch_name() sw_status = si.switch_status() ### fcr info sw_type = si.switch_type() sw_sync = si.synchronized() sw_tmp = si.temp_sensors() vf_y_n = si.vf_enabled() #### Fabric fi = anturlar.FabricInfo() sid_nums = fi.sid_numbers() sw_cnt = fi.switch_count() ipv4_lst = fi.ipv4_list() print("$"*80) print(ipv4_lst) print("@"*80) ipv4_fcr = fi.ipv4_plus_fcr_list('root','password') print("$"*80) print(ipv4_fcr) print("@"*80) fab_name = fi.name() fab_all = fi.all_info() fab_memb = fi.fabric_members() fab_zone = fi.zone_info() ##### FCIP info # fc = anturlar.FcipInfo() fc_ge_ports = fc.all_online_ge_ports() fc_ge_ports_dble = fc.all_ge_port_disabled() fc_vex_ports = fc.vex_ports() fc_ex_ports = fc.ex_ports() fc_ge_ports = fc.ge_ports() #### DATE TIME STUFF #### dt = liabhar.dateTimeStuff() crrnt_date = dt.current() time_stamp = dt.stamp() time_simple = dt.simple() #### other stuff print("\r\n"*5) print(crrnt_date) print(time_stamp) print(time_simple) liabhar.cls() liabhar.count_down(3) some_string_0 = "this is to compare different text strings" some_string_1 = "this is to compare diff erent text strings" some_string_2 = "this is to compare different text strings" case_1_diff = liabhar.diff_compare(some_string_0, some_string_1) case_2_diff = liabhar.diff_compare(some_string_0, some_string_2) print("result of case 1 diff test %s " % case_1_diff ) print("result of case 2 diff test %s " % case_2_diff ) this_pltfrm_is = liabhar.platform() print("this platform is %s " % this_pltfrm_is ) print(liabhar.random_number()) print(liabhar.random_number_int(23)) #### COFRA bld_port_map_info = cofra.bladeportmap_Info(3) port_stats_0 = cofra.PortStats() fid_to_check = "24" fids_0 = cofra.fids_check(fid_to_check) print("THIS IS FID CHECK %s is on the switch %s " % (fid_to_check, fids_0 )) print("Blade Port Map Info ") print(bld_port_map_info) print("PORT STATS ") print(port_stats_0) clr_stats = cofra.clear_stats()
def main(): global tn ############################################################################### #### #### #### ############################################################################### pa = parse_args(sys.argv) #print(pa) #print(pa.chassis_name) #print(pa.ipaddr) #print(pa.quiet) #print(pa.verbose) #print(pa.firmware) print(porttype) print("@" * 40) sys.exit() ########################################################################## ########################################################################## ### ### hold the ip address from the command line ### if pa.ipaddr: pa.chassis_name = console_info_from_ip(pa.ipaddr, pa.chassis_name) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] tn = anturlar.connect_tel_noparse(pa.ipaddr, user_name, usr_psswd) fi = anturlar.FabricInfo() si = anturlar.SwitchInfo() #fcr = anturlar.FcrInfo() if pa.fabwide: ipaddr_switch = fi.ipv4_list() elif pa.csvall: ipaddr_switch = get_ip_from_file(pa.chassis_name) elif pa.fcrwide: anturlar.fos_cmd("setcontext %s" % fcr.base_check()) ipaddr_switch = fcr.fcr_fab_wide_ip() else: ipaddr_switch = [pa.ipaddr] anturlar.close_tel() #### pass ip(s)to login procedure #### and write the file for i in ipaddr_switch: try: tn = anturlar.connect_tel_noparse(i, user_name, usr_psswd) except OSError: print("Switch %s not available" % i) nos = si.nos_check() if not nos: #print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") f_ports = si.f_ports() e_ports = si.e_ports() print(fports) print(eports) sys.exit() #devices = fcr.fcr_proxy_dev() print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") fabric_check = fi.fabric_members() #print(fabric_check) f = ('logs/PortFlapper.txt') try: with open(f, 'w') as file: file.write("F-Ports = %s\n" % str(fports)) file.write("E-Ports = %s\n" % str(eports)) except IOError: print("\n\nThere was a problem opening the file:", f) sys.exit() file.close() print(eports ) ################ if...else statement to use eport or fport for i in eports: slot = i[0] port = i[1] if slot: anturlar.fos_cmd("portdisable %s/%s" % (slot, port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s/%s" % (slot, port)) liabhar.count_down(15) else: anturlar.fos_cmd("portdisable %s" % (port)) liabhar.count_down(15) anturlar.fos_cmd("portenable %s" % (port)) liabhar.count_down(15) fabric_check1 = fi.fabric_members() if fabric_check != fabric_check1: print("WTF") #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" ) liabhar.email_sender_html("*****@*****.**", "*****@*****.**", "portflapper failed", "portflapper failed", "") sys.exit() liabhar.email_sender_html("*****@*****.**", "*****@*****.**", "portflapper passed", "portflapper passed", "") anturlar.close_tel() return (True) else: print("\n" + "@" * 40) print('\nTHIS IS A NOS SWITCH> SKIPPING') print("\n" + "@" * 40) pass anturlar.close_tel() sys.exit()
def main(): global tn # variable for telnet session pa = parse_args() # print(pa) # print(pa.chassis_name) # print(pa.ipaddr) # print(pa.quiet) # print(pa.verbose) # print(pa.firmware) # print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### # # if user enter ip address then get the chassisname from the SwitchMatrix file # then get the info from the SwitchMatrix file using the Chassis Name # # # if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) # cons_info = console_info(pa.chassis_name) # console_ip = cons_info[0] # console_port = cons_info[1] # console_ip_bkup = cons_info[2] # console_port_bkup = cons_info[3] # power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) # steps_to_run = pa.steps ################################################################################################################### # if the user does not enter a value for which steps to run prompt for user input value # # if not steps_to_run: # pa.start = user_start() # steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### # # configure some settings that are not defualt to confirm they remain after disruptions # # cons_out = send_cmd("creditrecovmode --cfg onLrThresh") # cons_out = send_cmd("creditrecovmode --fe_crdloss off") # cons_out = send_cmd("creditrecovmode --be_crdloss off") # cons_out = send_cmd("creditrecovmode --be_losync off") # cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### # # capture the configuration file if the user selected 1 or 3 # # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") # switch_info_orig = capture_switch_info("compare_orig", fid_to_compare) ###### File to compare before operations # switchdata_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) ################################################################################################################### # path to the first file to compare # switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # liabhar.JustSleep(10) ################################################################################################################### # this is how to reconnect with telnet # print("reconnect via telnet") # tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ################################################################################################################### ################################################################################################################### ################################################################################################################### # # do configupload or other test steps here # make other changes here before configupload or other commands # ################################################################################################################ # # hafailover or hareboot on pizza box # call the failover function from cofra and send the number of failovers # capture_switch_info("switch_info_orig", pa.fid) # Original File1 # if steps_to_run == 1: # print('\n\nFile written') # sys.exit(0) g = pa.iterations tn = cofra.ha_failover(g) liabhar.count_down(30) capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch diff_f = liabhar.file_diff(orig, compare, "HA_FAILOVER_DIFFERENCES") print(diff_f) # g = g-1 if not diff_f: liabhar.email_sender_html(pa.email, pa.email, "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint.\ Look in logs for HA_FAILOVER_DIFFERENCES file", "") cofra.DoSupportsave(ftp_ip, ftp_username, ftp_password, pa.chassis_name) print("Support Save captured") sys.exit(0) # g = pa.iterations # print(g) # while g > 0: # tn = cofra.ha_failover(g) # liabhar.count_down(60) # capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations # orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch # compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch # diff_f = liabhar.file_diff(orig, compare) # print(diff_f) # # g = g-1 # if not diff_f: # liabhar.email_sender_html(pa.email, pa.email, # "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint", "") # cofra.DoSupportsave("172.16.114.67", "ftp1", "ftp2", pa.chassis_name) # sys.exit(1) # g = g - 1 ################################################################################################################### # # power cycle slots # # ss = anturlar.SwitchInfo() # slot_list = ss.blades(True) # skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # # # # other interuptions # # ################################################################################################################### ################################################################################################################### ################################################################################################################### # if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) # liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") ################################################################################################################### liabhar.cls() print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(orig, compare) print(diff_f) print('\n\n') print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) ################################################################################################################### # put additional commands here before disconnecting from telnet # # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) liabhar.email_sender_html (pa.email, pa.email, "HA_Failover passed", "HA_Failover passed", "")
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 fid_to_compare = pa.fid ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: # pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrthreshold 7") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture teh configuration file if the user selected 1 or 3 #### if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") switch_info = capture_switch_info("compare_orig", fid_to_compare) ################################################################################################################### #### path to the first file to compare # switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch switch_data_0 = "/home/runfromhere/logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### REBOOT and RECONNECT WAIT 60 SECONDS and CONTINUE #### print("START Switch Update Class") liabhar.JustSleep(10) pp = cofra.SwitchUpdate() # tn = pp.reboot_reconnect() # liabhar.count_down(60) ################################################################################################################### #### #### hafailover or hareboot on pizza box #### call the failover function from cofra and send the number of failovers #### print("START HA FAILOVER") liabhar.JustSleep(10) tn = cofra.ha_failover(100) liabhar.count_down(600) ################################################################################################################### #### #### power cycle slots #### ss = anturlar.SwitchInfo() slot_list = ss.blades(True) #### skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # #### #### #### other interuptions #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") switch_info = capture_switch_info("compare", fid_to_compare) ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() #### compare the two files print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) print("Result ") print(diff_f) ################################################################################################################### #### put additional commands here before disconnecting from telnet #### # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) print(type(steps_to_run)) print(steps_to_run)
def main(): global tn ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) #print(pa) print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.delay_before_on) print(pa.delay_before_next_off) print(pa.count_power_cycles) print("@"*40) ################################################################################################################### ################################################################################################################### #### #### get the info from the SwitchMatrix file using the Chassis Name #### #### the only args required are chassisname #### power_pole_info = pwr_pole_info(pa.chassis_name) ################################################################################################################### ################################################################################################################### #### # ####################################################################################################################### # #### # #### # #### ####################################################################################################################### ####################################################################################################################### #### this step is the same for director or pizza box #### #### turn each port off then turn each port on (otherwise the delay between did not power cycle the switch) #### ####################################################################################################################### liabhar.count_down(20) cycles = 0 while cycles < pa.count_power_cycles: pass for pp in range(0, len(power_pole_info), 2): print('POWERPOLE') print(power_pole_info[pp]) print(power_pole_info[pp+1]) #pwr_cycle(power_pole_info[pp],power_pole_info[pp+1], "off" ,10) #time.sleep(4) try: for pp in range(0, len(power_pole_info), 2): print('POWERPOLE') print(power_pole_info[pp]) print(power_pole_info[pp+1]) pwr_cycle(power_pole_info[pp],power_pole_info[pp+1], "off",10) time.sleep(4) liabhar.count_down(pa.delay_before_on) for pp in range(0, len(power_pole_info), 2): print('POWERPOLE') print(power_pole_info[pp]) print(power_pole_info[pp+1]) pwr_cycle(power_pole_info[pp],power_pole_info[pp+1], "on",10) time.sleep(4) except: if '' == power_pole_info[0]: print("\n"*20) print("NO POWER POLE INFO FOUND ") print("HA "*10) print("you have to walk to power cycle the switch") print("I will wait ") liabhar.JustSleep(30) else: print("POWER TOWER INFO") print(power_pole_info[0]) print(power_pole_info) liabhar.JustSleep(30) cycles += 1 print("power cycle %s of %s" % (cycles, pa.count_power_cycles) ) liabhar.JustSleep(6) liabhar.count_down(pa.delay_before_next_off) ####################################################################################################################### ####################################################################################################################### #### #### #### ####################################################################################################################### dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is)
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print(pa.iterations) print(pa.porttype) print("@"*40) print("@"*40) #sys.exit() ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### if pa.ipaddr: print("do IP steps") pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr) cons_info = sw_matrix_tools.console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name) usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet: #### if you want to connect to the console it is available in anturlar and an example is available below #### #### ###################################################################################################################### ###################################################################################################################### #### Config_up_down_compare.main() #cons_out = anturlar.fos_cmd("firmwareshow") #### send any command with anturlar.fos_cmd #print("\r\n") #liabhar.JustSleep(5) #### sleep without printing anything #print(cons_out) # print("now closing telnet session ") # #anturlar.close_tel() #### close the telnet session ####################################################################################################################### ####################################################################################################################### #### #### connect via console example and other "send command" commands #### #### ####################################################################################################################### ####################################################################################################################### #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) #### connect to console w/o parser info #cons_out = anturlar.fos_cmd("firmwareshow") #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) #### change to the fid given on the command #tn = anturlar.connect_console(console_ip,console_port) #### use the console ip and console port info #cons_out = anturlar.fos_cmd("switchshow") #### send a command via the console #cons_out = cofra.power_cycle(power_pole_info) #### powercycle switch via switchmatrix.csv file #liabhar.JustSleep(30) #### wait for the switch to boot #cons_out = anturlar.send_cmd_console("\r\n") #### send some commands to the console #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid) #### send some commands to the console #cons_out = anturlar.send_cmd_console("firmwareshow") #### send some commands to the console #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2") #### send a cfgupload file to a ftp server #liabhar.count_down(5) #### set and observe a count down timer ####################################################################################################################### ####################################################################################################################### #### #### This starts the template for configshow output comparison (after some type of switch operation). #### First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file. #### ####################################################################################################################### ####################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid) dt = liabhar.dateTimeStuff() #### create the object for date and time stuff date_is = dt.current_no_dash_at_end() #### get the current time for file naming purposes #print("\n\nDate is %s" % date_is) liabhar.count_down(3) #### count down to the next command #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2") f = "%s%s%s%s"%("logs/NameServer_test_case_file","_"+ipaddr_switch+"_",date_is,".txt") f1 = "%s%s%s%s"%("logs/NameServer_test_case_file_compare","_"+ipaddr_switch+"_",date_is,".txt") ff = liabhar.FileStuff(f, 'w+b') #### open the log file for writing #header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch,"\n==============================\n\n") #### write a header line at top of file header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch, "\n==============================\n\n") ff.write(header) ff.write(anturlar.fos_cmd("nsshow")) ff.write(anturlar.fos_cmd("nsallshow")) ff.write(anturlar.fos_cmd("configshow")) ff.close() g = open(f, "r") lines = g.readlines() g.close() ff = liabhar.FileStuff(f, 'w+b') for l in lines: if " date = " not in l: ff.write(l) ff.close() #### close this file for comparison later ####################################################################################################################### ####################################################################################################################### #### #### do anything else you want to try (small sample of examples): #### anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### anturlar.fos_cmd("cfgenable") #### anturlar.fos_cmd("switchdisable") #### anturlar.fos_cmd("switchenable") #### #### In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver") #### Then grab output of configshow, drop into a file and compare that with original #### ####################################################################################################################### ####################################################################################################################### # tn = cofra.clear_stats() # print(pa.porttype) # #sys.exit() # porttype = pa.porttype # print(porttype) # PortFlapper.main(porttype) ############################################################################################# si = anturlar.SwitchInfo() fi = anturlar.FabricInfo() fabric_check = fi.fabric_members() f_ports = si.f_ports() e_ports = si.e_ports() if pa.porttype == "eports": ports = e_ports print("\n\n\n\n") print(e_ports) else: ports = f_ports print("\n\n\n\n") print(f_ports) i = ipaddr_switch # try: # tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd) # except OSError: # print("Switch %s not available" % i) nos = si.nos_check() if not nos: h = pa.iterations for i in range(h): print("\n\nWe are on loop number:") print(i+1) print("\n\n") for i in ports: slot = i[0] port = i[1] if slot: anturlar.fos_cmd("portdisable %s/%s" % (slot, port)) liabhar.count_down(5) anturlar.fos_cmd("portenable %s/%s" % (slot, port)) liabhar.count_down(5) else: anturlar.fos_cmd("portdisable %s" % (port)) liabhar.count_down(5) anturlar.fos_cmd("portenable %s" % (port)) liabhar.count_down(5) #g = g-1 fabric_check1 = fi.fabric_members() if fabric_check != fabric_check1: print ("WTF") #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" ) liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed becasue of Fabric Check","NS_portflapper failed because of Fabric Check","") anturlar.close_tel() sys.exit() ff = liabhar.FileStuff(f1, 'w+b') #### reset the log file #header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch, "\n==============================\n\n") header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", " sw_info ipaddr ",ipaddr_switch, "\n==============================\n\n") ff.write(header) ff.write(anturlar.fos_cmd("nsshow")) ff.write(anturlar.fos_cmd("nsallshow")) ff.write(anturlar.fos_cmd("configshow")) ff.close() g = open(f1,"r") lines = g.readlines() g.close() ff = liabhar.FileStuff(f1, 'w+b') for l in lines: if " date = " not in l: ff.write(l) ff.close() diff_f = liabhar.file_diff(f,f1) print(diff_f) if not diff_f: liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed a checkpoint","NS_portflapper failed a checkpoint","") sys.exit() else: print("\n"+"@"*40) print('\nTHIS IS A NOS SWITCH> SKIPPING') print("\n"+"@"*40) liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed becasue of NOS Check","NS_portflapper failed because of NOS Check","") sys.exit() anturlar.close_tel() print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper passed","NS_portflapper passed","") return(True) sys.exit()
def chck_a(): #global tn si = anturlar.SwitchInfo() does_allow_xisl = si.allow_xisl() show_all_ports = si.all_ports() show_all_ports_fc = si.all_ports_fc_only() base_y_n = si.base_check() blade_8G = si.blade_search_8GB() blades = si.blades() blade_blank = si.blank_type() fid_now = si.currentFID() chass_name = si.chassisname() dport = si.d_ports() dflt_switch = si.default_switch() dir_y_n = si.director() disbled_ports = si.disabled_ports() eports = si.e_ports() exports = si.ex_ports() vexports = si.vex_ports() fports = si.f_ports() fans = si.fan_count() fcr_y_n = si.fcr_enabled() gports = si.g_ports() lic_lst = si.getLicense() sw_ip = si.ipaddress() lport = si.loopback() ls_lst = si.ls() ls_crnt = si.ls_now() nports = si.n_ports() pdports = si.persistent_disabled_ports() sensors_lst_t = si.sensor_t_f_ps("t") sensors_lst_t = si.sensor_t_f_ps("f") sensors_lst_t = si.sensor_t_f_ps("ps") sfpinfo = si.sfp_info() sports = si.sim_ports() swstate = si.switch_state() sw_id = si.switch_id() sw_name = si.switch_name() sw_status = si.switch_status() ### fcr info sw_type = si.switch_type() sw_sync = si.synchronized() sw_tmp = si.temp_sensors() vf_y_n = si.vf_enabled() #### Fabric fi = anturlar.FabricInfo() sid_nums = fi.sid_numbers() sw_cnt = fi.switch_count() ipv4_lst = fi.ipv4_list() print("$" * 80) print(ipv4_lst) print("@" * 80) ipv4_fcr = fi.ipv4_plus_fcr_list('root', 'password') print("$" * 80) print(ipv4_fcr) print("@" * 80) fab_name = fi.name() fab_all = fi.all_info() fab_memb = fi.fabric_members() fab_zone = fi.zone_info() ##### FCIP info # fc = anturlar.FcipInfo() fc_ge_ports = fc.all_online_ge_ports() fc_ge_ports_dble = fc.all_ge_port_disabled() fc_vex_ports = fc.vex_ports() fc_ex_ports = fc.ex_ports() fc_ge_ports = fc.ge_ports() #### DATE TIME STUFF #### dt = liabhar.dateTimeStuff() crrnt_date = dt.current() time_stamp = dt.stamp() time_simple = dt.simple() #### other stuff print("\r\n" * 5) print(crrnt_date) print(time_stamp) print(time_simple) liabhar.cls() liabhar.count_down(3) some_string_0 = "this is to compare different text strings" some_string_1 = "this is to compare diff erent text strings" some_string_2 = "this is to compare different text strings" case_1_diff = liabhar.diff_compare(some_string_0, some_string_1) case_2_diff = liabhar.diff_compare(some_string_0, some_string_2) print("result of case 1 diff test %s " % case_1_diff) print("result of case 2 diff test %s " % case_2_diff) this_pltfrm_is = liabhar.platform() print("this platform is %s " % this_pltfrm_is) print(liabhar.random_number()) print(liabhar.random_number_int(23)) #### COFRA bld_port_map_info = cofra.bladeportmap_Info(3) port_stats_0 = cofra.PortStats() fid_to_check = "24" fids_0 = cofra.fids_check(fid_to_check) print("THIS IS FID CHECK %s is on the switch %s " % (fid_to_check, fids_0)) print("Blade Port Map Info ") print(bld_port_map_info) print("PORT STATS ") print(port_stats_0) clr_stats = cofra.clear_stats()