Beispiel #1
0
def license_restore(): #### NEED TO ADD supportftp settings AND Timeserver
    """
    Ned to replace sys.argv statements as the order can change on the cli input by user
    """
    host = sys.argv[1]
    user = sys.argv[2]
    password = sys.argv[7]
    print(password)
    si = anturlar.SwitchInfo()
    cn = si.chassisname()
    test_file = '/home/RunFromHere/ini/SwitchLicenses.csv'
    csv_file = csv.DictReader(open(test_file, 'r'), delimiter=',', quotechar='"')
    for line in csv_file:
        a = (type(line))
        switch_name = (line['Nickname'])
        if switch_name == cn[0]:
            del (line[''])
            del (line ['Nickname'])
            del (line['IP Address'])
            a = (list(line.values()))
            for i in a:
                if i != (''):
                    anturlar.fos_cmd("licenseadd %s" % i)
                    liabhar.JustSleep(5)
    anturlar.fos_cmd("echo y | reboot")
    print('\n\nSleeping: 150')
    liabhar.JustSleep(150)   
    anturlar.connect_tel_noparse(host, user, "password")
    anturlar.fos_cmd('licenseshow')
    return(True)
Beispiel #2
0
def license_restore():  #### NEED TO ADD supportftp settings AND Timeserver
    """
    Ned to replace sys.argv statements as the order can change on the cli input by user
    """
    host = sys.argv[1]
    user = sys.argv[2]
    password = sys.argv[7]
    print(password)
    si = anturlar.SwitchInfo()
    cn = si.chassisname()
    test_file = '/home/RunFromHere/ini/SwitchLicenses.csv'
    csv_file = csv.DictReader(open(test_file, 'r'),
                              delimiter=',',
                              quotechar='"')
    for line in csv_file:
        a = (type(line))
        switch_name = (line['Nickname'])
        if switch_name == cn[0]:
            del (line[''])
            del (line['Nickname'])
            del (line['IP Address'])
            a = (list(line.values()))
            for i in a:
                if i != (''):
                    anturlar.fos_cmd("licenseadd %s" % i)
                    liabhar.JustSleep(5)
    anturlar.fos_cmd("echo y | reboot")
    print('\n\nSleeping: 150')
    liabhar.JustSleep(150)
    anturlar.connect_tel_noparse(host, user, "password")
    anturlar.fos_cmd('licenseshow')
    return (True)
Beispiel #3
0
def get_licenses(ip):
    anturlar.connect_tel_noparse(ip,'root','password')
    sw_info = anturlar.SwitchInfo()
    #sw_ip = sw_info.ipaddr
    sw_name = sw_info.switch_name()
    f = "%s%s%s"%("logs/Switch_Licenses/License_File_", sw_name ,".txt")
    ff = liabhar.FileStuff(f,'a+b') ###open new file or clobber old
    header = "%s%s%s%s" % ("\nLICENSE FILE \n", ip+"\n" , sw_name, "\n==============================\n\n")
    cons_out = anturlar.fos_cmd("licenseshow")
    ff.write(header)
    ff.write(cons_out+"\n")
    ff.close()
Beispiel #4
0
def ha_failover_check_frame_log(times=1):
    """
    
    """
    
    
    sw_info = anturlar.SwitchInfo()
    #fid_now = sw_info.ls_now()
    ip_addr = sw_info.ipaddress()
    go_or_not = sw_info.synchronized()
    cons_out = anturlar.fos_cmd(" ")
    username = '******'
    pwrd = 'password'
    #counter = 1
    new_connect = True
  
    liabhar.count_down(10)
    
 
            
    while times > 0:
        cofra.ha_failover(1)
        
        print("\n\n\n")
        print("@"*60)
        print("HA Failovers remaining -- %s " % times)
        print("@"*60)
        anturlar.connect_tel_noparse(ip_addr,'root','password')

    
        times -= 1
    
        flog_status = maps_tools.frameview_status()
        print("$"*80)
        print("$"*80)
        print(flog_status)
        print("$"*80)
        print("$"*80)
        
        if 'Enabled' in flog_status:
            print("Framelog is Enabled")
        elif 'Disabled' in flog_status:
            print("Framelog is Disabled")
            sys.exit()
        else:
            print("Framelog State is UnKnown")
        
        
        
        
    
    return(flog_status)
Beispiel #5
0
def ha_failover_check_frame_log(times=1):
    """
    
    """
    
    
    sw_info = anturlar.SwitchInfo()
    #fid_now = sw_info.ls_now()
    ip_addr = sw_info.ipaddress()
    go_or_not = sw_info.synchronized()
    cons_out = anturlar.fos_cmd(" ")
    username = '******'
    pwrd = 'password'
    #counter = 1
    new_connect = True
  
    liabhar.count_down(10)
    
 
            
    while times > 0:
        cofra.ha_failover(1)
        
        print("\n\n\n")
        print("@"*60)
        print("HA Failovers remaining -- %s " % times)
        print("@"*60)
        anturlar.connect_tel_noparse(ip_addr,'root','password')

    
        times -= 1
    
        flog_status = maps_tools.frameview_status()
        print("$"*80)
        print("$"*80)
        print(flog_status)
        print("$"*80)
        print("$"*80)
        
        if 'Enabled' in flog_status:
            print("Framelog is Enabled")
        elif 'Disabled' in flog_status:
            print("Framelog is Disabled")
            sys.exit()
        else:
            print("Framelog State is UnKnown")
        
        
        
        
    
    return(flog_status)
Beispiel #6
0
def get_licenses(ip):
    anturlar.connect_tel_noparse(ip, 'root', 'password')
    sw_info = anturlar.SwitchInfo()
    #sw_ip = sw_info.ipaddr
    sw_name = sw_info.switch_name()
    f = "%s%s%s" % ("logs/Switch_Licenses/License_File_", sw_name, ".txt")
    ff = liabhar.FileStuff(f, 'a+b')  ###open new file or clobber old
    header = "%s%s%s%s" % ("\nLICENSE FILE \n", ip + "\n", sw_name,
                           "\n==============================\n\n")
    cons_out = anturlar.fos_cmd("licenseshow")
    ff.write(header)
    ff.write(cons_out + "\n")
    ff.close()
Beispiel #7
0
def fcr_state_persist_disabled():
    """
    Check if FCR is disabled, if not bail out and ask user to enable it.
    When FCR is disabled, do a reboot then check FCR is still disabled. 
    """
    host = (sys.argv[1])
    user = sys.argv[2]
    password = sys.argv[7]
    #test_file = '/home/RunFromHere/ini/SwitchMatrix.csv'
    #csv_file = csv.DictReader(open(test_file, 'r'), delimiter=',', quotechar='"')
    fcr_state = fcr_tools.switch_status()
    state = fcr_state['fcr_enabled']
    if state is False: #the same to here disabled is false, enabled is true
        anturlar.fos_cmd("switchdisable")
        print('\n\nSleeping: 10')
        liabhar.JustSleep(10)
        enabled = fcr_tools.switch_status()
        if enabled['fcr_enabled'] is False:
            anturlar.fos_cmd("switchenable")
            print('\n\nSleeping: 10')
            liabhar.JustSleep(10)
            print("\n\nENABLE/DISABLE TEST PASSED")
        else:
            pass
    else:
        print("\n\nENABLE/DISABLE TEST FAILED")
        print("Please disable fcr for this test and try again")
        sys.exit(0)
    print('Sleeping: 10')
    liabhar.JustSleep(10)
    si = anturlar.SwitchInfo()
    cn = si.chassisname()
    a = cofra.switch_power_off_on(cn, 'off')
    print('Sleeping: 20')
    liabhar.JustSleep(20)
    a = cofra.switch_power_off_on(cn, 'on')
    print('Sleeping: 120')
    liabhar.JustSleep(120)
    anturlar.connect_tel_noparse(host, user, password)
    fcr_state = fcr_tools.switch_status()
    state = fcr_state['fcr_enabled']
    if state is False:
        print('Reboot Complete. FCR State remains consistent')
        print('TEST PASSED')
    else:
        print('FCR State changed.')
        print('TEST FAILED')

    sys.exit(0)#######################
Beispiel #8
0
def fcr_state_persist_disabled():
    """
    Check if FCR is disabled, if not bail out and ask user to enable it.
    When FCR is disabled, do a reboot then check FCR is still disabled. 
    """
    host = (sys.argv[1])
    user = sys.argv[2]
    password = sys.argv[7]
    #test_file = '/home/RunFromHere/ini/SwitchMatrix.csv'
    #csv_file = csv.DictReader(open(test_file, 'r'), delimiter=',', quotechar='"')
    fcr_state = fcr_tools.switch_status()
    state = fcr_state['fcr_enabled']
    if state is False:  #the same to here disabled is false, enabled is true
        anturlar.fos_cmd("switchdisable")
        print('\n\nSleeping: 10')
        liabhar.JustSleep(10)
        enabled = fcr_tools.switch_status()
        if enabled['fcr_enabled'] is False:
            anturlar.fos_cmd("switchenable")
            print('\n\nSleeping: 10')
            liabhar.JustSleep(10)
            print("\n\nENABLE/DISABLE TEST PASSED")
        else:
            pass
    else:
        print("\n\nENABLE/DISABLE TEST FAILED")
        print("Please disable fcr for this test and try again")
        sys.exit(0)
    print('Sleeping: 10')
    liabhar.JustSleep(10)
    si = anturlar.SwitchInfo()
    cn = si.chassisname()
    a = cofra.switch_power_off_on(cn, 'off')
    print('Sleeping: 20')
    liabhar.JustSleep(20)
    a = cofra.switch_power_off_on(cn, 'on')
    print('Sleeping: 120')
    liabhar.JustSleep(120)
    anturlar.connect_tel_noparse(host, user, password)
    fcr_state = fcr_tools.switch_status()
    state = fcr_state['fcr_enabled']
    if state is False:
        print('Reboot Complete. FCR State remains consistent')
        print('TEST PASSED')
    else:
        print('FCR State changed.')
        print('TEST FAILED')

    sys.exit(0)  #######################
Beispiel #9
0
def fcr_state_persist_enabled():
    #print(sys.argv)
    host = (sys.argv[1])
    user = sys.argv[2]
    password = sys.argv[7]
    test_file = '/home/RunFromHere/ini/SwitchMatrix.csv'
    csv_file = csv.DictReader(open(test_file, 'r'),
                              delimiter=',',
                              quotechar='"')
    fcr_state = switch_status()
    state = fcr_state['fcr_enabled']
    if state is True:
        anturlar.fos_cmd("switchdisable")
        print('\n\nSleeping: 10')
        liabhar.JustSleep(10)
        enabled = switch_status()
        if enabled['fcr_enabled'] is True:
            anturlar.fos_cmd("switchenable")
            print('\n\nSleeping: 10')
            liabhar.JustSleep(10)
            print("\n\nENABLE/DISABLE TEST PASSED")
        else:
            pass
    else:
        print("\n\nENABLE/DISABLE TEST FAILED")
        print("Please enable fcr for this test and try again")
        sys.exit(0)
    print('\n\nSleeping: 10')
    liabhar.JustSleep(10)
    si = anturlar.SwitchInfo()
    cn = si.chassisname()
    a = cofra.switch_power_off_on(cn, 'off')
    print('\n\nSleeping: 20')
    liabhar.JustSleep(20)
    a = cofra.switch_power_off_on(cn, 'on')
    print('\n\nSleeping: 120')
    liabhar.JustSleep(120)
    anturlar.connect_tel_noparse(host, user, password)
    si = anturlar.SwitchInfo()
    print("GETTINGFCRSTATE")
    fcr_state = switch_status()
    state = fcr_state['fcr_enabled']
    if state is True:
        print('Reboot Complete. FCR State remains consistent')
        print('TEST PASSED')
    else:
        print('FCR State changed.')
        print('TEST FAILED')
