diff options
author | Frank Sachsenheim <funkyfuture@riseup.net> | 2018-01-28 01:38:31 +0100 |
---|---|---|
committer | Frank Sachsenheim <funkyfuture@riseup.net> | 2018-01-28 01:44:28 +0100 |
commit | a63b726d40096e45ebb0598511573efea13b320f (patch) | |
tree | 88f5d056de572da17580cdbfa07c5b4d4b073045 | |
parent | ad208dfd29e6b5b8426763b835c29948f9dd8604 (diff) | |
download | docker-py-a63b726d40096e45ebb0598511573efea13b320f.tar.gz |
Container.exec_run returns a namedtuple w/ attrs exit_code & output
Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
-rw-r--r-- | docker/models/containers.py | 11 | ||||
-rw-r--r-- | docker/types/__init__.py | 3 | ||||
-rw-r--r-- | docker/types/containers.py | 6 |
3 files changed, 14 insertions, 6 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py index 42c9d55..ed3f7ac 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -3,7 +3,7 @@ import copy from ..api import APIClient from ..errors import (ContainerError, ImageNotFound, create_unexpected_kwargs_error) -from ..types import HostConfig +from ..types import ExecResult, HostConfig from ..utils import version_gte from .images import Image from .resource import Collection, Model @@ -150,7 +150,7 @@ class Container(Model): workdir (str): Path to working directory for this exec session Returns: - (tuple): A tuple of (exit_code, output) + (ExecResult): A tuple of (exit_code, output) exit_code: (int): Exit code for the executed command or ``None`` if either ``stream```or ``socket`` is ``True``. @@ -172,10 +172,11 @@ class Container(Model): resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket ) if socket or stream: - return None, exec_output + return ExecResult(None, exec_output) else: - return (self.client.api.exec_inspect(resp['Id'])['ExitCode'], - exec_output) + return ExecResult( + self.client.api.exec_inspect(resp['Id'])['ExitCode'], + exec_output) def export(self): """ diff --git a/docker/types/__init__.py b/docker/types/__init__.py index 39c93e3..bd19638 100644 --- a/docker/types/__init__.py +++ b/docker/types/__init__.py @@ -1,5 +1,6 @@ # flake8: noqa -from .containers import ContainerConfig, HostConfig, LogConfig, Ulimit +from .containers import (ContainerConfig, ExecResult, HostConfig, LogConfig, + Ulimit) from .healthcheck import Healthcheck from .networks import EndpointConfig, IPAMConfig, IPAMPool, NetworkingConfig from .services import ( diff --git a/docker/types/containers.py b/docker/types/containers.py index 15dd86c..8d1f271 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -1,3 +1,4 @@ +from collections import namedtuple import six import warnings @@ -11,6 +12,11 @@ from .base import DictType 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): _values = ( 'json-file', |