Пример #1
0
 async def _establish_connection(self):
     """Establishing SSH connection to the network device"""
     logger.info(
         "Host {}: Establishing connection to port {}".format(self._host, self._port)
     )
     output = ""
     # initiate SSH connection
     fut = asyncssh.connect(**self._connect_params_dict)
     try:
         self._conn = await asyncio.wait_for(fut, self._timeout)
     except asyncssh.DisconnectError as e:
         raise DisconnectError(self._host, e.code, e.reason)
     except asyncio.TimeoutError:
         raise TimeoutError(self._host)
     self._stdin, self._stdout, self._stderr = await self._conn.open_session(
         term_type="Dumb", term_size=(200, 24)
     )
     logger.info("Host {}: Connection is established".format(self._host))
     # Flush unnecessary data
     delimiters = map(re.escape, type(self)._delimiter_list)
     delimiters = r"|".join(delimiters)
     output = await self._read_until_pattern(delimiters)
     logger.debug(
         "Host {}: Establish Connection Output: {}".format(self._host, repr(output))
     )
     return output
Пример #2
0
    async def _establish_connection(self):
        """Establish SSH connection to the network device"""
        logger.info('Host {}: Establishing connection to port {}'.format(self._host, self._port))
        output = ""
        # initiate SSH connection
        try:
            self._conn = await asyncssh.connect(**self._connect_params_dict)
        except asyncssh.DisconnectError as e:
            raise DisconnectError(self._host, e.code, e.reason)

        self._stdin, self._stdout, self._stderr = await self._conn.open_session(term_type='dumb')
        logger.info("Host {}: Connection is established".format(self._host))
        # Flush unnecessary data
        output = await self._read_until_prompt()
        logger.debug("Host {}: Establish Connection Output: {}".format(self._host, repr(output)))
        return output