Beispiel #10
0
def fcr_state_persist_enabled():
    #print(sys.argv)
    host = (sys.argv[1])
    user = sys.argv[2]
    password = sys.argv[7]
    test_file = '/home/RunFromHere/ini/SwitchMatrix.csv'
    csv_file = csv.DictReader(open(test_file, 'r'), delimiter=',', quotechar='"')
    fcr_state = switch_status()
    state = fcr_state['fcr_enabled']
    if state is True:
        anturlar.fos_cmd("switchdisable")
        print('\n\nSleeping: 10')
        liabhar.JustSleep(10)
        enabled = switch_status()
        if enabled['fcr_enabled'] is True:
            anturlar.fos_cmd("switchenable")
            print('\n\nSleeping: 10')
            liabhar.JustSleep(10)
            print("\n\nENABLE/DISABLE TEST PASSED")
        else:
            pass
    else:
        print("\n\nENABLE/DISABLE TEST FAILED")
        print("Please enable fcr for this test and try again")
        sys.exit(0)
    print('\n\nSleeping: 10')
    liabhar.JustSleep(10)
    si = anturlar.SwitchInfo()
    cn = si.chassisname()
    a = cofra.switch_power_off_on(cn, 'off')
    print('\n\nSleeping: 20')
    liabhar.JustSleep(20)
    a = cofra.switch_power_off_on(cn, 'on')
    print('\n\nSleeping: 120')
    liabhar.JustSleep(120)
    anturlar.connect_tel_noparse(host, user, password)
    si = anturlar.SwitchInfo()
    print("GETTINGFCRSTATE")
    fcr_state = switch_status()
    state = fcr_state['fcr_enabled']
    if state is True:
        print('Reboot Complete. FCR State remains consistent')
        print('TEST PASSED')
    else:
        print('FCR State changed.')
        print('TEST FAILED')
Beispiel #11
0
def testprocess( theargs, run_these, password ):
    print("\n"*60)
    print("="*60)
    #header(theargs, run_these)
    #print(theargs)
    #print(run_these)l = sys.argparse.Namespace
    global tn
            
    host_ip = theargs.ip
    user    = theargs.user
                
    #tn = anturlar.connect_tel(theargs, password )
    tn = anturlar.connect_tel_noparse(host_ip, user, password )
    conout = anturlar.fos_cmd("setcontext %s " % theargs.fid )
    
    #print("@@"*40)
    #print("IN BIRLINNN Just after the connect to telnet")
    #print("@@"*40)
    #conout = anturlar.fos_cmd("version")
    #print(conout)
    #print("@@"*40)

    for i in run_these:
        print("run these test   %s"%i )
        #test_to_run = "test_case_0."
        test_to_run = ""
        paramlist = ""
        i.pop(0)
        h = True
        for j in i:
            if h :
                h = False
                test_to_run = test_to_run + j +"("
            else:
                test_to_run = test_to_run + j 
                paramlist = j
            
        test_to_run = test_to_run + ")"
        #print("\n\n", test_to_run, "\n\nEND OF TEST TO RUN")
        #conout = anturlar.fos_cmd("switchshow")
        
        if paramlist == "" :
            eval(test_to_run)
        else:
            print("\n\n param list is  %s "%paramlist)
            eval(test_to_run)
            
###############################################################################        
#### close the telnet connection and end the test
###############################################################################
    anturlar.close_tel
Beispiel #12
0
def testprocess(theargs, run_these, password):
    print("\n" * 60)
    print("=" * 60)
    #header(theargs, run_these)
    #print(theargs)
    #print(run_these)l = sys.argparse.Namespace
    global tn

    host_ip = theargs.ip
    user = theargs.user

    #tn = anturlar.connect_tel(theargs, password )
    tn = anturlar.connect_tel_noparse(host_ip, user, password)
    conout = anturlar.fos_cmd("setcontext %s " % theargs.fid)

    #print("@@"*40)
    #print("IN BIRLINNN Just after the connect to telnet")
    #print("@@"*40)
    #conout = anturlar.fos_cmd("version")
    #print(conout)
    #print("@@"*40)

    for i in run_these:
        print("run these test   %s" % i)
        #test_to_run = "test_case_0."
        test_to_run = ""
        paramlist = ""
        i.pop(0)
        h = True
        for j in i:
            if h:
                h = False
                test_to_run = test_to_run + j + "("
            else:
                test_to_run = test_to_run + j
                paramlist = j

        test_to_run = test_to_run + ")"
        #print("\n\n", test_to_run, "\n\nEND OF TEST TO RUN")
        #conout = anturlar.fos_cmd("switchshow")

        if paramlist == "":
            eval(test_to_run)
        else:
            print("\n\n param list is  %s " % paramlist)
            eval(test_to_run)

###############################################################################
#### close the telnet connection and end the test
###############################################################################
    anturlar.close_tel
Beispiel #13
0
def firmwaredownload(frmdwn, frmup):
    """
        uses cofra firmwaredownload to do testing for update to
        newest code
        
        the test will load first firmware and return to the other on a second
        download command
    """

    capture_cmd = anturlar.fos_cmd("ipaddrshow")
    #match = re.search('(?P<ipaddress>[\s+\S+]+:([\d\.]){7,15}(?=\\r\\n))', capture_cmd)
    match = re.search('(?P<pre>([\s+\w+]+):\s?(?P<ip>[0-9\.]{1,15}))',
                      capture_cmd)
    if match:
        myip = (match.group('ip'))
        #return(myip)
    else:
        print("\n\n NO IP FOUND \n\n")
        #return (0)

    while True:
        #f = cofra.doFirmwareDownload(frmdwn)
        capture_cmd = anturlar.fos_cmd("version")
        f = cofra.DoFirmwaredownloadChoice(frmdwn, frmup)

        liabhar.count_down(600)

        anturlar.connect_tel_noparse(myip, 'root', 'password')
        #en = anturlar.SwitchInfo()
        capture_cmd = anturlar.fos_cmd("version")

        f = cofra.DoFirmwaredownloadChoice(frmdwn, frmup)

        anturlar.connect_tel_noparse(myip, 'root', 'password')
        #en = anturlar.SwitchInfo()

    return (0)
Beispiel #14
0
def slotpower_off_on_check_devices():
    si = anturlar.SwitchInfo()
    fcrc = anturlar.FcrInfo()
    fi = anturlar.FcipInfo()
    
    ip_address = fcr_tools.all_switches_in_bb_ip()
    switch_info = fcr_tools.bb_fabric_switch_status()
    #blades = si.blades()
    #ex_ports = si.ex_ports()
    b = (len(switch_info))
    print("The number of switches in backbone is:", b)
    print('\n\n\n')
    print('IP addresses of all switches in Backbone:')
    print(ip_address)
    print('\n\n\n')
    for i in ip_address:
        print(i)
        anturlar.connect_tel_noparse(i,'root','password')
        a = si.ex_ports()
        print(a)
        sys.exit(0)
        ex_port = a.append(a)
        print('EXPORTSEXPORTS')
        print(ex_port)
Beispiel #15
0
def fab_wide_proxy_device_numbers():
    """
    Retrieve number of proxy device on all backbone switches in fabric. Drop those numbers
    into a file for later retreival (e.g. say after reboot testing). Also return a
    dictionary (e.g {switch_ip: # of proxy devices})
    """
    
    fcrinfo = anturlar.FcrInfo()
    backbone_ip = fcrinfo.fcr_backbone_ip()
    print(backbone_ip)
    sys.exit()
    bb_fab_num = (len(backbone_ip))
    proxy_dev_count = []
    for ip in backbone_ip:
        anturlar.connect_tel_noparse(ip,'root','password')
        base = fcrinfo.base_check() # get the base FID number
        if base is not False:
            anturlar.fos_cmd("setcontext " + base)
            get_proxy = fcrinfo.fcr_proxy_dev()
            proxy_dev_count.extend(get_proxy)

        else:
            get_proxy = fcrinfo.fcr_proxy_dev()
            proxy_dev_count.extend(get_proxy)
    switch_list_with_proxy_dev = dict(zip(backbone_ip, proxy_dev_count))
    proxy_dev_count = (str(proxy_dev_count))
    f = ('logs/ProxyDev_Count.txt')
    ff = liabhar.FileStuff(f,'w+b') ###open new file or clobber old
    ff.write(proxy_dev_count)
    ff.close()
    print('\n\n'+ '='*20)        
    print('Backbone Fabric consists of %s switches.' % (len(bb_fab_num)))
    print('IP addresses: Number of proxy devices found')
    print(switch_list_with_proxy_dev)
    print('='*20 + '\n\n')
    return(switch_list_with_proxy_dev)
Beispiel #16
0
def slotpower_off_on_check_devices():
    si = anturlar.SwitchInfo()
    fcrc = anturlar.FcrInfo()
    fi = anturlar.FcipInfo()

    ip_address = fcr_tools.all_switches_in_bb_ip()
    switch_info = fcr_tools.bb_fabric_switch_status()
    #blades = si.blades()
    #ex_ports = si.ex_ports()
    b = (len(switch_info))
    print("The number of switches in backbone is:", b)
    print('\n\n\n')
    print('IP addresses of all switches in Backbone:')
    print(ip_address)
    print('\n\n\n')
    for i in ip_address:
        print(i)
        anturlar.connect_tel_noparse(i, 'root', 'password')
        a = si.ex_ports()
        print(a)
        sys.exit(0)
        ex_port = a.append(a)
        print('EXPORTSEXPORTS')
        print(ex_port)
Beispiel #17
0
def fab_wide_proxy_device_numbers():
    """
    Retrieve number of proxy device on all backbone switches in fabric. Drop those numbers
    into a file for later retreival (e.g. say after reboot testing). Also return a
    dictionary (e.g {switch_ip: # of proxy devices})
    """

    fcrinfo = anturlar.FcrInfo()
    backbone_ip = fcrinfo.fcr_backbone_ip()
    print(backbone_ip)
    sys.exit()
    bb_fab_num = (len(backbone_ip))
    proxy_dev_count = []
    for ip in backbone_ip:
        anturlar.connect_tel_noparse(ip, 'root', 'password')
        base = fcrinfo.base_check()  # get the base FID number
        if base is not False:
            anturlar.fos_cmd("setcontext " + base)
            get_proxy = fcrinfo.fcr_proxy_dev()
            proxy_dev_count.extend(get_proxy)

        else:
            get_proxy = fcrinfo.fcr_proxy_dev()
            proxy_dev_count.extend(get_proxy)
    switch_list_with_proxy_dev = dict(zip(backbone_ip, proxy_dev_count))
    proxy_dev_count = (str(proxy_dev_count))
    f = ('logs/ProxyDev_Count.txt')
    ff = liabhar.FileStuff(f, 'w+b')  ###open new file or clobber old
    ff.write(proxy_dev_count)
    ff.close()
    print('\n\n' + '=' * 20)
    print('Backbone Fabric consists of %s switches.' % (len(bb_fab_num)))
    print('IP addresses: Number of proxy devices found')
    print(switch_list_with_proxy_dev)
    print('=' * 20 + '\n\n')
    return (switch_list_with_proxy_dev)
Beispiel #18
0
def firmwaredownload(frmdwn, frmup):
    """
        uses cofra firmwaredownload to do testing for update to
        newest code
        
        the test will load first firmware and return to the other on a second
        download command
    """
    
    capture_cmd = anturlar.fos_cmd("ipaddrshow")
    #match = re.search('(?P<ipaddress>[\s+\S+]+:([\d\.]){7,15}(?=\\r\\n))', capture_cmd)
    match = re.search('(?P<pre>([\s+\w+]+):\s?(?P<ip>[0-9\.]{1,15}))', capture_cmd)
    if match:
        myip = (match.group('ip'))
        #return(myip)
    else:
        print("\n\n NO IP FOUND \n\n")
        #return (0)
    
    while True:
    #f = cofra.doFirmwareDownload(frmdwn)
        capture_cmd = anturlar.fos_cmd("version")
        f = cofra.DoFirmwaredownloadChoice(frmdwn,frmup)

        liabhar.count_down(600)
        
        anturlar.connect_tel_noparse(myip, 'root', 'password')
        #en = anturlar.SwitchInfo()
        capture_cmd = anturlar.fos_cmd("version")
        
        f = cofra.DoFirmwaredownloadChoice(frmdwn, frmup)
    
        anturlar.connect_tel_noparse(myip, 'root', 'password')
        #en = anturlar.SwitchInfo()

    return(0)
