From 8a5810b0a9818f9f61affa3b1bd2dc5e54f99a8c Mon Sep 17 00:00:00 2001 From: Dejan Levec Date: Fri, 13 Oct 2017 11:31:22 +0200 Subject: [PATCH 1/2] Minimal changes to get dockerpty.start working on new docker library. --- dockerpty/pty.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dockerpty/pty.py b/dockerpty/pty.py index 25cb788..1052c91 100644 --- a/dockerpty/pty.py +++ b/dockerpty/pty.py @@ -146,7 +146,7 @@ def start(self, sockets=None, **kwargs): pumps.append(io.Pump(pty_stderr, io.Stream(self.stderr), propagate_close=False)) if not self._container_info()['State']['Running']: - self.client.start(self.container, **kwargs) + self.container.start(**kwargs) return pumps @@ -175,9 +175,8 @@ def sockets(self): def attach_socket(key): if info['Config']['Attach{0}'.format(key.capitalize())]: - socket = self.client.attach_socket( - self.container, - {key: 1, 'stream': 1, 'logs': self.logs}, + socket = self.container.attach_socket( + params={key: 1, 'stream': 1, 'logs': self.logs} ) stream = io.Stream(socket) @@ -194,14 +193,14 @@ def resize(self, height, width, **kwargs): """ resize pty within container """ - self.client.resize(self.container, height=height, width=width) + self.container.resize(height=height, width=width) def _container_info(self): """ Thin wrapper around client.inspect_container(). """ - - return self.client.inspect_container(self.container) + self.container.reload() + return self.container.attrs def exec_create(client, container, command, interactive=True): From 73cc6f947a9501717b42158a9e839bf96bedeb69 Mon Sep 17 00:00:00 2001 From: Dejan Levec Date: Fri, 13 Oct 2017 15:23:14 +0200 Subject: [PATCH 2/2] Add support for exec_* from new API. --- dockerpty/pty.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dockerpty/pty.py b/dockerpty/pty.py index 1052c91..0a013f2 100644 --- a/dockerpty/pty.py +++ b/dockerpty/pty.py @@ -204,8 +204,8 @@ def _container_info(self): def exec_create(client, container, command, interactive=True): - exec_id = client.exec_create(container, command, tty=interactive, stdin=interactive) - return exec_id + exec_id = client.api.exec_create(container, command, tty=interactive, stdin=interactive) + return exec_id['Id'] class ExecOperation(Operation): @@ -256,7 +256,7 @@ def sockets(self): """ Return a single socket which is processing all I/O to exec """ - socket = self.client.exec_start(self.exec_id, socket=True, tty=self.interactive) + socket = self.client.api.exec_start(self.exec_id, socket=True, tty=self.interactive) stream = io.Stream(socket) if self.is_process_tty(): return stream @@ -267,7 +267,7 @@ def resize(self, height, width, **kwargs): """ resize pty of an execed process """ - self.client.exec_resize(self.exec_id, height=height, width=width) + self.client.api.exec_resize(self.exec_id, height=height, width=width) def is_process_tty(self): """ @@ -280,7 +280,7 @@ def _exec_info(self): Caching wrapper around client.exec_inspect """ if self._info is None: - self._info = self.client.exec_inspect(self.exec_id) + self._info = self.client.api.exec_inspect(self.exec_id) return self._info