11import warnings
22from .. import auth , errors , utils
3+ from ..types import ServiceMode
34
45
56class ServiceApiMixin (object ):
@@ -18,8 +19,8 @@ def create_service(
1819 name (string): User-defined name for the service. Optional.
1920 labels (dict): A map of labels to associate with the service.
2021 Optional.
21- mode (string ): Scheduling mode for the service (`` replicated`` or
22- `` global`` ). Defaults to `` replicated`` .
22+ mode (ServiceMode ): Scheduling mode for the service (replicated
23+ or global). Defaults to replicated.
2324 update_config (UpdateConfig): Specification for the update strategy
2425 of the service. Default: ``None``
2526 networks (:py:class:`list`): List of network names or IDs to attach
@@ -49,6 +50,9 @@ def create_service(
4950 raise errors .DockerException (
5051 'Missing mandatory Image key in ContainerSpec'
5152 )
53+ if mode and not isinstance (mode , dict ):
54+ mode = ServiceMode (mode )
55+
5256 registry , repo_name = auth .resolve_repository_name (image )
5357 auth_header = auth .get_config_header (self , registry )
5458 if auth_header :
@@ -191,8 +195,8 @@ def update_service(self, service, version, task_template=None, name=None,
191195 name (string): New name for the service. Optional.
192196 labels (dict): A map of labels to associate with the service.
193197 Optional.
194- mode (string ): Scheduling mode for the service (`` replicated`` or
195- `` global`` ). Defaults to `` replicated`` .
198+ mode (ServiceMode ): Scheduling mode for the service (replicated
199+ or global). Defaults to replicated.
196200 update_config (UpdateConfig): Specification for the update strategy
197201 of the service. Default: ``None``.
198202 networks (:py:class:`list`): List of network names or IDs to attach
@@ -222,6 +226,8 @@ def update_service(self, service, version, task_template=None, name=None,
222226 if labels is not None :
223227 data ['Labels' ] = labels
224228 if mode is not None :
229+ if not isinstance (mode , dict ):
230+ mode = ServiceMode (mode )
225231 data ['Mode' ] = mode
226232 if task_template is not None :
227233 image = task_template .get ('ContainerSpec' , {}).get ('Image' , None )
0 commit comments