Beispiel #19
0
def ha_failover(times=1):
    """
        do HA failover on directors
        do hareboot on pizza box
    """
    #### steps
    ####  1. Determine Pizza box or Director
    ####  2. save username and password
    ####  3. HA Failover or HA reboot
    ####  4. wait some time
    ####  5. reconnect

    sw_info = anturlar.SwitchInfo()
    print(sw_info)
    ip_addr = sw_info.ipaddress()
    chassis = sw_info.am_i_director
    #sys.exit()
    while times > 0:
        print("\n\n\n")
        print("@" * 60)
        print("HA Failovers remaining -- %s " % times)
        print("@" * 60)
        times -= 1
        liabhar.count_down(10)
        if chassis:
            capture = anturlar.fos_cmd("echo Y | hafailover")
        else:
            capture = anturlar.fos_cmd("hareboot")
        liabhar.count_down(300)
        tn = anturlar.connect_tel_noparse(ip_addr, 'root', 'password')
        switch_sync = sw_info.synchronized()
        print("\n\n")
        print("@" * 60)
        print("VALUE OF switch_sync is   --   %s   " % switch_sync)
        print("@" * 60)
        while switch_sync is False:
            liabhar.count_down(120)
            switch_sync = sw_info.synchronized()
            print("\n\n")
            print("@" * 60)
            print("The VALUE OF switch_sync is   --   %s   " % switch_sync)
            print("@" * 60)

    return (tn)
Beispiel #20
0
def ha_failover( times=1):
    """
        do HA failover on directors
        do hareboot on pizza box
    """
    #### steps
    ####  1. Determine Pizza box or Director
    ####  2. save username and password
    ####  3. HA Failover or HA reboot
    ####  4. wait some time
    ####  5. reconnect

    sw_info = anturlar.SwitchInfo()
    print(sw_info)
    ip_addr = sw_info.ipaddress()
    chassis = sw_info.am_i_director
    #sys.exit()
    while times > 0:
        print("\n\n\n")
        print("@"*60)
        print("HA Failovers remaining -- %s " % times)
        print("@"*60)
        times -= 1
        liabhar.count_down(10)
        if chassis:
            capture = anturlar.fos_cmd("echo Y | hafailover")    
        else:
            capture = anturlar.fos_cmd("hareboot")
        liabhar.count_down(300)
        tn = anturlar.connect_tel_noparse(ip_addr,'root','password')
        switch_sync = sw_info.synchronized()
        print("\n\n")
        print("@"*60)
        print("VALUE OF switch_sync is   --   %s   " % switch_sync)
        print("@"*60)
        while  switch_sync is False:
            liabhar.count_down(120)
            switch_sync = sw_info.synchronized()
            print("\n\n")
            print("@"*60)
            print("The VALUE OF switch_sync is   --   %s   " % switch_sync)
            print("@"*60)
    
    return(tn)
