1
1
import copy
2
2
from docker .errors import create_unexpected_kwargs_error , InvalidArgument
3
- from docker .types import TaskTemplate , ContainerSpec , ServiceMode
3
+ from docker .types import TaskTemplate , ContainerSpec , Placement , ServiceMode
4
4
from .resource import Model , Collection
5
5
6
6
@@ -153,6 +153,9 @@ def create(self, image, command=None, **kwargs):
153
153
command (list of str or str): Command to run.
154
154
args (list of str): Arguments to the command.
155
155
constraints (list of str): Placement constraints.
156
+ preferences (list of str): Placement preferences.
157
+ platforms (list of tuple): A list of platforms constraints
158
+ expressed as ``(arch, os)`` tuples
156
159
container_labels (dict): Labels to apply to the container.
157
160
endpoint_spec (EndpointSpec): Properties that can be configured to
158
161
access and load balance a service. Default: ``None``.
@@ -302,6 +305,12 @@ def list(self, **kwargs):
302
305
'endpoint_spec' ,
303
306
]
304
307
308
+ PLACEMENT_KWARGS = [
309
+ 'constraints' ,
310
+ 'preferences' ,
311
+ 'platforms' ,
312
+ ]
313
+
305
314
306
315
def _get_create_service_kwargs (func_name , kwargs ):
307
316
# Copy over things which can be copied directly
@@ -322,13 +331,10 @@ def _get_create_service_kwargs(func_name, kwargs):
322
331
container_spec_kwargs ['labels' ] = kwargs .pop ('container_labels' )
323
332
324
333
placement = {}
325
-
326
- if 'constraints' in kwargs :
327
- placement ['Constraints' ] = kwargs .pop ('constraints' )
328
-
329
- if 'preferences' in kwargs :
330
- placement ['Preferences' ] = kwargs .pop ('preferences' )
331
-
334
+ for key in copy .copy (kwargs ):
335
+ if key in PLACEMENT_KWARGS :
336
+ placement [key ] = kwargs .pop (key )
337
+ placement = Placement (** placement )
332
338
task_template_kwargs ['placement' ] = placement
333
339
334
340
if 'log_driver' in kwargs :
0 commit comments