Ejemplo n.º 1
0
def check(console):
    '''
    Checks if in enable
    '''

    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == ">":
                write.serial(console, "en")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, credentials.password)
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
            elif prompt[0][-1:] == "#":
                print("Enabled")
                return (True)
                break
        else:
            write.serial(console, "\r")
Ejemplo n.º 2
0
def command(console):
    '''
    Pings command gateway
    '''
    params = parameters.get()
    failedPing = 0

    while True:
        prompt = read.serial(console)
        test = params['test']
        if prompt:
            if prompt[0][-1:] == '#' or prompt[0][-1:] == '>':
                    write.serial(console, "ping {}".format(test))
                    prompt = read.serial(console)
                    time.sleep(1)
                    write.serial(console, '\r')
                    time.sleep(5)
                    prompt = read.serial(console)
                    if any('!!!!!' in s for s in prompt):
                        print("Ping OK")
                        return(True)
            if prompt[0] == '.':
                failedPing += 1
            if failedPing == 5:
                failedPing = 0
                print("Ping Timeout")
                tryAgain = input("Try again (y) or ignore (n): ")
                if tryAgain == "y":
                    continue
                else:
                    return(True)

        else:
            write.serial(console, "\r")
            time.sleep(1)
Ejemplo n.º 3
0
def check(console):
    '''
    Checks if ip interface configured
    '''

    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#" or prompt[0][-1:] == ">":
                write.serial(console, "sh ip int br")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                time.sleep(4)
                prompt = read.serial(console)
                if any('10.0.0.2' in s for s in prompt):
                    print("Interface set for 10.0.0.2")
                    return (True)
                else:
                    print("Interface not set.")
                    return (False)
            if prompt[0][:9] == 'Username:':
                login.now(console)
        else:
            write.serial(console, "\r")
Ejemplo n.º 4
0
def copy(console, vehicle):
    params = parameters.get()
    name = vehicle[0].lower()

    conf_file = '{}{}{}.txt'.format(params['prefix'], name, params['suffix'])

    waiting = False

    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#":
                write.serial(
                    console, "copy tftp://{}/config/{} flash:".format(
                        params['ip'], conf_file))
                time.sleep(1)
                prompt = read.serial(console)
                write.serial(console, "\r")
                time.sleep(3)
                prompt = read.serial(console)
            elif prompt[0][:9] == 'Accessing':
                print("waiting...")
                waiting = True
                prompt = read.serial(console)
                time.sleep(4)
                prompt = read.serial(console)

            elif any("(Timed out)" in s for s in prompt):
                if prompt[0][-11:] == '(Timed out)':
                    while True:
                        try_again = input("TFTP Timed out, try again? (y/n): ")
                        if try_again == 'y':
                            break
                        elif try_again == 'n':
                            print("Aborting...")
                            return (False)
                        else:
                            print("I said y or n")

            elif any("[OK - " in s for s in prompt):
                print("OK Detected")
                waiting = False
                return (True)

            elif any("Do you want to over write? [confirm]" in s
                     for s in prompt):
                print("Overwriting")
                write.serial(console, "\r")
                time.sleep(1)
                return (True)
        else:
            write.serial(console, "\r")
            time.sleep(1)
Ejemplo n.º 5
0
def now(console):
    write.serial(console, '\r')
    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == ">":
                write.serial(console, "login\r")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '{}\r'.format(credentials.username))
                prompt = read.serial(console)
                time.sleep(3)
                write.serial(console, '{}\r'.format(credentials.password))
                prompt = read.serial(console)
                time.sleep(3)
                write.serial(console, '{}\r'.format('en'))
                prompt = read.serial(console)
                time.sleep(3)
                write.serial(console, '{}\r'.format(credentials.password))
                prompt = read.serial(console)
                time.sleep(3)
                print('Logged in')
                return (True)
            elif prompt[0][-1:] == '#':
                print('Logged in')
                return (True)
            elif prompt[0][:9] == 'Username:'******'{}\r'.format(credentials.configured_username))
                prompt = read.serial(console)
                time.sleep(3)
                write.serial(console,
                             '{}\r'.format(credentials.configured_password))
                prompt = read.serial(console)
                time.sleep(3)
                write.serial(console, '{}\r'.format('en'))
                prompt = read.serial(console)
                time.sleep(3)
                write.serial(console,
                             '{}\r'.format(credentials.configured_password))
                prompt = read.serial(console)
                time.sleep(3)
                print('Logged in')
                return (True)
            else:
                write.serial(console, '\r')
                time.sleep(1)
Ejemplo n.º 6
0
def convert(console):
    write.serial(console, '\r')
    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#":
                write.serial(console, "debug capwap console cli")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, 'capwap ap autonomous')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, 'yes')
                prompt = read.serial(console)
                time.sleep(1)
                print('Stating autonomous conversion')
                return (True)
            elif prompt[0][-1:] == '>':
                print('Not Logged in')
                return (False)
            else:
                write.serial(console, '\r')
        else:
            write.serial(console, '\r')
Ejemplo n.º 7
0
def load(console, vehicle):

    print("Loading config to running-config")
    name = vehicle[0].lower()
    params = parameters.get()

    conf_file = '{}{}{}.txt'.format(params['prefix'], name, params['suffix'])

    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#":
                write.serial(console, "copy flash:{} run".format(conf_file))
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                time.sleep(2)
                prompt = read.serial(console)
                write.serial(console, '\r')
                time.sleep(2)
                prompt = read.serial(console)
                write.serial(console, 'wr mem')
                time.sleep(1)
                prompt = read.serial(console)
                write.serial(console, '\r')
                time.sleep(4)
                prompt = read.serial(console)
                print("Configured as {}".format(name))
                return (True)
        else:
            write.serial(console, "\r")
Ejemplo n.º 8
0
def upgrade(console):
    params = parameters.get()
    ip = params['ip']
    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#":
                write.serial(
                    console,
                    "archive download-sw /overwrite /force-reload tftp://{}/ap3g2-k9w7-tar.153-3.JI1.tar"
                    .format(ip))
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                print("Transferring image and upgrading...")
                prompt = read.serial(console)
                time.sleep(1)
                return (True)
            else:
                print("Not enabled.")
                return (False)
        else:
            write.serial(console, "\r")
Ejemplo n.º 9
0
def check(console):
    '''
    Checks if upgraded or not
    '''

    old_ver = 'Version 15.3(3)JF5, RELEASE SOFTWARE (fc2)'
    new_ver = 'Version 15.3(3)JI1, RELEASE SOFTWARE (fc1)'

    print("Checking software version...")
    while True:

        prompt = read.serial(console)
        if prompt:
            if prompt[0][:2] == 'AP':
                if prompt[0][-1:] == '>' or prompt[0][-1:] == '#':
                    write.serial(console, "sh ver")
            elif prompt[0] == 'ap>' or prompt[0] == 'ap#':
                write.serial(console, "sh ver")
            elif len(prompt[0]) >= 10:
                # suffix no longer relevant
                '''
                if prompt[0][-9:] == '-command#' or prompt[0][-7:] == '-fleet#':
                        print('Upgraded')
                        return(True)
                elif prompt[0][-9:] == '-command>' or prompt[0][-7:] == '-fleet>':
                        print('Upgraded')
                        return(True)
                '''
                if prompt[0][-1] == '>' or prompt[0][-1] == '#':
                    write.serial(console, "sh ver")
            elif len(prompt[0]) == 9:
                if prompt[0][:9] == 'Username:'******'Upgraded')
                return (True)
            elif any(old_ver in s for s in prompt):
                print('Not Upgraded')
                return (False)
            elif any("--More--" in s for s in prompt):
                write.serial(console, ' ')

        else:
            write.serial(console, "\r")
            time.sleep(1)
Ejemplo n.º 10
0
def check(console):
    '''
    Check if finished booting, otherwise print bootup
    '''
    print("Checking boot status...")
    while True:
        prompt = read.serial(console)

        if prompt:
            if match.boot(prompt[0]):
                print("Booted")
                return (True)
            elif any("--More--" in s for s in prompt):
                write.serial(console, ' ')
        else:
            write.serial(console, '\r')
            time.sleep(3)
