Skip to content

Commit 27ec5f3

Browse files
committed
Rename Client -> DockerClient
Replace references to old Client with APIClient Moved contents of services.md to appropriate locations Signed-off-by: Joffrey F <[email protected]>
1 parent e098dbf commit 27ec5f3

File tree

14 files changed

+206
-287
lines changed

14 files changed

+206
-287
lines changed

docker/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# flake8: noqa
22
from .api import APIClient
3-
from .client import Client, from_env
3+
from .client import DockerClient, from_env
44
from .version import version, version_info
55

66
__version__ = version

docker/api/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
3232
3333
Example:
3434
>>> from io import BytesIO
35-
>>> from docker import Client
35+
>>> from docker import APIClient
3636
>>> dockerfile = '''
3737
... # Shared Volume
3838
... FROM busybox:buildroot-2014.02
3939
... VOLUME /data
4040
... CMD ["/bin/sh"]
4141
... '''
4242
>>> f = BytesIO(dockerfile.encode('utf-8'))
43-
>>> cli = Client(base_url='tcp://127.0.0.1:2375')
43+
>>> cli = APIClient(base_url='tcp://127.0.0.1:2375')
4444
>>> response = [line for line in cli.build(
4545
... fileobj=f, rm=True, tag='yourname/volume'
4646
... )]

docker/api/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def copy(self, container, resource):
215215
"""
216216
if utils.version_gte(self._version, '1.20'):
217217
warnings.warn(
218-
'Client.copy() is deprecated for API version >= 1.20, '
218+
'APIClient.copy() is deprecated for API version >= 1.20, '
219219
'please use get_archive() instead',
220220
DeprecationWarning
221221
)

docker/api/swarm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
7777
force_new_cluster (bool): Force creating a new Swarm, even if
7878
already part of one. Default: False
7979
swarm_spec (dict): Configuration settings of the new Swarm. Use
80-
``Client.create_swarm_spec`` to generate a valid
80+
``APIClient.create_swarm_spec`` to generate a valid
8181
configuration. Default: None
8282
8383
Returns:

docker/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
from .utils import kwargs_from_env
1010

1111

12-
class Client(object):
12+
class DockerClient(object):
1313
"""
1414
A client for communicating with a Docker server.
1515
1616
Example:
1717
1818
>>> import docker
19-
>>> client = Client(base_url='unix://var/run/docker.sock')
19+
>>> client = docker.DockerClient(base_url='unix://var/run/docker.sock')
2020
2121
Args:
2222
base_url (str): URL to the Docker server. For example,
@@ -155,7 +155,7 @@ def version(self, *args, **kwargs):
155155
version.__doc__ = APIClient.version.__doc__
156156

