11import copy
22from 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
44from .resource import Model , Collection
55
66
@@ -153,6 +153,9 @@ def create(self, image, command=None, **kwargs):
153153 command (list of str or str): Command to run.
154154 args (list of str): Arguments to the command.
155155 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
156159 container_labels (dict): Labels to apply to the container.
157160 endpoint_spec (EndpointSpec): Properties that can be configured to
158161 access and load balance a service. Default: ``None``.
@@ -302,6 +305,12 @@ def list(self, **kwargs):
302305 'endpoint_spec' ,
303306]
304307
308+ PLACEMENT_KWARGS = [
309+ 'constraints' ,
310+ 'preferences' ,
311+ 'platforms' ,
312+ ]
313+
305314
306315def _get_create_service_kwargs (func_name , kwargs ):
307316 # Copy over things which can be copied directly
@@ -322,13 +331,10 @@ def _get_create_service_kwargs(func_name, kwargs):
322331 container_spec_kwargs ['labels' ] = kwargs .pop ('container_labels' )
323332
324333 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 )
332338 task_template_kwargs ['placement' ] = placement
333339
334340 if 'log_driver' in kwargs :
0 commit comments