Ejemplo n.º 11
0
def check(console):
    '''
    Checks if autonomous
    '''
    print("Checking if autonomous")
    while True:
        prompt = read.serial(console)
        if prompt:
            if len(prompt[0]) == 3:
                if prompt[0] == 'ap>' or prompt[0] == 'ap#':
                    print('Autonomous')
                    return (True)
            elif len(prompt[0]) >= 10:
                if prompt[0][:2] == 'AP':
                    if prompt[0][-1:] == '>' or prompt[0][-1:] == '#':
                        print('Not autonomous')
                        return (False)

                elif prompt[0][-9:] == '-command#' or prompt[0][
                        -7:] == '-fleet#':
                    print('Autonomous')
                    return (True)
                elif prompt[0][-9:] == '-command>' or prompt[0][
                        -7:] == '-fleet>':
                    print('Autonomous')
                    return (True)
                elif prompt[0][-1] == '>' or prompt[0][-1] == '#':
                    print('Autonomous')
                    return (True)
            elif len(prompt[0]) == 9:
                if prompt[0][:9] == 'Username:'******'Autonomous')
                    return (True)
                else:
                    print("Unreconized prompt")

        else:
            write.serial(console, "\r")
            time.sleep(1)
Ejemplo n.º 12
0
def check(console):
    '''
    Checks configuration status
    '''
    print('Checking configuration')

    params = parameters.get()

    while True:
        prompt = read.serial(console)
        if prompt:
            if len(prompt[0]) == 3:
                if prompt[0] == 'ap>' or prompt[0] == 'ap#':
                    print('Not configured')
                    return (False)
            elif prompt[0][:2] == 'AP':
                if prompt[0][-1:] == '>' or prompt[0][-1:] == '#':
                    print('Not configured')
                    return (False)

            elif len(prompt[0]) >= 9:
                if prompt[0][-1] == '#' or prompt[0][-1] == '>':
                    if prompt[0].startswith(
                            params['prefix']) and prompt[0].endswith(
                                params['suffix']):
                        print("Already configured as {}".format(prompt[0]))
                        return ('something')
                    else:
                        print('Unable to detect current configuration.')
                        return ('something')

            elif any("--More--" in s for s in prompt):
                write.serial(console, ' ')

        else:
            write.serial(console, "\r")
            time.sleep(1)
Ejemplo n.º 13
0
def configure(console):
    params = parameters.get()
    temp_ip = params['temp']
    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#":
                write.serial(console, "conf t")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, "int bvi1")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console,
                             "ip address {} 255.255.255.0".format(temp_ip))
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, "exit")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, "exit")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                print("Interface configured")
                return (True)
            else:
                print("Not enabled.")
                return (False)
        else:
            write.serial(console, "\r")
Ejemplo n.º 14
0
def finish(console, vehicle):
    params = parameters.get()

    hostname = '{}{}{}'.format(params['prefix'], vehicle[0], params['suffix'])

    if params['case'] == 'lower':
        hostname = hostname.lower()
    elif params['case'] == 'upper':
        hostname = hostname.upper()

    while True:
        prompt = read.serial(console)
        if prompt:
            if prompt[0][-1:] == "#":
                write.serial(console, "wr mem")
                prompt = read.serial(console)
                time.sleep(1)
                write.serial(console, '\r')
                prompt = read.serial(console)
                time.sleep(1)
                print("Config written to memory")
                write.serial(console, '\r')
                time.sleep(2)
                prompt = read.serial(console)
                configured_name = prompt[0][:-1]
                close.serial(console)
                break

        else:
            write.serial(console, "\r")

    

    if configured_name != hostname:
        print("!!WARNING!!")
        print('Configured hostname DOES NOT match specified vehicle [FAIL]')
        print("Configured:  {}".format(configured_name))
        print("Specified:   {}".format(vehicle[0]))

        while True:
            try_again = input("Try again (y) or ignore (n): ")
            if try_again == 'n':
                break
            elif try_again == "y":
                break
            else:
                print("How hard is it to press y or n")
    
        
    if configured_name == hostname or try_again == 'n':
        print("--------------------------------------")
        print("CONGRATULATIONS! MADE IT TO THE END!")
        print("Check config via putty.")
        print("Don't forget to update records")
        print("--------------------------------------")
        print('--------------------------------------')
        print('   VEHICLE:     {}'.format(vehicle[0]))
        print('        IP:     {}'.format(vehicle[1]))
        print('  HOSTNAME:     {}'.format(hostname))
        print('--------------------------------------')
        print('')
        print('Milkshakes are on {}'.format(random.choice(names)))
        input('Ready for another round? [ENTER]')