157157
def __getattr__(self, name):
158-
s = ["'Client' object has no attribute '{}'".format(name)]
158+
s = ["'DockerClient' object has no attribute '{}'".format(name)]
159159
# If a user calls a method on APIClient, they
160160
if hasattr(APIClient, name):
161161
s.append("In Docker SDK for Python 2.0, this method is now on the "
@@ -164,4 +164,4 @@ def __getattr__(self, name):
164164
raise AttributeError(' '.join(s))
165165

166166

167-
from_env = Client.from_env
167+
from_env = DockerClient.from_env

docker/models/images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def pull(self, name, **kwargs):
238238
tag (str): The tag to pull
239239
insecure_registry (bool): Use an insecure registry
240240
auth_config (dict): Override the credentials that
241-
:py:meth:`~docker.client.Client.login` has set for
241+
:py:meth:`~docker.client.DockerClient.login` has set for
242242
this request. ``auth_config`` should contain the ``username``
243243
and ``password`` keys to be valid.
244244

docker/types/services.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44

55

66
class TaskTemplate(dict):
7+
"""
8+
Describe the task specification to be used when creating or updating a
9+
service.
10+
11+
Args:
12+
13+
* container_spec (dict): Container settings for containers started as part
14+
of this task. See the :py:class:`~docker.types.services.ContainerSpec`
15+
for details.
16+
* log_driver (dict): Log configuration for containers created as part of
17+
the service. See the :py:class:`~docker.types.services.DriverConfig`
18+
class for details.
19+
* resources (dict): Resource requirements which apply to each individual
20+
container created as part of the service. See the
21+
:py:class:`~docker.types.services.Resources` class for details.
22+
* restart_policy (dict): Specification for the restart policy which applies
23+
to containers created as part of this service. See the
24+
:py:class:`~docker.types.services.RestartPolicy` class for details.
25+
* placement (list): A list of constraints.
26+
"""
727
def __init__(self, container_spec, resources=None, restart_policy=None,
828
placement=None, log_driver=None):
929
self['ContainerSpec'] = container_spec
@@ -36,6 +56,25 @@ def placement(self):
3656

3757

3858
class ContainerSpec(dict):
59+
"""
60+
Describes the behavior of containers that are part of a task, and is used
61+
when declaring a :py:class:`~docker.types.services.TaskTemplate`.
62+
63+
Args:
64+
65+
* image (string): The image name to use for the container.
66+
* command (string or list): The command to be run in the image.
67+
* args (list): Arguments to the command.
68+
* env (dict): Environment variables.
69+
* dir (string): The working directory for commands to run in.
70+
* user (string): The user inside the container.
71+
* labels (dict): A map of labels to associate with the service.
72+
* mounts (list): A list of specifications for mounts to be added to
73+
containers created as part of the service. See the
74+
:py:class:`~docker.types.services.Mount` class for details.
75+
* stop_grace_period (int): Amount of time to wait for the container to
76+
terminate before forcefully killing it.
77+
"""
3978
def __init__(self, image, command=None, args=None, env=None, workdir=None,
4079
user=None, labels=None, mounts=None, stop_grace_period=None):
4180
from ..utils import split_command # FIXME: circular import
@@ -70,6 +109,28 @@ def __init__(self, image, command=None, args=None, env=None, workdir=None,
70109

71110

72111
class Mount(dict):
112+
"""
113+
Describes a mounted folder's configuration inside a container. A list of
114+
``Mount``s would be used as part of a
115+
:py:class:`~docker.types.services.ContainerSpec`.
116+
117+
Args:
118+
119+
* target (string): Container path.
120+
* source (string): Mount source (e.g. a volume name or a host path).
121+
* type (string): The mount type (``bind`` or ``volume``).
122+
Default: ``volume``.
123+
* read_only (bool): Whether the mount should be read-only.
124+
* propagation (string): A propagation mode with the value ``[r]private``,
125+
``[r]shared``, or ``[r]slave``. Only valid for the ``bind`` type.
126+
* no_copy (bool): False if the volume should be populated with the data
127+
from the target. Default: ``False``. Only valid for the ``volume`` type.
128+
* labels (dict): User-defined name and labels for the volume. Only valid
129+
for the ``volume`` type.
130+
* driver_config (dict): Volume driver configuration.
131+
See the :py:class:`~docker.types.services.DriverConfig` class for
132+
details. Only valid for the ``volume`` type.
133+
"""
73134
def __init__(self, target, source, type='volume', read_only=False,
74135
propagation=None, no_copy=False, labels=None,
75136
driver_config=None):
@@ -124,6 +185,17 @@ def parse_mount_string(cls, string):
124185

125186

126187
class Resources(dict):
188+
"""
189+
Configures resource allocation for containers when made part of a
190+
:py:class:`~docker.types.services.ContainerSpec`.
191+
192+
Args:
193+
194+
* cpu_limit (int): CPU limit in units of 10^9 CPU shares.
195+
* mem_limit (int): Memory limit in Bytes.
196+
* cpu_reservation (int): CPU reservation in units of 10^9 CPU shares.
197+
* mem_reservation (int): Memory reservation in Bytes.
198+
"""
127199
def __init__(self, cpu_limit=None, mem_limit=None, cpu_reservation=None,
128200
mem_reservation=None):
129201
limits = {}
@@ -144,6 +216,19 @@ def __init__(self, cpu_limit=None, mem_limit=None, cpu_reservation=None,
144216

145217

146218
class UpdateConfig(dict):
219+
"""
220+
221+
Used to specify the way container updates should be performed by a service.
222+
223+
Args:
224+
225+
* parallelism (int): Maximum number of tasks to be updated in one iteration
226+
(0 means unlimited parallelism). Default: 0.
227+
* delay (int): Amount of time between updates.
228+
* failure_action (string): Action to take if an updated task fails to run,
229+
or stops running during the update. Acceptable values are ``continue``
230+
and ``pause``. Default: ``continue``
231+
"""
147232
def __init__(self, parallelism=0, delay=None, failure_action='continue'):
148233
self['Parallelism'] = parallelism
149234
if delay is not None:
@@ -165,6 +250,19 @@ class RestartConditionTypesEnum(object):
165250

166251

167252
class RestartPolicy(dict):
253+
"""
254+
Used when creating a :py:class:`~docker.types.services.ContainerSpec`,
255+
dictates whether a container should restart after stopping or failing.
256+
257+
* condition (string): Condition for restart (``none``, ``on-failure``,
258+
or ``any``). Default: `none`.
259+
* delay (int): Delay between restart attempts. Default: 0
260+
* attempts (int): Maximum attempts to restart a given container before
261+
giving up. Default value is 0, which is ignored.
262+
* window (int): Time window used to evaluate the restart policy. Default
263+
value is 0, which is unbounded.
264+
"""
265+
168266
condition_types = RestartConditionTypesEnum
169267

170268
def __init__(self, condition=RestartConditionTypesEnum.NONE, delay=0,
@@ -181,13 +279,37 @@ def __init__(self, condition=RestartConditionTypesEnum.NONE, delay=0,
181279

182280

183281
class DriverConfig(dict):
282+
"""
283+
Indicates which driver to use, as well as its configuration. Can be used
284+
as ``log_driver`` in a :py:class:`~docker.types.services.ContainerSpec`,
285+
and for the `driver_config` in a volume
286+
:py:class:`~docker.types.services.Mount`.
287+
288+
Args:
289+
290+
* name (string): Name of the driver to use.
291+
* options (dict): Driver-specific options. Default: ``None``.
292+
"""
184293
def __init__(self, name, options=None):
185294
self['Name'] = name
186295
if options:
187296
self['Options'] = options
188297

189298

190299
class EndpointSpec(dict):
300+
"""
301+
Describes properties to access and load-balance a service.
302+
303+
Args:
304+
305+
* mode (string): The mode of resolution to use for internal load balancing
306+
between tasks (``'vip'`` or ``'dnsrr'``). Defaults to ``'vip'`` if not
307+
provided.
308+
* ports (dict): Exposed ports that this service is accessible on from the
309+
outside, in the form of ``{ target_port: published_port }`` or
310+
``{ target_port: (published_port, protocol) }``. Ports can only be
311+
provided if the ``vip`` resolution mode is used.
312+
"""
191313
def __init__(self, mode=None, ports=None):
192314
if ports:
193315
self['Ports'] = convert_service_ports(ports)

docker/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
714714
if not version:
715715
warnings.warn(
716716
'docker.utils.create_host_config() is deprecated. Please use '
717-
'Client.create_host_config() instead.'
717+
'APIClient.create_host_config() instead.'
718718
)
719719
version = constants.DEFAULT_DOCKER_API_VERSION
720720

docs/client.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Client
66
Creating a client
77
-----------------
88

9-
To communicate with the Docker daemon, you first need to instantiate a client. The easiest way to do that is by calling the function :py:func:`~docker.client.from_env`. It can also be configured manually by instantiating a :py:class:`~docker.client.Client` class.
9+
To communicate with the Docker daemon, you first need to instantiate a client. The easiest way to do that is by calling the function :py:func:`~docker.client.from_env`. It can also be configured manually by instantiating a :py:class:`~docker.client.DockerClient` class.
1010

1111
.. autofunction:: from_env()
1212

1313
Client reference
1414
----------------
1515

16-
.. autoclass:: Client()
16+
.. autoclass:: DockerClient()
1717

1818
.. autoattribute:: containers
1919
.. autoattribute:: images

0 commit comments

Comments
 (0)