1
1
import warnings
2
2
from .. import auth , errors , utils
3
+ from ..types import ServiceMode
3
4
4
5
5
6
class ServiceApiMixin (object ):
@@ -18,8 +19,8 @@ def create_service(
18
19
name (string): User-defined name for the service. Optional.
19
20
labels (dict): A map of labels to associate with the service.
20
21
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.
23
24
update_config (UpdateConfig): Specification for the update strategy
24
25
of the service. Default: ``None``
25
26
networks (:py:class:`list`): List of network names or IDs to attach
@@ -49,6 +50,9 @@ def create_service(
49
50
raise errors .DockerException (
50
51
'Missing mandatory Image key in ContainerSpec'
51
52
)
53
+ if mode and not isinstance (mode , dict ):
54
+ mode = ServiceMode (mode )
55
+
52
56
registry , repo_name = auth .resolve_repository_name (image )
53
57
auth_header = auth .get_config_header (self , registry )
54
58
if auth_header :
@@ -191,8 +195,8 @@ def update_service(self, service, version, task_template=None, name=None,
191
195
name (string): New name for the service. Optional.
192
196
labels (dict): A map of labels to associate with the service.
193
197
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.
196
200
update_config (UpdateConfig): Specification for the update strategy
197
201
of the service. Default: ``None``.
198
202
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,
222
226
if labels is not None :
223
227
data ['Labels' ] = labels
224
228
if mode is not None :
229
+ if not isinstance (mode , dict ):
230
+ mode = ServiceMode (mode )
225
231
data ['Mode' ] = mode
226
232
if task_template is not None :
227
233
image = task_template .get ('ContainerSpec' , {}).get ('Image' , None )
0 commit comments