Beispiel #21
0
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()
Beispiel #22
0
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()
        #print(ipaddr_switch)
    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:
        tn = anturlar.connect_tel_noparse(i, user_name, usr_psswd)
        nos = si.nos_check()
        if not nos:
            fi = anturlar.FcrInfo()
            lsanzone = anturlar.fos_cmd("lsanzoneshow -s")
            fcrproxy = anturlar.fos_cmd("fcrproxydevshow")
            fcrresource = anturlar.fos_cmd("fcrresourceshow")
            print(lsanzone)
            print(fcrproxy)
            print(fcrresource)
            f1 = "%s%s%s" % ("logs/LsanZoneInfo_", pa.ipaddr, "_base.txt")
            a = os.path.isfile(f1)
            if not a:
                print("Not there. Capturing file now")
                header = "%s%s%s%s" % ("\nLsanZoneShow CAPTURE FILE \n",\
                           "","", "==============================\n")
                ff = liabhar.FileStuff(
                    f1, 'w+b')  #### open the log file for writing
                ff.write(header)
                ff.write(lsanzone)
                ff.write(fcrproxy)
                ff.write(fcrresource)
                sys.exit(0)
            else:
                f2 = "%s%s%s" % ("logs/LsanZoneInfo_", pa.ipaddr, "_after.txt")
                header = "%s%s%s%s" % ("\nLsanZoneShow CAPTURE FILE \n",\
                           "","", "==============================\n")
                ff = liabhar.FileStuff(
                    f2, 'w+b')  #### open the log file for writing
                ff.write(header)
                ff.write(lsanzone)
                ff.write(fcrproxy)
                ff.write(fcrresource)
                #sys.exit(0)

            #f0 = ("logs/LsanZoneInfo_",pa.ipaddr,"_base.txt")
            #f1 = ("logs/LsanZoneInfo_",pa.ipaddr,"_after.txt")
            diff = fcr_tools.file_diff(f1, f2)
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
            print(diff)
            sys.exit()

            #sw_dict              = cofra.get_info_from_the_switch()
            #switch_ip            = sw_dict["switch_ip"]
            #sw_name              = sw_dict["switch_name"]
            #sw_chass_name        = sw_dict["chassis_name"]
            #sw_director_or_pizza = sw_dict["director"]
            #sw_domains           = sw_dict["domain_list"]
            #sw_ls_list           = sw_dict["ls_list"]
            #sw_base_fid          = sw_dict["base_sw"]
            #sw_xisl              = sw_dict["xisl_state"]
            #sw_type              = sw_dict["switch_type"]
            #sw_license           = sw_dict["license_list"]
            #sw_vf_setting        = sw_dict["vf_setting"]
            #sw_fcr_enabled       = sw_dict["fcr_enabled"]
            #sw_port_list         = sw_dict["port_list"]
            #
            #print("\n"*20)
            #print("SWITCH IP            : %s   " % switch_ip)
            #print("SWITCH NAME          : %s   " % sw_name)
            #print("CHASSIS NAME         : %s   " % sw_chass_name)
            #print("DIRECTOR             : %s   " % sw_director_or_pizza)
            #print("SWITCH DOMAINS       : %s   " % sw_domains)
            #print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
            #print("BASE FID             : %s   " % sw_base_fid)
            #print("XISL STATE           : %s   " % sw_xisl)
            #print("SWITCH TYPE          : %s   " % sw_type)
            #print("LICENSE LIST         : %s   " % sw_license)
            #print("VF SETTING           : %s   " % sw_vf_setting)
            #print("FCR SETTING          : %s   " % sw_fcr_enabled)
            #print("PORT LIST            : %s   " % sw_port_list)
            #print("@"*40)
            #print("CONSOLE INFO         : %s   " % cons_info)
            #print("@"*40)
            #print("POWER POLE INFO      : %s   " % power_pole_info)
            #print("@"*40)
            #print("\nSwitch_Info has been written this file in logs/Switch_Info_%s_restore.txt\n" % switch_ip)
            #print("@"*40)
        else:
            print("\n" + "@" * 40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n" + "@" * 40)
            pass
    anturlar.close_tel()
    sys.exit()
Beispiel #23
0
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()
        #print(ipaddr_switch)
    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
    
    d = liabhar.dateTimeStuff()
    pa.cust_date = d.simple_no_dash()
    pa.cust_date = d.current_no_dash()
    pa.filename = pa.cust_date + pa.filename

    for i in ipaddr_switch:
        tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
        nos = si.nos_check()
        if not nos:
            sw_dict = cofra.get_info_from_the_switch(pa.filename, 128)
            my_ip                = sw_dict["switch_ip"]
            my_cp_ip_list        = sw_dict["cp_ip_list"]
            sw_name              = sw_dict["switch_name"]
            sw_chass_name        = sw_dict["chassis_name"]
            sw_director_or_pizza = sw_dict["director"]
            sw_domains           = sw_dict["domain_list"]
            sw_ls_list           = sw_dict["ls_list"]
            sw_base_fid          = sw_dict["base_sw"]
            sw_xisl              = sw_dict["xisl_state"]
            sw_type              = sw_dict["switch_type"]
            sw_license           = sw_dict["license_list"]
            sw_vf_setting        = sw_dict["vf_setting"]
            sw_fcr_enabled       = sw_dict["fcr_enabled"]
            sw_port_list         = sw_dict["port_list"]
            sw_ex_port_list      = sw_dict["ex_ports"]
    
    
            print("\n"*20)
            print("SWITHC IP            : %s   " % my_ip)
            print("CP IP List           : %s   " % my_cp_ip_list)
            print("SWITCH NAME          : %s   " % sw_name)
            print("CHASSIS NAME         : %s   " % sw_chass_name)
            print("DIRECTOR             : %s   " % sw_director_or_pizza)
            print("SWITCH DOMAINS       : %s   " % sw_domains)
            print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
            print("BASE FID             : %s   " % sw_base_fid)
            print("XISL STATE           : %s   " % sw_xisl)
            print("SWITCH TYPE          : %s   " % sw_type)
            print("LICENSE LIST         : %s   " % sw_license)
            print("VF SETTING           : %s   " % sw_vf_setting)
            print("FCR SETTING          : %s   " % sw_fcr_enabled)
            print("PORT LIST            : %s   " % sw_port_list)
            print("EX_PORT_LIST         : %s   " % sw_ex_port_list)
            print("@"*40)
            print("@"*40)
            print("CONSOLE INFO         : %s   " % cons_info)
            print("\n")
            print("POWER POLE INFO      : %s   " % power_pole_info)
        else:
            print("\n"+"@"*40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n"+"@"*40)
            pass
    anturlar.close_tel()
    sys.exit() ###### You are here. Need to grab EX-Ports then Port Flapping function next?????
     
###############################################################################
####
####  close telnet connection and 
####  connect to the console
####
###############################################################################

    cc = cofra.SwitchUpdate()
    
    cons_out = cc.playback_licenses()
    cons_out = cc.playback_ls()
    cons_out = cc.playback_switch_names()
    cons_out = cc.playback_switch_domains()
    cons_out = cc.playback_add_ports()
    tn       = cc.reboot_reconnect()
    cons_out = anturlar.fos_cmd("switchshow")
    print(cons_out)
    anturlar.close_tel()
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
Beispiel #25
0
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(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)
 
 

    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    
    
    liabhar.JustSleep(10)
    #cons_out = cc.power_cycle()
       
    cons_out = anturlar.fos_cmd("switchshow")
    print(cons_out)
    
    
    rt = create_flow(pa.chassis_name,pa.flowMatrixFile)
    
    print("\n\ncreated flows now waiting for while to reboot\n\n")
    
    liabhar.JustSleep(120)
    
    p_info = pwr_pole_info(pa.chassis_name)
    p_turn = power_cycle(p_info)
    
    liabhar.JustSleep(120)
    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    

    cons_out = anturlar.fos_cmd("flow --show all")
    print("\n"*30)
    print(cons_out)
    
    
    
    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
Beispiel #26
0
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()
    su = cofra.SwitchUpdate()
    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:  ###New
            tn = anturlar.connect_tel_noparse(i, user_name, usr_psswd)
        except OSError:  ##New
            print("Switch %s not available" % i)  ##New
        nos = si.nos_check()
        if not nos:
            anturlar.fos_cmd(
                "supportftp -s -h 10.38.35.131 -u ftp1 -p ftp2 -d ssaves -l ftp"
            )
            anturlar.fos_cmd("supportftp -e")
            anturlar.fos_cmd("supportftp -t 8")
            anturlar.fos_cmd(
                "tsclockserver 10.38.2.80; tstimezone America/Denver")
            #anturlar.fos_cmd("echo Y | reboot")
            #anturlar.fos_cmd("tsclockserver LOCL")
        else:
            print("\n" + "@" * 40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n" + "@" * 40)
            pass
        tn = su.reboot_reconnect()
        anturlar.close_tel()
    sys.exit()
Beispiel #27
0
def flow_to_each_SIM():
    """
        find all the SIM ports in the fabric and create a flow
        from each SIM port to all the Other SIM ports
          Since this test case finds all the switches in the
          fabric it might not be good to run in fabric mode
        steps
         1. get the ip list of switches in the fabric
         2. for each switch get a list of SIM ports
         3. create a flow for each SIMport to all other SIM ports
         4. start all of the flows if not started
         5. if there are only 2 switches only send to the other switch
            if there are more than 2 switches then send to a random port which
            could also be on the same switch
    """

    sw_info = anturlar.SwitchInfo()
    fid_now = sw_info.ls_now()
    cons_out = anturlar.fos_cmd(" ")
    #sw_ip = sw_info.ipaddress()
    f = anturlar.FabricInfo(fid_now)
    ip_list = f.ipv4_list()
    ip_count = len(ip_list)
    ip_c = ip_count

    combine_port_list = []
    list_for_j = []
    list_for_i = []
    temp_list = []

    for ip in ip_list:
        anturlar.connect_tel_noparse(ip, 'root', 'password')
        s = anturlar.SwitchInfo()
        cons_out = anturlar.fos_cmd(" ")
        cons_out = anturlar.fos_cmd("setcontext %s" % (fid_now))
        ports = s.sim_ports(False)
        #print("\n\n\n",ports, "\n\n\n")
        #combine_port_list.append(ports)
        combine_port_list = combine_port_list + ports
        if ip_c == 2:
            list_for_i = ports
            #print("\n\n\nI list \n")
            #print(list_for_i)
            liabhar.count_down(10)
            ip_c = 1
        if ip_c == 1:
            list_for_j = ports
            #print("\n\n\nJ list \n")
            #print(list_for_j)
            liabhar.count_down(10)

    flow_name_base = "Send_to_each_"
    count = 0

    #### need index address for simport
    #### now create a flow to each simport
    #print(combine_port_list)

    for ip in ip_list:
        anturlar.connect_tel_noparse(ip, 'root', 'password')
        s = anturlar.SwitchInfo()
        cons_out = anturlar.fos_cmd(" ")
        cons_out = anturlar.fos_cmd("setcontext %s " % (fid_now))
        cons_out = anturlar.fos_cmd(
            "flow --deact sys_gen_all_simports -fea all")

        #### randomize the list
        #combine_port_list = liabhar.randomList(combine_port_list)
        random.shuffle(combine_port_list)
        j_port_list = combine_port_list
        #print("\n\n\nPORT LIST RANDOMIZED  \n", combine_port_list)
        #print("\n\n\nNEW LIST RANDOMIZED  \n", new_combine_port_list)
        if len(ip_list) == 2:
            #print("\n\n\nyes only two switches\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
            liabhar.count_down(10)
            random.shuffle(list_for_i)
            #print("start I list ")
            for i in list_for_i:
                random.shuffle(list_for_j)
                generate_port = i[0]
                generate_addr = i[1]
                #print("\n\ngenerator port and address  %s  %s  \n\n" %(generate_port, generate_addr))

                #### this loops on the same list of combined port list
                #### one idea was to select a random element from the list each time
                ####
                for j in list_for_j:
                    target_port = j[0]
                    target_addr = j[1]
                    #print("\n\ntarget port and address  %s  %s \n\n" %( target_port, target_addr))

                    if generate_port not in target_port:
                        flow_name = ("%s%s" % (flow_name_base, count))
                        count += 1
                        #print(flow_name, "   " , generate_port," ", generate_addr, "to this port  " ,target_port," ", target_addr)
                        cmd_create = "flow --create %s -srcdev %s -dstdev %s -ingrport %s -fea gen,mon" % (
                            flow_name, generate_addr, target_addr,
                            generate_port)
                        cons_out = anturlar.fos_cmd(cmd_create)
                        if "maximum limit" in cons_out:
                            count -= 1
                            break
                        if "Port does not" in cons_out:
                            break
                        if "PID or WWN do not" in cons_out:
                            break
                        if "Exceeds maximum flow limit" in cons_out:
                            count -= 1
                            break
            temp_list = list_for_i
            list_for_i = list_for_j
            list_for_j = temp_list

        else:
            for i in combine_port_list:
                random.shuffle(j_port_list)
                generate_port = i[0]
                generate_addr = i[1]
                #### this loops on the same list of combined port list
                #### one idea was to select a random element from the list each time
                ####
                for j in j_port_list:
                    target_port = j[0]
                    target_addr = j[1]
                    if generate_port not in target_port:
                        flow_name = ("%s%s" % (flow_name_base, count))
                        count += 1
                        print(flow_name, "   ", generate_port, " ",
                              generate_addr, "to this port  ", target_port,
                              " ", target_addr)
                        cmd_create = "flow --create %s -srcdev %s -dstdev %s -ingrport %s -fea gen,mon" % (
                            flow_name, generate_addr, target_addr,
                            generate_port)
                        cons_out = anturlar.fos_cmd(cmd_create)
                        if "maximum limit" in cons_out:
                            count -= 1
                            break
                        if "Port does not" in cons_out:
                            break
                        if "PID or WWN do not" in cons_out:
                            break
                        if "Exceeds maximum flow limit" in cons_out:
                            count -= 1
                            break
Beispiel #28
0
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(pa.cmdprompt)
    print("@"*40)
    #sys.exit(0)
###################################################################################################################
###################################################################################################################
####
#### 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
#### 
#### the only args required are firmware and  ip or chassisname
####
    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)

###################################################################################################################
###################################################################################################################
#### if the switch is NOT at the command prompt 
#### then get all the info from the switch and save to a file
####  cofra.get_info_from_the_switch creates a file
####
#### If the switch is at the command prompt
####  then args -cp must be used
####
    if not pa.cmdprompt:
        try:
            tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
        except OSError:
            print("\n  If the Switch is at the command prompt use the -cp and -t switch")
            print("\n  ./APM/switch_playback.py -cp -t <no> -c <chassisname> <firmware>")
            print("\n\n  Popular switch types are:\n")
            print("       Type      Model\n")
            print("\t62       DCX\n\t64       5300\n\t66       5100\n\t71       300 \n")
            print("\t77       DCX-4S\n\t83       7800\n\t109      6510\n\t118      6505\n")
            print("\t120      DCX 8510-8\n\t121      DCX 8510-4")
            print("\t133      6520/Odin\n\t148      Skybolt ")
            print("\n"*5)
            sys.exit()
        sw_dict = cofra.get_info_from_the_switch()
        my_ip                = sw_dict["switch_ip"]
        my_cp_ip_list        = sw_dict["cp_ip_list"]
        sw_name              = sw_dict["switch_name"]
        sw_chass_name        = sw_dict["chassis_name"]
        sw_director_or_pizza = sw_dict["director"]
        sw_domains           = sw_dict["domain_list"]
        sw_ls_list           = sw_dict["ls_list"]
        sw_base_fid          = sw_dict["base_sw"]
        sw_xisl              = sw_dict["xisl_state"]
        sw_type              = sw_dict["switch_type"]
        sw_license           = sw_dict["license_list"]
        sw_vf_setting        = sw_dict["vf_setting"]
        sw_fcr_enabled       = sw_dict["fcr_enabled"]
        sw_port_list         = sw_dict["port_list"]


        print("\n"*20)
        print("SWITHC IP            : %s   " % my_ip)
        print("CP IP List           : %s   " % my_cp_ip_list)
        print("SWITCH NAME          : %s   " % sw_name)
        print("CHASSIS NAME         : %s   " % sw_chass_name)
        print("DIRECTOR             : %s   " % sw_director_or_pizza)
        print("SWITCH DOMAINS       : %s   " % sw_domains)
        print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
        print("BASE FID             : %s   " % sw_base_fid)
        print("XISL STATE           : %s   " % sw_xisl)
        print("SWITCH TYPE          : %s   " % sw_type)
        print("LICENSE LIST         : %s   " % sw_license)
        print("VF SETTING           : %s   " % sw_vf_setting)
        print("FCR SETTING          : %s   " % sw_fcr_enabled)
        print("PORT LIST            : %s   " % sw_port_list)
        print("@"*40)
        print("@"*40)
        print("CONSOLE INFO         : %s   " % cons_info)
        print("\n")
        print("POWER POLE INFO      : %s   " % power_pole_info)
        
        
###################################################################################################################
####
####  close telnet connection 
####
###################################################################################################################
        
        anturlar.close_tel()
    else:
        sw_type = pa.switchtype
        my_ip   = ipaddr_switch
        sw_director_or_pizza = False
        my_cp_ip_list = []
        
###################################################################################################################
###################################################################################################################
####
#### if I am Director then get the CP0 and CP1 IP addresses
####    before connecting to the console
#### 
###################################################################################################################
###################################################################################################################
    print("@"*40)
    print("switch is a director          %s  "    % sw_director_or_pizza)
    print("console_ip                    %s  "    %  console_ip)
    print("console port                  %s  "    %  console_port)
    print("user name is                  %s  "    %  user_name)
    print("password                      %s  "    % usr_pass)
    print("console_ip   backup           %s  "    % console_ip_bkup)
    print("console port backup           %s  "    % console_port_bkup)
    print("CP IP list (chassis CP0 CP1)  %s  "    % my_cp_ip_list)
    if sw_director_or_pizza:
        print("CP0                           %s  "    % my_cp_ip_list[1])
        print("CP1                           %s  "    % my_cp_ip_list[2])  
          
    #sys.exit()   stop here for getting the switch info only
    
###################################################################################################################
###################################################################################################################
####
####  if I am Director then connect to console 1 and find the cmdprompt
####     then connect to console 2 and find the cmdprompt
####
####     switch IP now needs to be the CP0 and CP1 values
####
    tn_list = []
    if sw_director_or_pizza:
        tn_cp0 = connect_console(console_ip, user_name, usr_pass, console_port, 0)
        
        tn_cp1 = connect_console(console_ip_bkup, user_name,usr_pass,console_port_bkup,0)
        #tn_list = []
        tn_list.append(tn_cp0)
        tn_list.append(tn_cp1)
        
        for tn in tn_list:
            cons_out = send_cmd("switchshow")
        
    
#######################################################################################################################
####
####  reboot and find the command prompt
####
        cnt = 1
    
        if not pa.cmdprompt:
            for tn in tn_list:
                cons_out = stop_at_cmd_prompt(0)
                print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
                print(cons_out)
                print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
                print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
            
            for tn in tn_list:
                cons_out = env_variables(sw_type, 0)
                print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
                print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") 
                print(cons_out)
                load_kernel(sw_type, my_cp_ip_list[cnt], pa.firmware)
                cnt += 1
        
    else:
    ###########################################################################
    #### im a pizza box
    ###########################################################################
         
        tn = connect_console(console_ip, user_name, usr_pass, console_port, 0)
        tn_list.append(tn)
       
     
#######################################################################################################################
####
####  reboot and find the command prompt
####
        if not pa.cmdprompt:
            cons_out = stop_at_cmd_prompt(9)
            print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
            print(cons_out)
            print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
            print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
            
        cons_out = env_variables(sw_type, 9)
        print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
        print("\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") 
        print(cons_out)
        load_kernel(sw_type, my_ip, pa.firmware)
    
#######################################################################################################################
#######################################################################################################################
#### this step is the same for director or pizza box
####
####  turn each port off then turn each port on (otherwise the delay between did not power cycle the switch)
####
#######################################################################################################################
    try:
        for pp in range(0, len(power_pole_info), 2):
            print('POWERPOLE')
            print(power_pole_info[pp])
            print(power_pole_info[pp+1])
            pwr_cycle(power_pole_info[pp],power_pole_info[pp+1], "off")
            time.sleep(2)
            
        for pp in range(0, len(power_pole_info), 2):
            print('POWERPOLE')
            print(power_pole_info[pp])
            print(power_pole_info[pp+1])
            pwr_cycle(power_pole_info[pp],power_pole_info[pp+1], "on")
            time.sleep(2)
    except:
        if  '' == power_pole_info[0]:
            print("\n"*20)
            print("NO POWER POLE INFO FOUND ")
            print("HA "*10)
            print("you have to walk to power cycle the switch")
            print("I will wait ")
            liabhar.JustSleep(30)
        else:
            print("POWER TOWER INFO")
            print(power_pole_info[0])
            print(power_pole_info)
            liabhar.JustSleep(30)
            
#######################################################################################################################
#######################################################################################################################
####
#### 
    #### is there another way to tell if switch is ready ??
    #### instead of waiting
    ####  maybe looking at switch Domain and if it is uncomfirmed then switch is not ready
    ####
#######################################################################################################################
#######################################################################################################################
####
####
#######################################################################################################################

    print("\r\n"*6)
    print("@"*40)
    print("Close Console sessions and login via telnet")
    print("Sleep for a minute")
    print("\r\n"*6)     
    #liabhar.count_down(300)
    #time.sleep(360)
    #cons_out = sw_set_pwd_timeout(usr_psswd,10)
    #print("@"*40)
    #print("TN   TN    TN")
    #print(tn_list)
    #print("@"*40)
    for tn in tn_list:
        tn.close()

    
    liabhar.JustSleep(600)
    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne")
    cons_out = sw_set_pwd_timeout(usr_psswd, tn)
    #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    
    print("\r\n\r\nLICENSE ADD TO SWITCH \r\n\r\n")
    print(my_ip)
    
    cc = cofra.SwitchUpdate()
    
    cons_out = cc.playback_licenses()
    cons_out = cc.playback_ls()
    cons_out = cc.playback_switch_names()
    cons_out = cc.playback_switch_domains()
    cons_out = cc.playback_add_ports()
    tn       = cc.reboot_reconnect()
    cons_out = anturlar.fos_cmd("switchshow")
    print(cons_out)
    cons_out = anturlar.fos_cmd("timeout 0")
    print(cons_out)
     
    anturlar.close_tel()
    #tn.write(b"exit\n")
    #tn.close()
     
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
Beispiel #29
0
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(pa.cmdprompt)
    print(pa.fid)
    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
#### 
#### 
####
    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)
 
 

    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    
    print("\r\n\r\nLICENSE ADD TO SWITCH \r\n\r\n")
    print(ipaddr_switch)
    
    en = anturlar.Maps()
    fab_stuff = anturlar.FabricInfo(en.currentFID())
    print("$$$$$$$$$$$$$$")
    print(fab_stuff)

    cons_out = anturlar.fos_cmd("setcontext %s" % pa.fid)
    cons_out = anturlar.fos_cmd("switchshow")
    
    #fabmems = fab_stuff.fabric_members()
    myzone_info = fab_stuff.zone_info(1)
    try:
        myzone = myzone_info[0][1]
    except IndexError:
        myzone = "NewZone"
    
    liabhar.JustSleep(10)
    cons_out = anturlar.fos_cmd("switchshow")
   
   
    add_zones(myzone)
    
    
    print(cons_out)
    
    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
Beispiel #30
0
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)
Beispiel #31
0
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()
Beispiel #32
0
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()
Beispiel #33
0
def main():

    global tn   #### varable for telnet session
