Merge pull request #36 from aanand/get-attach-socket

attach_socket() method for just getting the HTTP socket
This commit is contained in:
Joffrey F 2013-09-03 18:52:37 -07:00
commit 76a34c5fd3
1 changed files with 12 additions and 7 deletions

View File

@ -197,18 +197,23 @@ class Client(requests.Session):
f.close()
return config_file
def attach(self, container):
params = {
'stdout': 1,
'stderr': 1,
'stream': 1
}
def attach_socket(self, container, params=None):
if params is None:
params = {
'stdout': 1,
'stderr': 1,
'stream': 1
}
u = self._url("/containers/{0}/attach".format(container))
res = self.post(u, None, params=params, stream=True)
# hijack the underlying socket from requests, icky
# but for some reason requests.iter_contents and ilk
# eventually block
socket = res.raw._fp.fp._sock
return res.raw._fp.fp._sock
def attach(self, container):
socket = self.attach_socket(container)
while True:
chunk = socket.recv(4096)