Example #1
0
 def _execute(self, connection=None, cmd=None, interactions=None):
     super(Telnet, self)._execute(connection=connection, cmd=cmd, interactions=interactions)
     context     = {"CTX-UUID": get_context_uid()}
     logger      = self._logger
     buff        = StringIO()
     connection.write(self.crlf(cmd))
     if interactions:
         for i_res, i_cmd in interactions:
             i_res_re  = re.compile(i_res)
             i_cmd_res = connection.expect([i_res_re], self.transaction_timeout)
             if i_cmd_res[0] >= 0:
                 logger.info("Pattern '%s' matched; Sending reply-command '%s' -- context: %s" % (i_res, i_cmd, context))
                 buff.write(i_cmd_res[2])
                 connection.write(self.crlf(i_cmd))
     cmd_res = connection.expect([self.prompt_mark_re], self.transaction_timeout)
     buff.write(cmd_res[2])
     try:
         self._check_telnet_return(cmd_res)
     except TelnetProtocolException:
         self._logger.debug("Incomplete data received: Stuck process or bad configured interactions -- context: %s. (transaction_timeout='%s'; recv_buffer='%s')" \
                                  % (context, self.transaction_timeout, buff.getvalue()))
         buff.close()
         raise TransportTransactionException("Incomplete data received: Stuck process or bad configured interactions (transaction_timeout='%s')" % self.transaction_timeout)
     cmdout = "\r\n".join(buff.getvalue().splitlines()[1:-1])
     buff.close()
     if self.error_mark is not None:
         # errpos = cmdout.find(self.error_mark)
         # if self.error_mark and errpos > -1:
         #     raise SwitchCommandException(cmdout[errpos+len(self.error_mark):].strip())
         m = self.error_mark_re.search(cmdout)
         if m:
             raise SwitchCommandException(m.group(1).strip())
     return cmdout
Example #2
0
 def _execute(self, connection=None, cmd=None, interactions=None):
     super(SysSSH, self)._execute(connection=connection, cmd=cmd, interactions=interactions)
     context = {"CTX-UUID": get_context_uid()}
     logger = self._logger
     buff = StringIO()
     interaction = 0
     connection.send(self.crlf(cmd))
     while not self.prompt_mark_re.search(buff.getvalue()):
         try:
             self._recvall_with_timeout(connection=connection, buff=buff)
         except SSHTimeout, e:
             buff.close()
             logger.error(
                 "Incomplete data received: Stuck process or bad configured interactions -- context: %s. (transaction_timeout='%s'; recv_buffer='%s')"
                 % (context, e.recv_timeout, e.recv_buff)
             )
             raise TransportTransactionException(
                 "Incomplete data received: Stuck process or bad configured interactions (transaction_timeout='%s')"
                 % e.recv_timeout
             )
         if interactions and interaction <= (len(interactions) - 1):
             i_res, i_cmd = interactions[interaction]
             i_res_re = re.compile(i_res)
             if i_res_re.search(buff.getvalue()):
                 logger.info(
                     "Pattern '%s' matched; Sending reply-command '%s' -- context: %s" % (i_res, i_cmd, context)
                 )
                 connection.send(self.crlf(i_cmd))
                 interaction += 1
Example #3
0
    def _execute(self, connection=None, cmd=None, interactions=None):
        """
        Execute command 'cmd' (+'interactions') using 'connection' object
        """
        context = {"CTX-UUID": get_context_uid()}

        self._logger.info("%s(%s@%s:%s): Command '%s' invoked with interactions: %s -- context: %s" % \
        (self.__class__.__name__, self.username, self.host, self.port, cmd, \
            "; ".join(["'%s'->'%s'" % (i_res, i_cmd) for i_res, i_cmd in interactions]) \
            if interactions else "''", context))