#######################################################################################################################
####
#### 
####
#######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    #print(pa.chassis_name)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    #print(pa.firmware)
    print(pa.cmdprompt)
    print("@"*40)
    
###################################################################################################################
###################################################################################################################
####
#### if user enter ip address then get the chassisname from the
####   SwitchMatrix file
#### then get the info from the SwitchMatrix file using the Chassis Name
#### 
#### 
####
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = console_info_from_ip(pa.ipaddr)
        
    cons_info                  = console_info(pa.chassis_name)
    console_ip                 = cons_info[0]
    console_port             = cons_info[1]
    console_ip_bkup        = cons_info[2]
    console_port_bkup    = cons_info[3]
    power_pole_info        = pwr_pole_info(pa.chassis_name)    
    usr_pass                    = get_user_and_pass(pa.chassis_name)
    user_name                = usr_pass[0]
    usr_psswd                  = usr_pass[1]
    ipaddr_switch             = get_ip_from_file(pa.chassis_name)
    steps_to_run              = pa.steps
 
    fid_to_compare         = 128    ### later we will capture info for all fids 
    
    ###################################################################################################################
    #### if the user does not enter a value for which steps to run prompt for user input value
    ####
    if not steps_to_run:
        #pa.start = user_start()
        steps_to_run = pa.start = user_start()
        
    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    
    ###################################################################################################################
    ####
    ####   configure some settings that are not defualt to confirm they remain after disruptions
    ####
    cons_out = send_cmd("creditrecovmode --cfg onLrThresh")
    cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrtthreshold 7")
    cons_out = send_cmd("creditrecovmode --fe_crdloss off")
    cons_out = send_cmd("creditrecovmode --be_crdloss off")
    cons_out = send_cmd("creditrecovmode --be_losync off")
    cons_out = send_cmd("creditrecovmode --fault edgeblade")
    
    
    
    ###################################################################################################################
    ####
    ####   capture teh configuration file  if the user selected 1 or 3
    ####
    
    if steps_to_run == 1 or steps_to_run == 3:
        switch_info = capture_switch_info("compare_orig", fid_to_compare)
        
    ###################################################################################################################
    #### path to the first file to compare
    #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr
    
    switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch    
    liabhar.JustSleep(10)

    ###################################################################################################################
    ###################################################################################################################
    ###################################################################################################################
    ####
    #### do configupload  or other test steps here
    ####  make other changes here before configupload or other commands 
    ####
    ###################################################################################################################
    ####
    ####   
    ####
    pp = cofra.SwitchUpdate()
    
    ###################################################################################################################
    ####
    #### 
    ####  
    ####
    cd = cofra.cfgupload(pa.ftp_ipaddress, pa.ftp_username,pa.ftp_password,pa.config_path)
    
   
    liabhar.count_down(120)
 
    mc = make_changes()
    
    
    
    
    
    cdd = cofra.cfgdownload(pa.ftp_ipaddress, pa.ftp_username,pa.ftp_password,cd)
    liabhar.count_down(360)
    ###################################################################################################################
    ####
    #### 
    ####
    ####
    ####
    #### 
    ####  other actions here
    ####
    ####
    ###################################################################################################################
    ###################################################################################################################
    ###################################################################################################################
    
    if steps_to_run == 2 or steps_to_run == 3:
      #  liabhar.JustSleep(10)
        liabhar.count_down(60)
        switch_info = capture_switch_info("compare", fid_to_compare)
    ###################################################################################################################
    #### path to the second file to compare
        switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch
        
        liabhar.cls()
        #### compare the two files
        print("#"*80)
        print("#"*80)
        print("#######")
        print("#######     @@@@@   @@@@@   @@@@@  @   @   @      @@@@@   @  ")
        print("#######     @  @    @       @      @   @   @        @     @  ")
        print("#######     @@@     @@@@    @@@@   @   @   @        @     @  ")
        print("#######     @  @    @           @  @   @   @        @        ")
        print("#######     @   @   @@@@@   @@@@@   @@@    @@@@@    @     @ ")
        print("#"*80)
        print("#"*80)
            
        diff_f  = liabhar.file_diff(switch_data_0,switch_data_1)
        print("#"*80)
        print("#"*80)
        print("#"*80)
        print("#"*80)
        print("Result ")
        print(diff_f)
    
    ###################################################################################################################
    ####
    ####   disconnecting from telnet
    ####
    ###################################################################################################################
    anturlar.close_tel()
Beispiel #34
0
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)
Beispiel #35
0
def main():

    global tn
    #######################################################################################################################
    ####
    ####   start with parsing the command line
    ####
    ####    use  the procedures  parent_parser and parse_args
    ####     to determine the command line switches
    ####
    #######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print("@" * 40)
    print("@" * 40)
    #######################################################################################################################
    #######################################################################################################################
    ####
    #### if user enter ip address then get the chassisname from the
    ####   SwitchMatrix file
    ####
    #### then get the info from the SwitchMatrix file using the Chassis Name
    ####
    ####
    ####  Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port,
    ####       Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port,
    ####            KVM IP,KVM Port,Web Username,Web Password,Admin Password
    ####
    #######################################################################################################################
    #######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)

    cons_info = sw_matrix_tools.console_info(pa.chassis_name)
    console_ip = cons_info[0]
    console_port = cons_info[1]
    console_ip_bkup = cons_info[2]
    console_port_bkup = cons_info[3]

    power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name)
    usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]

    ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name)

    ######################################################################################################################
    ######################################################################################################################
    ####
    ####   connect via telnet
    ####                            if you want to connect to the console it is available in anturlar and an example below
    ####
    ####
    ######################################################################################################################
    ######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)
    cons_out = anturlar.fos_cmd(
        "setcontext %s " %
        pa.fid)  ####   change to the fid given on the command
    cons_out = anturlar.fos_cmd(
        "firmwareshow")  ####   send any command with anturlar.fos_cmd
    print("\r\n")
    liabhar.JustSleep(30)  ####   sleep without printing anything
    print("now closing telnet session ")
    anturlar.close_tel()  ####  close the telnet session
    liabhar.JustSleep(30)
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####   connect via console example
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################

    #tn = anturlar.connect_console(console_ip,console_port)          ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                       ####  send a command via the console
    #
    ##cons_out = cofra.power_cycle(power_pole_info)                  #### power cycle the switch  using the
    #                                                                ####   Switch Matrix info
    #liabhar.JustSleep(30)                                           ####  wait for the switch to boot
    #
    #
    #cons_out = anturlar.send_cmd_console("\r\n")                        ####  send some commands to the console
    #                                                                    ####
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)     ####
    #cons_out = anturlar.send_cmd_console("firmwareshow")                ####

    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  do anything else you want to try
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################
    dt = liabhar.dateTimeStuff(
    )  #### create the object for date and time stuff
    date_is = dt.current()  #### get the current time
    print(date_is)

    print("Leaving the script\r\n\r\n")
    liabhar.count_down(30)  ####   count down to the next command
Beispiel #36
0
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
    ###
    #try:
    #    ipaddr_test = ipaddress.ip_address(pa.ipaddr)
    #    #print (ipaddr_test)
    #except ValueError:
    #    print("\nPLEASE CHECK YOUR IP ADDRESS AND TRY AGAIN")
    #    sys.exit()

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

    ff = ""
    f = ("%s%s%s" % ("logs/Switch_Info_", pa.ipaddr, "_restore.txt"))
    #f = ("logs/Switch_Info_10.38.134.66_VF_Wedge.txt")
    #f = ("logs/Switch_Info_10.38.134.66_for_playback.txt")
    print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
    print(f)

    try:
        with open(f, 'r') as file:
            ff = file.read()
    except IOError:
        print("\n\nThere was a problem opening the file:", f)
        sys.exit()
    print(ff)

    #sys.exit()

    #for i in ipaddr_switch:
    #    tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
    #    nos = si.nos_check()
    #    if not nos:
    #        sw_dict              = cofra.get_info_from_the_switch()
    #        switch_ip            = sw_dict["switch_ip"]
    #        sw_name              = sw_dict["switch_name"]
    #        sw_chass_name        = sw_dict["chassis_name"]
    #        sw_director_or_pizza = sw_dict["director"]
    #        sw_domains           = sw_dict["domain_list"]
    #        sw_ls_list           = sw_dict["ls_list"]
    #        sw_base_fid          = sw_dict["base_sw"]
    #        sw_xisl              = sw_dict["xisl_state"]
    #        sw_type              = sw_dict["switch_type"]
    #        sw_license           = sw_dict["license_list"]
    #        sw_vf_setting        = sw_dict["vf_setting"]
    #        sw_fcr_enabled       = sw_dict["fcr_enabled"]
    #        sw_port_list         = sw_dict["port_list"]
    #
    #        print("\n"*20)
    #        print("SWITCH IP            : %s   " % switch_ip)
    #        print("SWITCH NAME          : %s   " % sw_name)
    #        print("CHASSIS NAME         : %s   " % sw_chass_name)
    #        print("DIRECTOR             : %s   " % sw_director_or_pizza)
    #        print("SWITCH DOMAINS       : %s   " % sw_domains)
    #        print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
    #        print("BASE FID             : %s   " % sw_base_fid)
    #        print("XISL STATE           : %s   " % sw_xisl)
    #        print("SWITCH TYPE          : %s   " % sw_type)
    #        print("LICENSE LIST         : %s   " % sw_license)
    #        print("VF SETTING           : %s   " % sw_vf_setting)
    #        print("FCR SETTING          : %s   " % sw_fcr_enabled)
    #        print("PORT LIST            : %s   " % sw_port_list)
    #        print("@"*40)
    #        print("CONSOLE INFO         : %s   " % cons_info)
    #        print("@"*40)
    #        print("POWER POLE INFO      : %s   " % power_pole_info)
    #        print("@"*40)
    #        print("\nSwitch_Info has been written this file in logs/Switch_Info_for_playback_%s.txt\n" % switch_ip)
    #        print("@"*40)
    #    else:
    #        print("\n"+"@"*40)
    #        print('\nTHIS IS A NOS SWITCH> SKIPPING')
    #        print("\n"+"@"*40)
    #        pass
    #anturlar.close_tel()
    #sys.exit()

    ###############################################################################
    ####
    ####  close telnet connection and
    ####  connect to the console
    ####
    ###############################################################################

    tn = anturlar.connect_tel_noparse(pa.ipaddr, user_name, usr_psswd)
    cc = cofra.SwitchUpdate()

    cons_out = cc.playback_licenses()
    cons_out = cc.playback_ls()
    cons_out = cc.playback_switch_names()
    cons_out = cc.playback_switch_domains()
    cons_out = cc.playback_add_ports()
    cons_out = cc.playback_fosconfig_fcr()
    tn = cc.reboot_reconnect()
    cons_out = anturlar.fos_cmd("switchshow")
    print(cons_out)
    anturlar.close_tel()
Beispiel #37
0
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]
        

    fabric_check =  fi.fabric_members()
    if (len(fabric_check)) < 2:
        print('this test requires a minimum of 2 switches in the fabric')
        sys.exit()
    trans_check = fi.zone_cfgtransshow()
    print(trans_check)
    if trans_check:
        print( "\n\nThere are open transaction(s). Closing them now")
        anturlar.fos_cmd("cfgtransabort",9)
    #sys.exit()
    all_ips = fi.ipv4_list()
    for item in all_ips:
        print(type("\n\n %s" % item))
        print(item)
    if pa.ipaddr in all_ips:
        print(pa.ipaddr)
        all_ips = all_ips.remove(pa.ipaddr)
        print(all_ips)
    # if pa.ipaddr in all_ips:
    #     print("Found it")
    # else:
    #     print("Not there")
    anturlar.close_tel()
    sys.exit()
    for i in all_ips:
        if pa.ipaddr == i:
            pass
        else:
            ips = i
            switch1_ip = pa.ipaddr
            switch2_ip = all_ips[0]
            print(switch1_ip)
            print(switch2_ip)
    sys.exit()
    #print(all_ips[0])

    print(ipaddr_switch)
    sys.exit()
    #ipaddr_switch = (str(ipaddr_switch))
    print(type(ipaddr_switch))
    print(ipaddr_switch)
    if ipaddr_switch in all_ips:
        all_ips = (all_ips.remove(ipaddr_switch))
        print("222222222222222222222222")
        print(all_ips)
    anturlar.close_tel()
    sys.exit()
    
    #### 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)
            tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
            #tn.set_debuglevel(9)
        except OSError:
            print("Switch %s not available" % i) 
        nos = si.nos_check()
        if not nos:
            # all_ips = fi.ipv4_list()
            # print(all_ips)
            # fabric_check =  fi.fabric_members()
            # if (len(fabric_check)) < 2:
            #     print('this test requires a minimum of 2 switches in the fabric')
            #     sys.exit()
            #print(fabric_check)
            switch1_ip = (all_ips[0])
            switch2_ip = (all_ips[1])
            trans_check = fi.zone_cfgtransshow()
            if trans_check:
                print( "\n\nThere are open transactions. Closing them now")
                anturlar.fos_cmd("cfgtransabort")
                anturlar.close_tel()
            tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
            
            print(b)
            anturlar.close_tel()            
            sys.exit()
            
            tn1 = anturlar.connect_tel_noparse(switch2_ip,user_name,usr_psswd)
            cfgtrans2 = anturlar.fos_cmd("cfgtransshow --opentrans")
            print(cfgtrans2)
            anturlar.close_tel(tn)
            anturlar.close_tel(tn1)
            sys.exit()
            #print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
            # f_ports = si.f_ports()
            # e_ports = si.e_ports()
            # print(fports)
            # print(eports)
            #sys.exit()
            #devices = fcr.fcr_proxy_dev()
           # print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
            #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()
Beispiel #39
0
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","")
Beispiel #40
0
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)
Beispiel #41
0
def main():

    global tn
    #######################################################################################################################
    ####
    ####   start with parsing the command line
    ####
    ####    use  the procedures  parent_parser and parse_args
    ####     to determine the command line switches
    ####
    #######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print("@" * 40)
    print("@" * 40)
    #######################################################################################################################
    #######################################################################################################################
    ####
    #### if user enter ip address then get the chassisname from the
    ####   SwitchMatrix file
    ####
    #### then get the info from the SwitchMatrix file using the Chassis Name
    ####
    ####
    ####  Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port,
    ####       Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port,
    ####            KVM IP,KVM Port,Web Username,Web Password,Admin Password
    ####
    #######################################################################################################################
    #######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)

    cons_info = sw_matrix_tools.console_info(pa.chassis_name)
    console_ip = cons_info[0]
    console_port = cons_info[1]
    console_ip_bkup = cons_info[2]
    console_port_bkup = cons_info[3]

    power_pole_info = sw_matrix_tools.pwr_pole_info(pa.chassis_name)
    usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]

    ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name)

    ######################################################################################################################
    ######################################################################################################################
    ####
    ####   connect via telnet:
    ####   if you want to connect to the console it is available in anturlar and an example below
    ####
    ####
    ######################################################################################################################
    ######################################################################################################################
    ####   Config_up_down_compare.main()

    # cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    # print("\r\n")
    # liabhar.JustSleep(5)                                                ####   sleep without printing anything
    # print("now closing telnet session ")
    # #anturlar.close_tel()                                                 ####  close the telnet session
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####   connect via console example and other "send command" commands
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################
    #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)   ####  connect to console w/o parser info
    #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)                 ####  change to the fid given on the command
    #tn = anturlar.connect_console(console_ip,console_port)                 ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                              ####  send a command via the console
    #cons_out = cofra.power_cycle(power_pole_info)                          ####  powercycle switch via switchmatrix.csv file
    #liabhar.JustSleep(30)                                                  ####  wait for the switch to boot
    #cons_out = anturlar.send_cmd_console("\r\n")                           ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)        ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("firmwareshow")                   ####  send some commands to the console
    #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2")              ####  send a cfgupload file to a ftp server
    #liabhar.count_down(5)                                                  ####  set and observe a count down timer

    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  This starts the template for configshow output comparison (after some type of switch operation).
    ####  First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file.
    ####
    #######################################################################################################################
    #######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)
    dt = liabhar.dateTimeStuff(
    )  #### create the object for date and time stuff
    date_is = dt.current_no_dash_at_end(
    )  #### get the current time for file naming purposes
    #print("\n\nDate is %s" % date_is)

    liabhar.count_down(5)  ####   count down to the next command
    #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2")
    f = "%s%s%s%s" % ("logs/Configupload_test_case_file", ipaddr_switch,
                      date_is, ".txt")
    ff = liabhar.FileStuff(f, 'w+b')  #### open the log file for writing
    header = "%s%s%s%s" % (
        "\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ", ipaddr_switch,
        "\n==============================\n\n"
    )  #### write a header line at top of file
    ff.write(header)
    #cons_out = anturlar.fos_cmd (configup_cmd)
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()  #### close this file for comparison later
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  do anything else you want to try (small sample of examples):
    ####  anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    ####  anturlar.fos_cmd("cfgenable")
    ####  anturlar.fos_cmd("switchdisable")
    ####  anturlar.fos_cmd("switchenable")
    ####
    ####  In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    ####  Then grab output of configshow, drop into a file and compare that with original
    ####
    #######################################################################################################################
    #######################################################################################################################

    anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    date_is = dt.current_no_dash_at_end()
    f1 = "%s%s%s%s" % ("logs/Configupload_test_case_file", ipaddr_switch,
                       date_is, ".txt")
    ff = liabhar.FileStuff(f1, 'w+b')  #### reset the log file
    header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n",
                           "  sw_info ipaddr  ", ipaddr_switch,
                           "\n==============================\n\n")
    ff.write(header)
    #cons_out = anturlar.fos_cmd (configup_cmd)
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()

    diff_f = liabhar.file_diff(f, f1)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("Result ")
    print(diff_f)

    #return(cons_out)
    return (True)
Beispiel #42
0
def main():

    global tn
#######################################################################################################################
####
####   start with parsing the command line
#### 
####    use  the procedures  parent_parser and parse_args
####     to determine the command line switches 
####
#######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print("@"*40)
    print("@"*40)
#######################################################################################################################
#######################################################################################################################
####
#### if user enter ip address then get the chassisname from the
####   SwitchMatrix file
#### 
#### then get the info from the SwitchMatrix file using the Chassis Name
#### 
#### 
####  Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port,
####       Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port,
####            KVM IP,KVM Port,Web Username,Web Password,Admin Password
####
#######################################################################################################################
#######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)
        
    cons_info         = sw_matrix_tools.console_info(pa.chassis_name)
    console_ip        = cons_info[0]
    console_port      = cons_info[1]
    console_ip_bkup   = cons_info[2]
    console_port_bkup = cons_info[3]
    
    power_pole_info   = sw_matrix_tools.pwr_pole_info(pa.chassis_name)    
    usr_pass          = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name         = usr_pass[0]
    usr_psswd         = usr_pass[1]
    
    ipaddr_switch     = sw_matrix_tools.get_ip_from_file(pa.chassis_name)
 
 ######################################################################################################################
 ######################################################################################################################
 ####
 ####   connect via telnet
 ####                            if you want to connect to the console it is available in anturlar and an example below
 ####
 ####
 ######################################################################################################################
 ######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)               ####   change to the fid given on the command 
    cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    print("\r\n")
    liabhar.JustSleep(30)                                                ####   sleep without printing anything
    print("now closing telnet session ") 
    anturlar.close_tel()                                                 ####  close the telnet session
    liabhar.JustSleep(30)
#######################################################################################################################   
#######################################################################################################################
####
####   connect via console example
####    
####
#######################################################################################################################
#######################################################################################################################
 
    #tn = anturlar.connect_console(console_ip,console_port)          ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                       ####  send a command via the console
    #
    ##cons_out = cofra.power_cycle(power_pole_info)                  #### power cycle the switch  using the
    #                                                                ####   Switch Matrix info
    #liabhar.JustSleep(30)                                           ####  wait for the switch to boot
    #
    #
    #cons_out = anturlar.send_cmd_console("\r\n")                        ####  send some commands to the console
    #                                                                    ####
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)     ####
    #cons_out = anturlar.send_cmd_console("firmwareshow")                ####


#######################################################################################################################
#######################################################################################################################
####
####  do anything else you want to try
####
####
#######################################################################################################################
#######################################################################################################################
    dt = liabhar.dateTimeStuff()                         #### create the object for date and time stuff
    date_is = dt.current()                               #### get the current time
    print(date_is)
    
    print("Leaving the script\r\n\r\n")
    liabhar.count_down(30)                               ####   count down to the next command 
