mirror of https://github.com/docker/docker-py.git
Merge branch 'master' of github.com:dotcloud/docker-py into issue-33
Conflicts: docker/client.py
This commit is contained in:
commit
49a3cb87b1
|
@ -106,6 +106,18 @@ class Client(requests.Session):
|
||||||
command = shlex.split(str(command))
|
command = shlex.split(str(command))
|
||||||
if isinstance(environment, dict):
|
if isinstance(environment, dict):
|
||||||
environment = ['{0}={1}'.format(k, v) for k, v in environment.items()]
|
environment = ['{0}={1}'.format(k, v) for k, v in environment.items()]
|
||||||
|
|
||||||
|
attach_stdin = False
|
||||||
|
attach_stdout = False
|
||||||
|
attach_stderr = False
|
||||||
|
|
||||||
|
if not detach:
|
||||||
|
attach_stdout = True
|
||||||
|
attach_stderr = True
|
||||||
|
|
||||||
|
if stdin_open:
|
||||||
|
attach_stdin = True
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'Hostname': hostname,
|
'Hostname': hostname,
|
||||||
'PortSpecs': ports,
|
'PortSpecs': ports,
|
||||||
|
@ -113,9 +125,9 @@ class Client(requests.Session):
|
||||||
'Tty': tty,
|
'Tty': tty,
|
||||||
'OpenStdin': stdin_open,
|
'OpenStdin': stdin_open,
|
||||||
'Memory': mem_limit,
|
'Memory': mem_limit,
|
||||||
'AttachStdin': False,
|
'AttachStdin': attach_stdin,
|
||||||
'AttachStdout': False,
|
'AttachStdout': attach_stdout,
|
||||||
'AttachStderr': False,
|
'AttachStderr': attach_stderr,
|
||||||
'Env': environment,
|
'Env': environment,
|
||||||
'Cmd': command,
|
'Cmd': command,
|
||||||
'Dns': dns,
|
'Dns': dns,
|
||||||
|
@ -197,20 +209,25 @@ class Client(requests.Session):
|
||||||
f.close()
|
f.close()
|
||||||
return config_file
|
return config_file
|
||||||
|
|
||||||
def attach(self, container):
|
def attach_socket(self, container, params=None):
|
||||||
params = {
|
if params is None:
|
||||||
'stdout': 1,
|
params = {
|
||||||
'stderr': 1,
|
'stdout': 1,
|
||||||
'stream': 1
|
'stderr': 1,
|
||||||
}
|
'stream': 1
|
||||||
|
}
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
|
|
||||||
u = self._url("/containers/{0}/attach".format(container))
|
u = self._url("/containers/{0}/attach".format(container))
|
||||||
res = self.post(u, None, params=params, stream=True)
|
res = self.post(u, None, params=params, stream=True)
|
||||||
# hijack the underlying socket from requests, icky
|
# hijack the underlying socket from requests, icky
|
||||||
# but for some reason requests.iter_contents and ilk
|
# but for some reason requests.iter_contents and ilk
|
||||||
# eventually block
|
# 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:
|
while True:
|
||||||
chunk = socket.recv(4096)
|
chunk = socket.recv(4096)
|
||||||
|
|
Loading…
Reference in New Issue