4
4
5
5
6
6
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
+ """
7
27
def __init__ (self , container_spec , resources = None , restart_policy = None ,
8
28
placement = None , log_driver = None ):
9
29
self ['ContainerSpec' ] = container_spec
@@ -36,6 +56,25 @@ def placement(self):
36
56
37
57
38
58
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
+ """
39
78
def __init__ (self , image , command = None , args = None , env = None , workdir = None ,
40
79
user = None , labels = None , mounts = None , stop_grace_period = None ):
41
80
from ..utils import split_command # FIXME: circular import
@@ -70,6 +109,28 @@ def __init__(self, image, command=None, args=None, env=None, workdir=None,
70
109
71
110
72
111
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
+ """
73
134
def __init__ (self , target , source , type = 'volume' , read_only = False ,
74
135
propagation = None , no_copy = False , labels = None ,
75
136
driver_config = None ):
@@ -124,6 +185,17 @@ def parse_mount_string(cls, string):
124
185
125
186
126
187
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
+ """
127
199
def __init__ (self , cpu_limit = None , mem_limit = None , cpu_reservation = None ,
128
200
mem_reservation = None ):
129
201
limits = {}
@@ -144,6 +216,19 @@ def __init__(self, cpu_limit=None, mem_limit=None, cpu_reservation=None,
144
216
145
217
146
218
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
+ """
147
232
def __init__ (self , parallelism = 0 , delay = None , failure_action = 'continue' ):
148
233
self ['Parallelism' ] = parallelism
149
234
if delay is not None :
@@ -165,6 +250,19 @@ class RestartConditionTypesEnum(object):
165
250
166
251
167
252
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
+
168
266
condition_types = RestartConditionTypesEnum
169
267
170
268
def __init__ (self , condition = RestartConditionTypesEnum .NONE , delay = 0 ,
@@ -181,13 +279,37 @@ def __init__(self, condition=RestartConditionTypesEnum.NONE, delay=0,
181
279
182
280
183
281
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
+ """
184
293
def __init__ (self , name , options = None ):
185
294
self ['Name' ] = name
186
295
if options :
187
296
self ['Options' ] = options
188
297
189
298
190
299
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
+ """
191
313
def __init__ (self , mode = None , ports = None ):
192
314
if ports :
193
315
self ['Ports' ] = convert_service_ports (ports )
0 commit comments