def main():
    global tn  #### varable for telnet session
    #######################################################################################################################
    ####
    ####
    ####
    #######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print("@" * 40)

    ###################################################################################################################
    ###################################################################################################################
    ####
    #### if user enter ip address then get the chassisname from the
    ####   SwitchMatrix file
    #### then get the info from the SwitchMatrix file using the Chassis Name
    ####
    ####
    ####
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = console_info_from_ip(pa.ipaddr)

    cons_info = console_info(pa.chassis_name)
    console_ip = cons_info[0]
    console_port = cons_info[1]
    console_ip_bkup = cons_info[2]
    console_port_bkup = cons_info[3]
    power_pole_info = pwr_pole_info(pa.chassis_name)
    usr_pass = get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]
    ipaddr_switch = get_ip_from_file(pa.chassis_name)
    steps_to_run = pa.steps

    fid_to_compare = 128
    fid_to_compare = pa.fid

    ###################################################################################################################
    #### if the user does not enter a value for which steps to run prompt for user input value
    ####
    if not steps_to_run:
        # pa.start = user_start()
        steps_to_run = pa.start = user_start()

    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)

    ###################################################################################################################
    ####
    ####   configure some settings that are not defualt to confirm they remain after disruptions
    ####
    cons_out = send_cmd("creditrecovmode --cfg onLrThresh")
    cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrthreshold 7")
    cons_out = send_cmd("creditrecovmode --fe_crdloss off")
    cons_out = send_cmd("creditrecovmode --be_crdloss off")
    cons_out = send_cmd("creditrecovmode --be_losync off")
    cons_out = send_cmd("creditrecovmode --fault edgeblade")

    ###################################################################################################################
    ####
    ####   capture teh configuration file  if the user selected 1 or 3
    ####

    if steps_to_run == 1 or steps_to_run == 3:
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy")
        switch_info = capture_switch_info("compare_orig", fid_to_compare)

    ###################################################################################################################
    #### path to the first file to compare
    # switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr

    #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch
    switch_data_0 = "/home/runfromhere/logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch

    liabhar.JustSleep(10)

    ###################################################################################################################
    ###################################################################################################################
    ###################################################################################################################
    ####
    #### do configupload  or other test steps here
    ####  make other changes here before configupload or other commands
    ####
    ###################################################################################################################
    ####
    ####  REBOOT and RECONNECT WAIT 60 SECONDS and CONTINUE
    ####
    print("START Switch Update Class")
    liabhar.JustSleep(10)

    pp = cofra.SwitchUpdate()
    # tn = pp.reboot_reconnect()

    # liabhar.count_down(60)
    ###################################################################################################################
    ####
    #### hafailover or hareboot on pizza box
    ####  call the failover function from cofra and send the number of failovers
    ####
    print("START HA FAILOVER")
    liabhar.JustSleep(10)

    tn = cofra.ha_failover(100)

    liabhar.count_down(600)

    ###################################################################################################################
    ####
    #### power cycle slots
    ####

    ss = anturlar.SwitchInfo()
    slot_list = ss.blades(True)
    #### skip if switch is a pizza box
    # if "not a d" not in slot_list:
    #     pc_result = slot_pwr_cycle(slot_list)
    # else:
    #    print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST")
    #
    ####
    ####
    #### other interuptions
    ####
    ####
    ###################################################################################################################
    ###################################################################################################################
    ###################################################################################################################

    if steps_to_run == 2 or steps_to_run == 3:
        liabhar.JustSleep(10)
        liabhar.count_down(360)
        # cons_out = anturlar.fos_cmd("setcontext 128")
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy")

        switch_info = capture_switch_info("compare", fid_to_compare)
        ###################################################################################################################
        #### path to the second file to compare
        switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch

        liabhar.cls()
        #### compare the two files
        print("#" * 80)
        print("#" * 80)
        print("#######")
        print("#######     @@@@@   @@@@@   @@@@@  @   @   @      @@@@@   @  ")
        print("#######     @  @    @       @      @   @   @        @     @  ")
        print("#######     @@@     @@@@    @@@@   @   @   @        @     @  ")
        print("#######     @  @    @           @  @   @   @        @        ")
        print("#######     @   @   @@@@@   @@@@@   @@@    @@@@@    @     @ ")
        print("#" * 80)
        print("#" * 80)

        diff_f = liabhar.file_diff(switch_data_0, switch_data_1)
        print("#" * 80)
        print("#" * 80)
        print("#" * 80)
        print("#" * 80)
        print("Result ")
        print(diff_f)

    ###################################################################################################################
    ####  put additional commands here before disconnecting from telnet
    ####
    # cons_out = anturlar.fos_cmd("mapsdb --show all")
    # print(cons_out)
    # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
    #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio")
    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
    print(type(steps_to_run))
    print(steps_to_run)
def main():
    global tn  #### varable for telnet session
    #######################################################################################################################
    ####
    ####
    ####
    #######################################################################################################################
    pa = parse_args(sys.argv)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print("@" * 40)

    ###################################################################################################################
    ###################################################################################################################
    ####
    #### if user enter ip address then get the chassisname from the
    ####   SwitchMatrix file
    #### then get the info from the SwitchMatrix file using the Chassis Name
    ####
    ####
    ####
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = console_info_from_ip(pa.ipaddr)

    cons_info = console_info(pa.chassis_name)
    console_ip = cons_info[0]
    console_port = cons_info[1]
    console_ip_bkup = cons_info[2]
    console_port_bkup = cons_info[3]
    power_pole_info = pwr_pole_info(pa.chassis_name)
    usr_pass = get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]
    ipaddr_switch = get_ip_from_file(pa.chassis_name)
    steps_to_run = pa.steps

    fid_to_compare = 128
    fid_to_compare = pa.fid
    
    ###################################################################################################################
    #### if the user does not enter a value for which steps to run prompt for user input value
    ####
    if not steps_to_run:
        # pa.start = user_start()
        steps_to_run = pa.start = user_start()

    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)

    ###################################################################################################################
    ####
    ####   configure some settings that are not defualt to confirm they remain after disruptions
    ####
    cons_out = send_cmd("creditrecovmode --cfg onLrThresh")
    cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrthreshold 7")
    cons_out = send_cmd("creditrecovmode --fe_crdloss off")
    cons_out = send_cmd("creditrecovmode --be_crdloss off")
    cons_out = send_cmd("creditrecovmode --be_losync off")
    cons_out = send_cmd("creditrecovmode --fault edgeblade")
    
    ###################################################################################################################
    ####
    ####   capture teh configuration file  if the user selected 1 or 3
    ####

    if steps_to_run == 1 or steps_to_run == 3:
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy")
        switch_info = capture_switch_info("compare_orig", fid_to_compare)

    ###################################################################################################################
    #### path to the first file to compare
    # switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr

    #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch
    switch_data_0 = "/home/runfromhere/logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch

    liabhar.JustSleep(10)

    ###################################################################################################################
    ###################################################################################################################
    ###################################################################################################################
    ####
    #### do configupload  or other test steps here
    ####  make other changes here before configupload or other commands 
    ####
    ###################################################################################################################
    ####
    ####  REBOOT and RECONNECT WAIT 60 SECONDS and CONTINUE
    ####
    print("START Switch Update Class")
    liabhar.JustSleep(10)
    
    pp = cofra.SwitchUpdate()
    # tn = pp.reboot_reconnect()

    # liabhar.count_down(60)
    ###################################################################################################################
    ####
    #### hafailover or hareboot on pizza box
    ####  call the failover function from cofra and send the number of failovers
    ####
    print("START HA FAILOVER")
    liabhar.JustSleep(10)
    
    tn = cofra.ha_failover(100)

    liabhar.count_down(600)

    ###################################################################################################################
    ####
    #### power cycle slots
    ####

    ss = anturlar.SwitchInfo()
    slot_list = ss.blades(True)
    #### skip if switch is a pizza box
    # if "not a d" not in slot_list:
    #     pc_result = slot_pwr_cycle(slot_list)
    # else:
    #    print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST")
    # 
    ####
    #### 
    #### other interuptions
    ####
    ####
    ###################################################################################################################
    ###################################################################################################################
    ###################################################################################################################

    if steps_to_run == 2 or steps_to_run == 3:
        liabhar.JustSleep(10)
        liabhar.count_down(360)
        # cons_out = anturlar.fos_cmd("setcontext 128")
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
        # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy")

        switch_info = capture_switch_info("compare", fid_to_compare)
        ###################################################################################################################
        #### path to the second file to compare
        switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch

        liabhar.cls()
        #### compare the two files
        print("#" * 80)
        print("#" * 80)
        print("#######")
        print("#######     @@@@@   @@@@@   @@@@@  @   @   @      @@@@@   @  ")
        print("#######     @  @    @       @      @   @   @        @     @  ")
        print("#######     @@@     @@@@    @@@@   @   @   @        @     @  ")
        print("#######     @  @    @           @  @   @   @        @        ")
        print("#######     @   @   @@@@@   @@@@@   @@@    @@@@@    @     @ ")
        print("#" * 80)
        print("#" * 80)

        diff_f = liabhar.file_diff(switch_data_0, switch_data_1)
        print("#" * 80)
        print("#" * 80)
        print("#" * 80)
        print("#" * 80)
        print("Result ")
        print(diff_f)

    ###################################################################################################################
    ####  put additional commands here before disconnecting from telnet
    ####
    # cons_out = anturlar.fos_cmd("mapsdb --show all")
    # print(cons_out)
    # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
    #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio")
    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
    print(type(steps_to_run))
    print(steps_to_run)
def main():
    global tn  # 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", "")
Beispiel #46
0
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(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)

    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)

    liabhar.JustSleep(10)
    #cons_out = cc.power_cycle()

    cons_out = anturlar.fos_cmd("switchshow")
    print(cons_out)

    rt = create_flow(pa.chassis_name, pa.flowMatrixFile)

    print("\n\ncreated flows now waiting for while to reboot\n\n")

    liabhar.JustSleep(120)

    p_info = pwr_pole_info(pa.chassis_name)
    p_turn = power_cycle(p_info)

    liabhar.JustSleep(120)
    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)

    cons_out = anturlar.fos_cmd("flow --show all")
    print("\n" * 30)
    print(cons_out)

    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
