def enable_flows(ones): """ enable all fea of flows of current switch - get the flow names - enable the flows with all features """ f = anturlar.FlowV() the_names = f.flow_names() print(the_names) for k in the_names: if "sys_gen_all_simports" in k: print("not enabling this one", k) else: cmd_create = ("flow --activate %s -fea all" % k) cons_out = anturlar.fos_cmd(cmd_create)
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 capture_switch_info(extend_name="", fid=128): """ """ si = anturlar.SwitchInfo() mi = anturlar.Maps() fi = anturlar.FlowV() fcr = anturlar.FcrInfo() vdx = si.nos_check() switch_ip = si.ipaddress() switch_cp_ips = si.cp_ipaddrs_get() license_list = si.getLicense() ls_list = si.ls() first_ls = si.ls_now() switch_id = si.switch_id() fid_now = si.currentFID() try: theswitch_name = si.switch_name() except IndexError: theswitch_name = "unknown" pass chassis_name = si.chassisname() director_pizza = si.director() vf_enabled = si.vf_enabled() sw_type = si.switch_type() base_sw = si.base_check() sim_ports = si.sim_ports() ex_ports = fcr.all_ex_ports() fcr_state = si.fcr_enabled() ports_and_ls = si.all_ports_fc_only() psw_reset_value = "YES" xisl_st_per_ls = si.allow_xisl() maps_policy_sum = mi.get_policies() maps_non_dflt_policy = mi.get_nondflt_policies() flow_per_ls = fi.flow_names() blades = si.blades() deflt_switch = si.default_switch() # sfp_info = si.sfp_info() maps_email_cfg = mi.get_email_cfg() maps_actions = mi.get_actions() logical_groups = mi.logicalgroup_count() relay_server_info = mi.get_relay_server_info() credit_recov_info = mi.credit_recovery() dns_info = mi.dns_config_info() ################################################################################################################### ################################################################################################################### #### #### print the variables for review #### ################################################################################################################### ################################################################################################################### print("\n\n\n") print("SWITCH IP : %s " % switch_ip) print("SWITCH NAME : %s " % theswitch_name) # print("SWITCH DOMAIN : %s " % domain_list) print("LS LIST : %s " % ls_list) print("DEFAULT SWITCH : %s " % deflt_switch) print("BASE SWITCH : %s " % base_sw) print("EX_PORTS : %s " % ex_ports) ######################NEW print("VF SETTING : %s " % vf_enabled) print("SWITCH TYPE : %s " % sw_type) print("TIMEOUT VALUE : 0 ") print("RESET PASSWORD : %s " % psw_reset_value) print("FCR ENABLED : %s " % fcr_state) print("BLADES : %s " % blades) print("LICENSE LIST : %s " % license_list) ####################################################################################################################### ####################################################################################################################### ####################################################################################################################### #### #### Write to the file #### ####################################################################################################################### ####################################################################################################################### ####################################################################################################################### # f = "%s%s%s" % ("logs/Switch_Info_cudc", switch_ip, "_%s.txt" % extend_name) f = "%s%s%s" % ("/home/runfromhere/logs/Switch_Info_cudc", switch_ip, "_%s.txt" % extend_name) header = "%s%s%s%s" % ("\nSwitch_info_for_playback CAPTURE FILE \n", \ "", "", "==============================\n") ff = liabhar.FileStuff(f, 'w+b') #### open the log file for writing ff.write(header) ################################################################################################################### ff.write("SWITCH IP : %s \n" % switch_ip) ff.write("LS LIST : %s \n" % ls_list) ff.write("DEFAULT SWITCH : %s \n" % deflt_switch) ff.write("BASE SWITCH : %s \n" % base_sw) ff.write("EX_PORTS : %s \n" % ex_ports) ff.write("SWITCH NAME : %s \n" % theswitch_name) ff.write("CHASSIS NAME : %s \n" % chassis_name) ff.write("DIRECTOR STATUS : %s \n" % director_pizza) ff.write("VF SETTING : %s \n" % vf_enabled) ff.write("SWITCH TYPE : %s \n" % sw_type) ff.write("TIMEOUT VALUE : 0 \n") ff.write("RESET PASSWORD : %s \n" % psw_reset_value) ff.write("FCR ENABLED : %s \n" % fcr_state) ff.write("Ports : %s \n" % ports_and_ls) ff.write("SIM PORTS : %s \n" % sim_ports) ff.write("Blades : %s \n" % blades) ff.write("LICENSE LIST : %s \n" % license_list) #ff.write("SFP INFO : %s \n" % sfpinfo) ff.write("=" * 80) ff.write("\n") ff.write("MAPS POLICIES : %s \n" % maps_policy_sum) ff.write("MAPS NON DFLT POLICIES : %s \n" % maps_non_dflt_policy) ff.write("EMAIL CFG : %s \n" % maps_email_cfg) ff.write("MAPS ACTIONS : %s \n" % maps_actions) ff.write("LOGICAL GROUPS : %s \n" % logical_groups) ff.write("RELAY SERVER HOST IP : %s \n" % relay_server_info) ff.write("CREDIT RECOVERY INFO : %s \n" % credit_recov_info) ff.write("DNS CONFIG INFO : %s \n" % dns_info) ff.write("=" * 80) ff.write("\n") ff.write("FLOW CONFIGURATION : %s \n" % flow_per_ls) ff.write("\n" * 2) ff.close() # cons_out = anturlar.fos_cmd("setcontext %s " % fid_now) return (True)
def fabric_switch_config_show(): """ document how this works here 1. Retreive a list of all of the switches in the FID passed at start of the test 2. get Flow and MAPS basic setup information 3. write to logs/fabric_info_switch.txt """ cons_out = anturlar.fos_cmd("") swtch = anturlar.SwitchInfo() fab = anturlar.FabricInfo() fab_ip_list = fab.ipv4_list() this_fid = swtch.currentFID() ############################################################################### ############################################################################### #### #### write to the file the list of IP addresses that data will be captured for #### ############################################################################### ############################################################################### fname = "%s%s" % ("logs/fabric_info_logs/fabric_info_switch", ".txt" ) #### %s string %d number ff = liabhar.FileStuff(fname, 'w+b') ff.write( "#############################################################\r\n") ff.write( "#############################################################\r\n") ff.write("\r\n") for ip in fab_ip_list: ff.write(ip) ff.write("\r\n") ff.write( "#############################################################\r\n") ff.write( "#############################################################\r\n") ff.write( "#############################################################\r\n") ff.write( "#############################################################\r\n\r\n\r\n" ) ff.close() m_info = anturlar.Maps() f_info = anturlar.FlowV() maps_config = anturlar.fos_cmd("mapsconfig --show") firmware_ver = check_version() s_name = m_info.switch_name() s_type = m_info.switch_type() ls_list = m_info.ls() switch_id = m_info.switch_id() ls_domain = m_info.ls_and_domain() chass_name = m_info.chassisname() vf_state = m_info.vf_enabled() ff = liabhar.FileStuff(fname, 'a+b') ff.write("Seed switch Info \n") ff.write( "---------------------------------------------------------------------------------\n" ) ff.write("Switch ipv4 : %s \r\n" % ip) ff.write("Chassis Name : %s \r\n" % chass_name) ff.write("Firmware version : %s \r\n" % firmware_ver) ff.write("Switch Name : %s \r\n" % s_name) ff.write("Switch Type : %s \r\n" % s_type) ff.write("VF State : %s \r\n" % vf_state) ff.write("Logical Switches : %s \r\n" % ls_list) ff.write("Switch ID : %s \r\n" % switch_id) ff.write("ls and domain : %s \r\n" % ls_domain) ############################################################################### ############################################################################### #### #### loop through each switch in the fabric and collect and write the MAPS and Flow Info #### ############################################################################### for ip in fab_ip_list: tnn = anturlar.connect_tel_noparse(ip, 'root', 'password') cons_out = anturlar.fos_cmd("setcontext %s " % this_fid) m_info = anturlar.Maps() f_info = anturlar.FlowV() maps_config = anturlar.fos_cmd("mapsconfig --show") maps_policy_list = m_info.get_policies() maps_active_policy = m_info.get_active_policy() non_dflt_policy = m_info.get_nondflt_policies() flow_names = f_info.flow_names() flows_nondflt = f_info.get_nondflt_flows() flows_active = f_info.get_active_flows() #flow_cnfg = f_info.flow_config() flow_details = f_info.get_flow_details() anturlar.close_tel() ####### ####### remove line switchname FID ?? root> ####### m_no_root = s_name + ":FID" + str(this_fid) + ":root>" m = maps_config.replace(m_no_root, '') mc = m.lstrip() #### remove leading white space ####### ####### remove line switchname FID ?? root> ####### #### #### leave as capturing data for only one FID at a time #### have a switch for all fid data #### #### seperator(ff, ip) ff.write( "---------------------------------------------------------------------\r\n" ) #ff.write("MAPS config : %s \r\n" % maps_config) ff.write( "MAPS config :\r\n") ## maps config header ff.write(mc) ## write maps config ff.write( "\n---------------------------------------------------------------------\r\n" ) ff.write("MAPS Policy List : %s \r\n" % maps_policy_list) ff.write("MAPS Active Policy : %s \r\n" % maps_active_policy) ff.write("MAPS Non Default Policy : %s \r\n" % non_dflt_policy) ff.write( "---------------------------------------------------------------------\r\n" ) ff.write("FLOW Names list : %s \r\n" % flow_names) ff.write("FLOW non dflt Flows : %s \r\n" % flows_nondflt) ff.write("FLOWs Active : %s \r\n" % flows_active) ff.write("FLOW Details : %s \r\n" % flow_details) ff.write( "---------------------------------------------------------------------\r\n" ) ff = liabhar.FileStuff(fname, 'a+b') ff.write( "#####################################################################\r\n" ) ff.write( "#####################################################################\r\n" ) ff.write("##########\r\n") ff.write( "########## FABRIC SWITCHES INFO ##########\r\n" ) ff.write("##########\r\n") ff.write( "#####################################################################\r\n" ) for ip in fab_ip_list: tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password') firmware_ver = check_version() chass_name = m_info.chassisname() sf = "{0:18} {1:25} {2:25}" print(sf.format(str(ip), str(chass_name), str(firmware_ver)), file=ff) ff.write("\r\n") ff.write( "#####################################################################\r\n" ) ff.write( "#####################################################################\r\n" ) ff.write( "#####################################################################\r\n" ) ff.write( "#####################################################################\r\n" ) ff.write( "#####################################################################\r\n" ) ff.close() print("\n") print("#" * 120) print( "\nFind the results in logs/fabric_info_logs/fabric_info_switchtxt\n" ) print("#" * 120) print("\n" * 10) return (True)
def switch_config_show(): """ get information for a switch for each FID """ cons_out = anturlar.fos_cmd("") swtch = anturlar.SwitchInfo() fab = anturlar.FabricInfo() #fab_ip_list = fab.ipv4_list() ip = swtch.ipaddress() this_fid = swtch.currentFID() fname = "%s%s" % ("logs/Switch_info_per_FID_", ".txt" ) #### %s string %d number ff = liabhar.FileStuff(fname, 'w+b') ff.write( "#############################################################\r\n") ff.close() tnn = anturlar.connect_tel_noparse(ip, 'root', 'password') ff = liabhar.FileStuff(fname, 'a+b') ls_list_fids = swtch.ls() m_info = anturlar.Maps() f_info = anturlar.FlowV() firmware_ver = check_version() s_type = m_info.switch_type() ls_list = m_info.ls() switch_id = m_info.switch_id() ls_domain = m_info.ls_and_domain() chass_name = m_info.chassisname() vf_state = m_info.vf_enabled() ff.write("Switch ipv4 : %s \r\n" % ip) ff.write("Chassis Name : %s \r\n" % chass_name) ff.write("Firmware version : %s \r\n" % firmware_ver) #ff.write("Switch Name : %s \r\n" % s_name) ff.write("Switch Type : %s \r\n" % s_type) ff.write("VF State : %s \r\n" % vf_state) ff.write("Logical Switches : %s \r\n" % ls_list) ff.write("Switch ID : %s \r\n" % switch_id) ff.write("ls and domain : %s \r\n" % ls_domain) print(ls_list_fids) for i in ls_list_fids: print(i) print("\n" * 10) for ls in ls_list_fids: cons_out = anturlar.fos_cmd("setcontext %s " % ls) s_name = m_info.switch_name() maps_policy_list = m_info.get_policies() maps_active_policy = m_info.get_active_policy() non_dflt_policy = m_info.get_nondflt_policies() flow_names = f_info.flow_names() flows_nondflt = f_info.get_nondflt_flows() flows_active = f_info.get_active_flows() flow_details = f_info.get_flow_details() #flow_cnfg = f_info.flow_config() maps_config = anturlar.fos_cmd("mapsconfig --show") ####### ####### remove line switchname FID ?? root> ####### print("\n" * 4) print(maps_config) print("\n" * 4) m_no_root = s_name + ":FID" + str(ls) + ":root>" #m_no_name = maps_config.replace(s_name ,'') #m_no_fid = m_no_name.replace(str(this_fid), '') m = maps_config.replace(m_no_root, '') print("\n" * 4) print(m) print("\n" * 4) ####### ####### remove line switchname FID ?? root> ####### seperator_switch(ff, ls) ff.write("Switch Name : %s \r\n" % s_name) ff.write( "---------------------------------------------------------------------\r\n" ) #ff.write("MAPS config : %s \r\n" % maps_config) ff.write("MAPS config : \r\n\r\n %s \r\n" % m) ## maps config ff.write( "---------------------------------------------------------------------\r\n" ) ff.write("MAPS Policy List : %s \r\n" % maps_policy_list) ff.write("MAPS Active Policy : %s \r\n" % maps_active_policy) ff.write("MAPS Non Default Policy : %s \r\n" % non_dflt_policy) ff.write( "---------------------------------------------------------------------\r\n" ) ff.write("FLOW Names list : %s \r\n" % flow_names) ff.write("FLOW non dflt Flows : %s \r\n" % flows_nondflt) ff.write("FLOWs Active : %s \r\n" % flows_active) ff.write("FLOW Details : %s \r\n" % flow_details) ff.write( "---------------------------------------------------------------------\r\n" ) ff.close() anturlar.close_tel()
def capture_switch_info(extend_name="", fid=128): """ capture switch info to compare """ si = anturlar.SwitchInfo() mi = anturlar.Maps() fi = anturlar.FlowV() switch_ip = si.ipaddress() switch_cp_ips = si.cp_ipaddrs_get() license_list = si.getLicense() ls_list = si.ls() first_ls = si.ls_now() switch_id = si.switch_id() fid_now = si.currentFID() chassis_name = si.chassisname() director_pizza = si.director() vf_enabled = si.vf_enabled() sw_type = si.switch_type() base_sw = si.base_check() blades = si.blades() deflt_switch = si.default_switch() dns_info = mi.dns_config_info() ####################################################################################################################### ####################################################################################################################### ####################################################################################################################### #### #### Write to the file #### ####################################################################################################################### ####################################################################################################################### ####################################################################################################################### f = "%s%s%s"%("logs/Switch_Info_cudc",switch_ip,"_%s.txt" % extend_name) header = "%s%s%s%s" % ("\nSwitch_info_for_playback CAPTURE FILE \n",\ "","", "==============================\n") ff = liabhar.FileStuff(f, 'w+b') #### open the log file for writing ff.write(header) ################################################################################################################### ff.write("SWITCH IP : %s \n" % switch_ip) ff.write("CP IP : %s \n" % switch_cp_ips) ff.write("LICENSE LIST : %s \n" % license_list) ff.write("LS LIST : %s \n" % ls_list) ff.write("LS Test Start : %s \n" % first_ls) ff.write("Switch ID : %s \n" % switch_id) ff.write("Current FID : %s \n" % fid_now) ff.write("CHASSIS NAME : %s \n" % chassis_name) ff.write("DIRECTOR STATUS : %s \n" % director_pizza) ff.write("VF SETTING : %s \n" % vf_enabled) ff.write("SWITCH TYPE : %s \n" % sw_type) ff.write("BASE SWITCH : %s \n" % base_sw) ff.write("Blades : %s \n" % blades) ff.write("DEFAULT SWITCH : %s \n" % deflt_switch) ff.write("DNS CONFIG INFO : %s \n" % dns_info) for l in ls_list: cons_out = anturlar.fos_cmd("setcontext %s " % l ) try: theswitch_name = si.switch_name() except IndexError: theswitch_name = "unknown" pass sim_ports = si.sim_ports() ports_and_ls = si.all_ports_fc_only() xisl_st_per_ls = si.allow_xisl() maps_policy_sum = mi.get_policies() maps_non_dflt_policy = mi.get_nondflt_policies() flow_per_ls = fi.flow_names() maps_email_cfg = mi.get_email_cfg() maps_actions = mi.get_actions() logical_groups = mi.logicalgroup_count() relay_server_info = mi.get_relay_server_info() credit_recov_info = mi.credit_recovery() sfpinfo = si.sfp_info() ff.write("="*80) ff.write("\n") ff.write("="*80) ff.write("\n") ff.write("FID %s \n" % l) ff.write("SWITCH NAME : %s \n" % theswitch_name) ff.write("SIM PORTS : %s \n" % sim_ports) ff.write("Ports : %s \n" % ports_and_ls) ff.write("XISL state : %s \n" % xisl_st_per_ls) ff.write("MAPS POLICIES : %s \n" % maps_policy_sum ) ff.write("MAPS NON DFLT POLICIES : %s \n" % maps_non_dflt_policy) ff.write("FLOW CONFIGURATION : %s \n" % flow_per_ls) ff.write("EMAIL CFG : %s \n" % maps_email_cfg) ff.write("MAPS ACTIONS : %s \n" % maps_actions) ff.write("LOGICAL GROUPS : %s \n" % logical_groups) ff.write("RELAY SERVER HOST IP : %s \n" % relay_server_info) ff.write("CREDIT RECOVERY INFO : %s \n" % credit_recov_info) ff.write("SFP INFO : %s \n" % sfpinfo) ff.write("\n") ff.write("=END"*20) ff.write("\n") ff.close() cons_out = anturlar.fos_cmd("setcontext %s " % fid_now) return(True)
def fabric_switch_config_show(): """ document how this works here 1. Retreive a list of all of the switches in the FID passed during start 2. get Flow and MAPS basic setup information """ cons_out = anturlar.fos_cmd("") swtch = anturlar.SwitchInfo() fab = anturlar.FabricInfo() fab_ip_list = fab.ipv4_list() this_fid = swtch.currentFID() fname = "%s%s" % ("logs/fabric_info_switch" ,".txt") #### %s string %d number ff = liabhar.FileStuff(fname, 'w+b') ff.write("#############################################################\r\n") ff.write("#############################################################\r\n") ff.write("\r\n") for ip in fab_ip_list: ff.write(ip) ff.write("\r\n") ff.write("#############################################################\r\n") ff.write("#############################################################\r\n") ff.write("#############################################################\r\n") ff.write("#############################################################\r\n\r\n\r\n") ff.close() #ff = liabhar.FileStuff(fname, 'a+b') #for ip in fab_ip_list: # tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password') # firmware_ver = check_version() # # ip_firm_ver_pair = "%s %s" % ( ip,firmware_ver) # # ff.write("\r\n") # ff.write(ip_firm_ver_pair) # #ff.write("\r\n") #ff.write("#############################################################\r\n") #ff.write("#############################################################\r\n") #ff.write("#############################################################\r\n") #ff.write("#############################################################\r\n") #ff.write("#############################################################\r\n") #ff.close() m_info = anturlar.Maps() f_info = anturlar.FlowV() maps_config = anturlar.fos_cmd("mapsconfig --show") firmware_ver = check_version() s_name = m_info.switch_name() s_type = m_info.switch_type() ls_list = m_info.ls() switch_id = m_info.switch_id() ls_domain = m_info.ls_and_domain() chass_name = m_info.chassisname() vf_state = m_info.vf_enabled() ff = liabhar.FileStuff(fname, 'a+b') ff.write("Switch ipv4 : %s \r\n" % ip) ff.write("Chassis Name : %s \r\n" % chass_name) ff.write("Firmware version : %s \r\n" % firmware_ver) ff.write("Switch Name : %s \r\n" % s_name) ff.write("Switch Type : %s \r\n" % s_type) ff.write("VF State : %s \r\n" % vf_state) ff.write("Logical Switches : %s \r\n" % ls_list) ff.write("Switch ID : %s \r\n" % switch_id) ff.write("ls and domain : %s \r\n" % ls_domain) for ip in fab_ip_list: tnn = anturlar.connect_tel_noparse(ip, 'root', 'password') cons_out = anturlar.fos_cmd("setcontext %s " % this_fid) maps_policy_list = m_info.get_policies() maps_active_policy = m_info.get_active_policy() non_dflt_policy = m_info.get_nondflt_policies() flow_names = f_info.flow_names() flows_nondflt = f_info.get_nondflt_flows() flows_active = f_info.get_active_flows() #flow_cnfg = f_info.flow_config() flow_details = f_info.get_flow_details() anturlar.close_tel() ####### ####### remove line switchname FID ?? root> ####### print("\n"*4) print(maps_config) print("\n"*4) m_no_root = s_name + ":FID" + str(this_fid) + ":root>" #m_no_name = maps_config.replace(s_name ,'') #m_no_fid = m_no_name.replace(str(this_fid), '') m = maps_config.replace(m_no_root, '') print("\n"*4) print(m) print("\n"*4) ####### ####### remove line switchname FID ?? root> ####### #### #### leave as capturing data for only one FID at a time #### have a switch for all fid data #### #### seperator(ff, ip) ff.write("---------------------------------------------------------------------\r\n") #ff.write("MAPS config : %s \r\n" % maps_config) ff.write("MAPS config : \r\n %s \r\n" % m) ## maps config ff.write("---------------------------------------------------------------------\r\n") ff.write("MAPS Policy List : %s \r\n" % maps_policy_list) ff.write("MAPS Active Policy : %s \r\n" % maps_active_policy) ff.write("MAPS Non Default Policy : %s \r\n" % non_dflt_policy) ff.write("---------------------------------------------------------------------\r\n") ff.write("FLOW Names list : %s \r\n" % flow_names) ff.write("FLOW non dflt Flows : %s \r\n" % flows_nondflt) ff.write("FLOWs Active : %s \r\n" % flows_active) ff.write("FLOW Details : %s \r\n" % flow_details) ff.write("---------------------------------------------------------------------\r\n") #ff.write("FLOW CONFIG : \r\n %s \r\n" % flow_cnfg) ff = liabhar.FileStuff(fname, 'a+b') ff.write("#####################################################################\r\n") ff.write("#####################################################################\r\n") ff.write("##########\r\n") ff.write("########## FABRIC SWITCHES INFO ##########\r\n") ff.write("##########\r\n") ff.write("#####################################################################\r\n") #for ip in fab_ip_list: # tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password') # firmware_ver = check_version() # m_info = anturlar.Maps() # chass_name = m_info.chassisname() # # ip_firm_ver_pair = "%s\t\t%s\t\t%s " % ( ip,chass_name,firmware_ver) # # ff.write("\r\n") # ff.write(ip_firm_ver_pair) # #ff.write("\n"*5) for ip in fab_ip_list: tnnn = anturlar.connect_tel_noparse(ip, 'root', 'password') firmware_ver = check_version() m_info = anturlar.Maps() chass_name = m_info.chassisname() sf = "{0:18} {1:25} {2:25}" print(sf.format( str(ip), str(chass_name), str(firmware_ver) ), file=ff) ff.write("\r\n") ff.write("#####################################################################\r\n") ff.write("#####################################################################\r\n") ff.write("#####################################################################\r\n") ff.write("#####################################################################\r\n") ff.write("#####################################################################\r\n") ff.close() return(True)
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) if pa.verbose: print("@" * 40) print("#" * 40) print(pa) print(pa.file) print(pa.quiet) print(pa.verbose) 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 #### ####################################################################################################################### ####################################################################################################################### reg_list = get_info_from_flow_file(pa.file) if pa.verbose: print("\n\ninfo from flow reg file\n\n") print(reg_list) #### this is common steps to get the information from a csv file #### for this test we only need the chassis name and fid for i in range(0, len(reg_list), 2): chass_1 = reg_list[i] target_fid = reg_list[i + 1] print("chassname is %s " % chass_1) print("target fid is %s " % target_fid) #chass_1 = reg_list[0] #target_fid = reg_list[1] #cons_info = sw_matrix_tools.console_info(chass_1) #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(chass_1) usr_pass = sw_matrix_tools.get_user_and_pass(chass_1) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(chass_1) ###################################################################################################################### ###################################################################################################################### #### #### 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 " % target_fid) #### change to the fid given on the command firmware_ver = anturlar.fos_cmd( "firmwareshow") #### send any command with anturlar.fos_cmd flow = anturlar.FlowV() date_is = get_time_stamp() header = "%s" % ("\nFlow Regression Log \n" ) #### write a header line at top of file seperator = "%s" % ("=" * 80) write_to_results_file("\r\n\r\n", ipaddr_switch, date_is) write_to_results_file(header, ipaddr_switch, date_is) write_to_results_file(ipaddr_switch, ipaddr_switch, date_is) write_to_results_file(firmware_ver, ipaddr_switch, date_is) write_to_results_file(seperator, ipaddr_switch, date_is) write_to_results_file(seperator, ipaddr_switch, date_is) #### get the list of flows on the switch flow_all_fport = flow.get_flow_details() #### change the list to a string a = str(flow_all_fport) write_to_results_file(a, ipaddr_switch, date_is) liabhar.cls() ####################################################################################################################### ####################################################################################################################### #### #### ####################################################################################################################### cons_out = anturlar.fos_cmd( "fosexec --fid all -cmd 'flow --deact all'") cons_out = anturlar.fos_cmd("flow --deact all") cons_out = anturlar.fos_cmd( "echo y | flow --delete all -force") #### remove all flows cons_out = anturlar.fos_cmd("flow --act sys_mon_all_fports") liabhar.JustSleep(360) stats = flow.get_egr_stats("sys_mon_all_fports") liabhar.JustSleep(120) write_to_results_file(stats, ipaddr_switch, date_is) result = look_for_zero(stats) #### print the result to a file #### write_pass_fail_to_file(result, ipaddr_switch, date_is) print("@" * 80) print("#" * 80) print(result) print("#" * 80) print("@" * 80) cons_out = anturlar.fos_cmd("flow --deact all") #### find the SID DID pairs and create each monitor #### ras = re.compile('\|([0-9a-f]{1,4})\s+\|([0-9a-f]{6})\|([0-9a-f]{6})') ingr_sid_did_list = ras.findall(stats) if pa.verbose: print("LIST OF FLOWS \n") print(stats) print("regex ") print(ingr_sid_did_list) name_number = 0 for ingr_p, sid, did in ingr_sid_did_list: print(ingr_p) print(sid) print(did) print("\n") cons_out = anturlar.fos_cmd( "flow --create regress_flow_a%s -fea mon -ingrport %s -srcdev %s -dstdev %s -noact " % (name_number, ingr_p, sid, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_b%s -fea mon -ingrport %s -dstdev %s -noact " % (name_number, ingr_p, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_c%s -fea mon -ingrport %s -srcdev %s -noact " % (name_number, ingr_p, sid)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_d%s -fea mon -ingrport %s -srcdev '*' -dstdev %s -noact " % (name_number, ingr_p, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_e%s -fea mon -ingrport %s -srcdev %s -dstdev '*' -noact " % (name_number, ingr_p, sid)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_f%s -fea mon -egrport %s -srcdev %s -dstdev %s -noact " % (name_number, ingr_p, did, sid)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_g%s -fea mon -egrport %s -srcdev %s -noact " % (name_number, ingr_p, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_h%s -fea mon -egrport %s -dstdev %s -noact " % (name_number, ingr_p, sid)) name_number += 1 flow_all = flow.get_nondflt_flows() if pa.verbose: verb_list_print(flow_all) for f in flow_all: cons_out = anturlar.fos_cmd("flow --act %s " % f) #### get the current flow #egrp_flow = flow.get_active_flows() #e = egrp_flow[0] liabhar.JustSleep(120) stats = flow.get_egr_stats(f) liabhar.JustSleep(120) write_to_results_file(stats, ipaddr_switch, date_is) result = look_for_zero(stats) #### print the result to a file #### write_pass_fail_to_file(result, ipaddr_switch, date_is) print("@" * 80) print("#" * 80) print(result) print("#" * 80) print("@" * 80) cons_out = anturlar.fos_cmd("flow --deact all") #### close the telnet session ############################# anturlar.close_tel() #### close the telnet session #liabhar.JustSleep(30) return (True)