Example #1
0
    def cli_command(self, cmd_list, host, port, username, password, output='/tmp/cli_command.log', cli_type='telnet'):
        """
        True False
        """
        print 'in cli_command'

        CLI = clicmd.clicmd(has_color=False)

        res, last_error = CLI.run(cmd_list, cli_type, host, port, username, password, cli_prompt=None, mute=False,
                                  timeout=60)

        m_return_code = r'last_cmd_return_code:(\d)'

        if res:

            for r in res:
                rc = re.findall(m_return_code, r)
                if len(rc) > 0:
                    print 'EACH command result :', rc
                    return_code = rc[0]
                    if str(return_code) != '0':
                        all_rc = False
                        return all_rc

            CLI.saveResp2file(output)
        else:
            print 'AT_ERROR : cli command failed'
            return False
        return True
Example #2
0
 def cli_command_with_output(self, cmd_list, host, port, username, password, output='/tmp/cli_command.log', cli_type='ssh', timeout=360):
     """
     True False
     """
     print 'in cli_command'
     
     CLI = clicmd.clicmd(has_color=False)
     
     
     res, last_error = CLI.run(cmd_list, cli_type, host, port, username, password, cli_prompt=None, mute=False, timeout=timeout)
     
     
     m_return_code = r'last_cmd_return_code:(\d)'
     
     out_rc = ''
     
     if res:
         
         for r in res:
             out_rc += r
             rc = re.findall(m_return_code, r)
             if len(rc) > 0:
                 print 'EACH command result :', rc
                 return_code = 0
                 for rc_idx in range(len(rc)):
                     return_code += int(rc[rc_idx])
 
                 if str(return_code) != '0':
                     all_rc = False
                     return all_rc, out_rc
                 
 
     else:
         print 'AT_ERROR : cli command failed'
         return False, 'AT_ERROR : cli command failed'
 
             
     return True, out_rc
Example #3
0
    def cli_command_with_output(
        self, cmd_list, host, port, username, password, output="/tmp/cli_command.log", cli_type="ssh", timeout=360
    ):
        """
        True False
        """
        print "in cli_command"

        CLI = clicmd.clicmd(has_color=False)

        res, last_error = CLI.run(
            cmd_list, cli_type, host, port, username, password, cli_prompt=None, mute=False, timeout=timeout
        )

        m_return_code = r"last_cmd_return_code:(\d)"

        out_rc = ""

        if res:

            for r in res:
                out_rc += r
                rc = re.findall(m_return_code, r)
                if len(rc) > 0:
                    print "EACH command result :", rc
                    return_code = 0
                    for rc_idx in range(len(rc)):
                        return_code += int(rc[rc_idx])

                    if str(return_code) != "0":
                        all_rc = False
                        return all_rc, out_rc

        else:
            print "AT_ERROR : cli command failed"
            return False, "AT_ERROR : cli command failed"

        return True, out_rc