Beispiel #47
0
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()
        #print(ipaddr_switch)
    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:
        tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
        nos = si.nos_check()
        if not nos:
            def ex_deconfig():
                """
                Find all EX-Ports AND VEX-Ports on either director or pizzabox and deconfigure.
                This parses "portcfgshow" command for any EX-Port, online or not, and deconfigures. This includes
                VEX ports as well.
                """
            si = anturlar.SwitchInfo()
            anturlar.fos_cmd("switchdisable")
            portlist =  si.all_ports()
            if si.am_i_director:
                for i in portlist:
                    slot = i[0]
                    port = i[1]
                    pattern = re.compile(r'(?:\EX\sPort\s+)(?P<state> ON)')
                    cmd = anturlar.fos_cmd("portcfgshow %a/%a" % (slot, port))
                    ex = pattern.search(cmd)
                    if ex:
                        anturlar.fos_cmd("portcfgexport %s/%s %s"%(slot,port,"-a 2"))
                        anturlar.fos_cmd("portcfgvexport %s/%s %s"%(slot,port,"-a 2"))
            else: 
                for i in portlist:
                    print(i)
                    port = i[1]
                    pattern = re.compile(r'(?:\EX\sPort\s+)(?P<state> ON)')
                    cmd = anturlar.fos_cmd("portcfgshow %a" % port)
                    ex = pattern.search(cmd)
                    if ex:
                        anturlar.fos_cmd("portcfgexport %s %s"%(port,"-a 2"))
                        anturlar.fos_cmd("portcfgvexport %s %s"%(port,"-a 2"))
            cmd_cap = anturlar.fos_cmd("switchenable")
            print('\n\nAll EX_ports found are now deconfigured.')
    #return(cmd_cap)
        #    sw_dict              = cofra.get_info_from_the_switch()
        #    switch_ip            = sw_dict["switch_ip"]
        #    sw_name              = sw_dict["switch_name"]
        #    sw_chass_name        = sw_dict["chassis_name"]
        #    sw_director_or_pizza = sw_dict["director"]
        #    sw_domains           = sw_dict["domain_list"]
        #    sw_ls_list           = sw_dict["ls_list"]
        #    sw_base_fid          = sw_dict["base_sw"]
        #    sw_xisl              = sw_dict["xisl_state"]
        #    sw_type              = sw_dict["switch_type"]
        #    sw_license           = sw_dict["license_list"]
        #    sw_vf_setting        = sw_dict["vf_setting"]
        #    sw_fcr_enabled       = sw_dict["fcr_enabled"]
        #    sw_port_list         = sw_dict["port_list"]
        #
        #    print("\n"*20)
        #    print("SWITCH IP            : %s   " % switch_ip)
        #    print("SWITCH NAME          : %s   " % sw_name)
        #    print("CHASSIS NAME         : %s   " % sw_chass_name)
        #    print("DIRECTOR             : %s   " % sw_director_or_pizza)
        #    print("SWITCH DOMAINS       : %s   " % sw_domains)
        #    print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
        #    print("BASE FID             : %s   " % sw_base_fid)
        #    print("XISL STATE           : %s   " % sw_xisl)
        #    print("SWITCH TYPE          : %s   " % sw_type)
        #    print("LICENSE LIST         : %s   " % sw_license)
        #    print("VF SETTING           : %s   " % sw_vf_setting)
        #    print("FCR SETTING          : %s   " % sw_fcr_enabled)
        #    print("PORT LIST            : %s   " % sw_port_list)
        #    print("@"*40)
        #    print("CONSOLE INFO         : %s   " % cons_info)
        #    print("@"*40)
        #    print("POWER POLE INFO      : %s   " % power_pole_info)
        #    print("@"*40)        
        #    print("\nSwitch_Info has been written this file in logs/Switch_Info_for_playback_%s.txt\n" % switch_ip)
        #    print("@"*40)
        else:
            print("\n"+"@"*40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n"+"@"*40)
            pass
    anturlar.close_tel()
    sys.exit()
     
###############################################################################
####
####  close telnet connection and 
####  connect to the console
####
###############################################################################

    cc = cofra.SwitchUpdate()
    
    cons_out = cc.playback_licenses()
    cons_out = cc.playback_ls()
    cons_out = cc.playback_switch_names()
    cons_out = cc.playback_switch_domains()
    cons_out = cc.playback_add_ports()
    tn       = cc.reboot_reconnect()
    cons_out = anturlar.fos_cmd("switchshow")
    print(cons_out)
    anturlar.close_tel()
Beispiel #48
0
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
 
    ###################################################################################################################
    #### 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)
    
    if steps_to_run == 1 or steps_to_run == 3:
        
        #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy")
        switch_info = cofra.get_info_from_the_switch("compare_orig")
    #switch_data_0 = "logs/Switch_Info_for_playback_",pa.ipaddr,".orig.txt" # this failed the compare
                                                                            #  the because it sees it
                                                                            #  as a tuple
    ###################################################################################################################
    #### path to the first file to compare
    switch_data_0 = "logs/Switch_Info_%s_compare_orig.txt" % pa.ipaddr
    
    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
    ###########################################################################
    #### 
    
    if steps_to_run == 2 or steps_to_run == 3:
        liabhar.JustSleep(10)
        cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_conservative_policy")
        switch_info = cofra.get_info_from_the_switch("compare")
    ###################################################################################################################
    #### path to the second file to compare
        switch_data_1 = "logs/Switch_Info_%s_compare.txt" % pa.ipaddr
        
        liabhar.cls()
        #### compare the two files
    
        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)
    
    
    anturlar.close_tel()
    dt = liabhar.dateTimeStuff()
    date_is = dt.current()
    print(date_is)
Beispiel #49
0
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()
        #print(ipaddr_switch)
    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:
        tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
        nos = si.nos_check()
        if not nos:
            fi=anturlar.FcrInfo()
            lsanzone = anturlar.fos_cmd("lsanzoneshow -s")
            fcrproxy = anturlar.fos_cmd("fcrproxydevshow")
            fcrresource = anturlar.fos_cmd("fcrresourceshow")
            print(lsanzone)
            print(fcrproxy)
            print(fcrresource)
            f1 = "%s%s%s"%("logs/LsanZoneInfo_",pa.ipaddr,"_base.txt")
            a = os.path.isfile(f1)
            if not a:
                print("Not there. Capturing file now")
                header = "%s%s%s%s" % ("\nLsanZoneShow CAPTURE FILE \n",\
                           "","", "==============================\n")  
                ff = liabhar.FileStuff(f1, 'w+b')  #### open the log file for writing
                ff.write(header)
                ff.write(lsanzone)
                ff.write(fcrproxy)
                ff.write(fcrresource)
                sys.exit(0)
            else:
                f2 = "%s%s%s"%("logs/LsanZoneInfo_",pa.ipaddr,"_after.txt")
                header = "%s%s%s%s" % ("\nLsanZoneShow CAPTURE FILE \n",\
                           "","", "==============================\n")  
                ff = liabhar.FileStuff(f2, 'w+b')  #### open the log file for writing
                ff.write(header)
                ff.write(lsanzone)
                ff.write(fcrproxy)
                ff.write(fcrresource)
                #sys.exit(0)
            
            #f0 = ("logs/LsanZoneInfo_",pa.ipaddr,"_base.txt")
            #f1 = ("logs/LsanZoneInfo_",pa.ipaddr,"_after.txt")
            diff = fcr_tools.file_diff(f1,f2)
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
            print(diff)
            sys.exit()
            
            #sw_dict              = cofra.get_info_from_the_switch()
            #switch_ip            = sw_dict["switch_ip"]
            #sw_name              = sw_dict["switch_name"]
            #sw_chass_name        = sw_dict["chassis_name"]
            #sw_director_or_pizza = sw_dict["director"]
            #sw_domains           = sw_dict["domain_list"]
            #sw_ls_list           = sw_dict["ls_list"]
            #sw_base_fid          = sw_dict["base_sw"]
            #sw_xisl              = sw_dict["xisl_state"]
            #sw_type              = sw_dict["switch_type"]
            #sw_license           = sw_dict["license_list"]
            #sw_vf_setting        = sw_dict["vf_setting"]
            #sw_fcr_enabled       = sw_dict["fcr_enabled"]
            #sw_port_list         = sw_dict["port_list"]
            #
            #print("\n"*20)
            #print("SWITCH IP            : %s   " % switch_ip)
            #print("SWITCH NAME          : %s   " % sw_name)
            #print("CHASSIS NAME         : %s   " % sw_chass_name)
            #print("DIRECTOR             : %s   " % sw_director_or_pizza)
            #print("SWITCH DOMAINS       : %s   " % sw_domains)
            #print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
            #print("BASE FID             : %s   " % sw_base_fid)
            #print("XISL STATE           : %s   " % sw_xisl)
            #print("SWITCH TYPE          : %s   " % sw_type)
            #print("LICENSE LIST         : %s   " % sw_license)
            #print("VF SETTING           : %s   " % sw_vf_setting)
            #print("FCR SETTING          : %s   " % sw_fcr_enabled)
            #print("PORT LIST            : %s   " % sw_port_list)
            #print("@"*40)
            #print("CONSOLE INFO         : %s   " % cons_info)
            #print("@"*40)
            #print("POWER POLE INFO      : %s   " % power_pole_info)
            #print("@"*40)        
            #print("\nSwitch_Info has been written this file in logs/Switch_Info_%s_restore.txt\n" % switch_ip)
            #print("@"*40)
        else:
            print("\n"+"@"*40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n"+"@"*40)
            pass
    anturlar.close_tel()
    sys.exit()
Beispiel #50
0
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()
Beispiel #51
0
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()
    su = cofra.SwitchUpdate()
    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

    ##################################################################################################
    # Manual list of switches to run suppportftp against. Entire csv list is printed out above but the
    # list below overwries it.
    # This keeps bombing on AMP switch IP (not included below).
    ##################################################################################################
    ip_no_amp = [
        '10.38.36.240', '10.38.36.10', '10.38.36.33', '10.38.36.158',
        '10.38.36.249', '10.38.36.102', '10.38.36.246', '10.38.36.250',
        '10.38.36.98', '10.38.36.125', '10.38.36.25', '10.38.36.24',
        '10.38.36.111', '10.38.36.95', '10.38.36.85', '10.38.36.112'
    ]
    for i in ip_no_amp:
        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:
            anturlar.fos_cmd(
                "supportftp -s -h 10.39.2.171 -u ftp1 -p ftp2 -d ssaves -l ftp"
            )
            anturlar.fos_cmd("supportftp -e")
            anturlar.fos_cmd("supportftp -t 8")
            anturlar.fos_cmd(
                "tsclockserver 10.38.2.80; tstimezone America/Denver")
            anturlar.fos_cmd("echo Y | reboot")
            #anturlar.fos_cmd("tsclockserver LOCL")
        else:
            print("\n" + "@" * 40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n" + "@" * 40)
            pass
        # tn = su.reboot_reconnect()
        anturlar.close_tel()
    sys.exit()
Beispiel #52
0
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 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()
Beispiel #54
0
def main():

    global tn
    
###############################################################################
####
#### 
####
###############################################################################
    pa = parse_args(sys.argv)
    #print("@"*40)
    #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()
        #print(ipaddr_switch)
    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:
        tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
        nos = si.nos_check()
        if not nos:
            sw_dict              = cofra.get_info_from_the_switch()
            switch_ip            = sw_dict["switch_ip"]
            sw_name              = sw_dict["switch_name"]
            sw_chass_name        = sw_dict["chassis_name"]
            sw_director_or_pizza = sw_dict["director"]
            sw_domains           = sw_dict["domain_list"]
            sw_ls_list           = sw_dict["ls_list"]
            sw_base_fid          = sw_dict["base_sw"]
            sw_xisl              = sw_dict["xisl_state"]
            sw_type              = sw_dict["switch_type"]
            sw_license           = sw_dict["license_list"]
            sw_vf_setting        = sw_dict["vf_setting"]
            sw_fcr_enabled       = sw_dict["fcr_enabled"]
            sw_port_list         = sw_dict["port_list"]

            print("\n"*20)
            print("SWITCH IP            : %s   " % switch_ip)
            print("SWITCH NAME          : %s   " % sw_name)
            print("CHASSIS NAME         : %s   " % sw_chass_name)
            print("DIRECTOR             : %s   " % sw_director_or_pizza)
            print("SWITCH DOMAINS       : %s   " % sw_domains)
            print("LOGICAL SWITCH LIST  : %s   " % sw_ls_list)
            print("BASE FID             : %s   " % sw_base_fid)
            print("XISL STATE           : %s   " % sw_xisl)
            print("SWITCH TYPE          : %s   " % sw_type)
            print("LICENSE LIST         : %s   " % sw_license)
            print("VF SETTING           : %s   " % sw_vf_setting)
            print("FCR SETTING          : %s   " % sw_fcr_enabled)
            print("PORT LIST            : %s   " % sw_port_list)
            print("@"*40)
            print("CONSOLE INFO         : %s   " % cons_info)
            print("@"*40)
            print("POWER POLE INFO      : %s   " % power_pole_info)
            print("@"*40)        
            print("\nSwitch_Info has been written this file in logs/Switch_Info_for_playback_%s.txt\n" % switch_ip)
            print("@"*40)
        else:
            print("\n"+"@"*40)
            print('\nTHIS IS A NOS SWITCH> SKIPPING')
            print("\n"+"@"*40)
            pass
    #anturlar.close_tel()
    #sys.exit()
    
###############################################################################
####
####  close telnet connection and 
####  connect to the console
####
###############################################################################
    fcrstate = fcr_state(fcr)
    if fcrstate is True:
        result = fcr_state_persist_enabled_switch_disable(fcr, si)
        print("RESULTFROMSWITCH_DISABLE")
        print(result)
        if result is None:
            print("SUCCESS")
            fcr_state_persist_enabled_hareboot(fcr, si)
        else:
            print("FAILED")
            sys.exit(0)