def connect(self): url = self.url LOG.debug('connecting to: %s', url) try: self.ws = websocket.create_connection( url, skip_utf8_validation=True, origin=self._compute_origin_header(url), subprotocols=["binary", "base64"]) print('connected to %s, press Enter to continue' % self.id) print('type %s. to disconnect' % self.escape) except socket.error as e: raise exceptions.ConnectionFailed(e) except websocket.WebSocketConnectionClosedException as e: raise exceptions.ConnectionFailed(e) except websocket.WebSocketBadStatusException as e: raise exceptions.ConnectionFailed(e)
def connect(self): try: client = docker.APIClient(base_url=self.url) self.socket = client.exec_start(self.exec_id, socket=True, tty=True) print('connected to container "%s"' % self.id) print('type %s. to disconnect' % self.escape) except docker.errors.APIError as e: raise exceptions.ConnectionFailed(e)
def start_loop(self): self.poll = select.poll() self.poll.register(sys.stdin, select.POLLIN | select.POLLHUP | select.POLLPRI) self.poll.register(self.fileno(), select.POLLIN | select.POLLHUP | select.POLLPRI) self.start_of_line = False self.read_escape = False with WINCHHandler(self): try: self.setup_tty() self.run_forever() except socket.error as e: raise exceptions.ConnectionFailed(e) except websocket.WebSocketConnectionClosedException as e: raise exceptions.Disconnected(e) finally: self.restore_tty()