コード例 #1
0
    def reconnect(self, timeout=None):
        """Reconnect session, keep current command mode.

        :param timeout: Timeout for operation
        """
        prompts_re = r"|".join(
            CommandModeHelper.defined_modes_by_prompt(self.command_mode).keys()
        )
        self.session.reconnect(prompts_re, self._logger, timeout)
        self._initialize(self.command_mode)
コード例 #2
0
    def __enter__(self):
        """Enter.

        :rtype: CliService
        """
        prompts_re = r"|".join(
            CommandModeHelper.defined_modes_by_prompt(
                self._command_mode).keys())
        self._active_session = self._session_pool.get_session(
            self._defined_sessions, prompts_re, self._logger)
        try:
            return self._initialize_cli_service(self._active_session,
                                                prompts_re)
        except Exception:
            self._session_pool.remove_session(self._active_session,
                                              self._logger)
            raise