コード例 #1
0
def console_info_from_ip(ipaddr, chassis_name):
    """
    
    """
    #####################################
    # Check if file is available
    switchmatrix = '/home/RunFromHere/ini/SwitchMatrix.csv'
    switchmatrix = 'ini/SwitchMatrix.csv'
    try:
        csv_file = csv.DictReader(open(switchmatrix, 'r'),
                                  delimiter=',',
                                  quotechar='"')
    except OSError:
        print("Cannot find the file SwitchMatrix.csv")
        return (False)

    #####################################
    #Check if IP is in valid format
    a = cofra.check_ip_format(ipaddr)
    print(a)
    if a == True:
        pass
    else:
        print("\nPLEASE CHECK YOUR IP ADDRESS AND TRY AGAIN")
        sys.exit()

    #####################################
    #Check if IP is in SwitchMatrix file
    ipaddr_switch = get_ip_from_file(chassis_name)
    if ipaddr in ipaddr_switch:
        print('IP ADDRESS FOUND IN SwitchMatrix file')
    else:
        print('\nIP ADDRESS NOT FOUND IN SwitchMatrix file.')
        print('Are you sure this is your switch??\n')
        sys.exit()

    for line in csv_file:
        ip_address_from_file = (line['IP Address'])

        if ip_address_from_file == ipaddr:
            swtch_name = (line['Chassisname'])

        else:
            print("\r\n")
    return (swtch_name)
コード例 #2
0
ファイル: ex_deconfig.py プロジェクト: gsquire1/Python
def console_info_from_ip(ipaddr, chassis_name):
    """
    
    """
    #####################################
    # Check if file is available
    switchmatrix = '/home/RunFromHere/ini/SwitchMatrix.csv'
    switchmatrix = 'ini/SwitchMatrix.csv'
    try:
        csv_file = csv.DictReader(open(switchmatrix, 'r'), delimiter=',', quotechar='"')
    except OSError:
        print("Cannot find the file SwitchMatrix.csv")
        return(False)
    
    #####################################
    #Check if IP is in valid format
    a = cofra.check_ip_format(ipaddr)
    print(a)
    if a == True:
        pass
    else:
        print("\nPLEASE CHECK YOUR IP ADDRESS AND TRY AGAIN")
        sys.exit()
        
    #####################################
    #Check if IP is in SwitchMatrix file
    ipaddr_switch   = get_ip_from_file(chassis_name)
    if ipaddr in ipaddr_switch:
        print('IP ADDRESS FOUND IN SwitchMatrix file')
    else:
        print('\nIP ADDRESS NOT FOUND IN SwitchMatrix file.')
        print('Are you sure this is your switch??\n')
        sys.exit()
        
    for line in csv_file:
        ip_address_from_file = (line['IP Address'])
        
        if ip_address_from_file == ipaddr:
            swtch_name = (line['Chassisname'])
         
        else:
            print("\r\n")
    return(swtch_name)