'Telnet login. Can be username/password or just password.'

def telnet_login(self, pri_prompt_terminator=u'#', alt_prompt_terminator=u'>', username_pattern=u'sername', pwd_pattern=u'assword', delay_factor=1, max_loops=60):

    TELNET_RETURN = u'\r\n'
    delay_factor = self.select_delay_factor(delay_factor)
    time.sleep((1 * delay_factor))
    output = u''
    return_msg = u''
    i = 1
    while (i <= max_loops):
        try:
            output = self.read_channel()
            return_msg += output
            if re.search(username_pattern, output):
                self.write_channel((self.username + TELNET_RETURN))
                time.sleep((1 * delay_factor))
                output = self.read_channel()
                return_msg += output
            if re.search(pwd_pattern, output):
                self.write_channel((self.password + TELNET_RETURN))
                time.sleep((0.5 * delay_factor))
                output = self.read_channel()
                return_msg += output
                if ((pri_prompt_terminator in output) or (alt_prompt_terminator in output)):
                    return return_msg
            if ((pri_prompt_terminator in output) or (alt_prompt_terminator in output)):
                return return_msg
            self.write_channel(TELNET_RETURN)
            time.sleep((0.5 * delay_factor))
            i += 1
        except EOFError:
            msg = u'Telnet    login    failed:    {0}'.format(self.host)
            raise NetMikoAuthenticationException(msg)
    self.write_channel(TELNET_RETURN)
    time.sleep((0.5 * delay_factor))
    output = self.read_channel()
    return_msg += output
    if ((pri_prompt_terminator in output) or (alt_prompt_terminator in output)):
        return return_msg
    msg = u'Telnet    login    failed:    {0}'.format(self.host)
    raise NetMikoAuthenticationException(msg)
