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 ####################################################################################################################### #### #### 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 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() 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 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 ############################################################################### #### #### #### ############################################################################### 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 # 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 # 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 ####################################################################################################################### #### #### 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)