Kaydet (Commit) 600cc15c authored tarafından Joffrey F's avatar Joffrey F

Merge branch 'container_exec_run' of https://github.com/funkyfuture/docker-py…

Merge branch 'container_exec_run' of https://github.com/funkyfuture/docker-py into funkyfuture-container_exec_run
Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
...@@ -3,7 +3,7 @@ import copy ...@@ -3,7 +3,7 @@ import copy
from ..api import APIClient from ..api import APIClient
from ..errors import (ContainerError, ImageNotFound, from ..errors import (ContainerError, ImageNotFound,
create_unexpected_kwargs_error) create_unexpected_kwargs_error)
from ..types import HostConfig from ..types import ExecResult, HostConfig
from ..utils import version_gte from ..utils import version_gte
from .images import Image from .images import Image
from .resource import Collection, Model from .resource import Collection, Model
...@@ -150,9 +150,10 @@ class Container(Model): ...@@ -150,9 +150,10 @@ class Container(Model):
workdir (str): Path to working directory for this exec session workdir (str): Path to working directory for this exec session
Returns: Returns:
(tuple): A tuple of (exit_code, output) (ExecResult): A tuple of (exit_code, output)
exit_code: (int): exit_code: (int):
Exit code for the executed command Exit code for the executed command or ``None`` if
either ``stream```or ``socket`` is ``True``.
output: (generator or str): output: (generator or str):
If ``stream=True``, a generator yielding response chunks. If ``stream=True``, a generator yielding response chunks.
If ``socket=True``, a socket object for the connection. If ``socket=True``, a socket object for the connection.
...@@ -170,10 +171,12 @@ class Container(Model): ...@@ -170,10 +171,12 @@ class Container(Model):
exec_output = self.client.api.exec_start( exec_output = self.client.api.exec_start(
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
) )
exit_code = 0 if socket or stream:
if stream is False: return ExecResult(None, exec_output)
exit_code = self.client.api.exec_inspect(resp['Id'])['ExitCode'] else:
return (exit_code, exec_output) return ExecResult(
self.client.api.exec_inspect(resp['Id'])['ExitCode'],
exec_output)
def export(self): def export(self):
""" """
......
# flake8: noqa # flake8: noqa
from .containers import ContainerConfig, HostConfig, LogConfig, Ulimit from .containers import (ContainerConfig, ExecResult, HostConfig, LogConfig,
Ulimit)
from .healthcheck import Healthcheck from .healthcheck import Healthcheck
from .networks import EndpointConfig, IPAMConfig, IPAMPool, NetworkingConfig from .networks import EndpointConfig, IPAMConfig, IPAMPool, NetworkingConfig
from .services import ( from .services import (
......
from collections import namedtuple
import six import six
import warnings import warnings
...@@ -11,6 +12,11 @@ from .base import DictType ...@@ -11,6 +12,11 @@ from .base import DictType
from .healthcheck import Healthcheck from .healthcheck import Healthcheck
ExecResult = namedtuple('ExecResult', 'exit_code,output')
""" A result of Container.exec_run with the properties ``exit_code`` and
``output``. """
class LogConfigTypesEnum(object): class LogConfigTypesEnum(object):
_values = ( _values = (
'json-file', 'json-file',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment