2
2
from ..types import ServiceMode
3
3
4
4
5
- def _check_api_features (version , task_template , update_config , endpoint_spec ):
5
+ def _check_api_features (version , task_template , update_config , endpoint_spec ,
6
+ rollback_config ):
6
7
7
8
def raise_version_error (param , min_version ):
8
9
raise errors .InvalidVersion (
@@ -18,10 +19,24 @@ def raise_version_error(param, min_version):
18
19
if 'Monitor' in update_config :
19
20
raise_version_error ('UpdateConfig.monitor' , '1.25' )
20
21
22
+ if utils .version_lt (version , '1.28' ):
23
+ if update_config .get ('FailureAction' ) == 'rollback' :
24
+ raise_version_error (
25
+ 'UpdateConfig.failure_action rollback' , '1.28'
26
+ )
27
+
21
28
if utils .version_lt (version , '1.29' ):
22
29
if 'Order' in update_config :
23
30
raise_version_error ('UpdateConfig.order' , '1.29' )
24
31
32
+ if rollback_config is not None :
33
+ if utils .version_lt (version , '1.28' ):
34
+ raise_version_error ('rollback_config' , '1.28' )
35
+
36
+ if utils .version_lt (version , '1.29' ):
37
+ if 'Order' in update_config :
38
+ raise_version_error ('RollbackConfig.order' , '1.29' )
39
+
25
40
if endpoint_spec is not None :
26
41
if utils .version_lt (version , '1.32' ) and 'Ports' in endpoint_spec :
27
42
if any (p .get ('PublishMode' ) for p in endpoint_spec ['Ports' ]):
@@ -99,7 +114,7 @@ class ServiceApiMixin(object):
99
114
def create_service (
100
115
self , task_template , name = None , labels = None , mode = None ,
101
116
update_config = None , networks = None , endpoint_config = None ,
102
- endpoint_spec = None
117
+ endpoint_spec = None , rollback_config = None
103
118
):
104
119
"""
105
120
Create a service.
@@ -114,6 +129,8 @@ def create_service(
114
129
or global). Defaults to replicated.
115
130
update_config (UpdateConfig): Specification for the update strategy
116
131
of the service. Default: ``None``
132
+ rollback_config (RollbackConfig): Specification for the rollback
133
+ strategy of the service. Default: ``None``
117
134
networks (:py:class:`list`): List of network names or IDs to attach
118
135
the service to. Default: ``None``.
119
136
endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -129,7 +146,8 @@ def create_service(
129
146
"""
130
147
131
148
_check_api_features (
132
- self ._version , task_template , update_config , endpoint_spec
149
+ self ._version , task_template , update_config , endpoint_spec ,
150
+ rollback_config
133
151
)
134
152
135
153
url = self ._url ('/services/create' )
@@ -160,6 +178,9 @@ def create_service(
160
178
if update_config is not None :
161
179
data ['UpdateConfig' ] = update_config
162
180
181
+ if rollback_config is not None :
182
+ data ['RollbackConfig' ] = rollback_config
183
+
163
184
return self ._result (
164
185
self ._post_json (url , data = data , headers = headers ), True
165
186
)
@@ -336,7 +357,8 @@ def tasks(self, filters=None):
336
357
def update_service (self , service , version , task_template = None , name = None ,
337
358
labels = None , mode = None , update_config = None ,
338
359
networks = None , endpoint_config = None ,
339
- endpoint_spec = None , fetch_current_spec = False ):
360
+ endpoint_spec = None , fetch_current_spec = False ,
361
+ rollback_config = None ):
340
362
"""
341
363
Update a service.
342
364
@@ -354,6 +376,8 @@ def update_service(self, service, version, task_template=None, name=None,
354
376
or global). Defaults to replicated.
355
377
update_config (UpdateConfig): Specification for the update strategy
356
378
of the service. Default: ``None``.
379
+ rollback_config (RollbackConfig): Specification for the rollback
380
+ strategy of the service. Default: ``None``
357
381
networks (:py:class:`list`): List of network names or IDs to attach
358
382
the service to. Default: ``None``.
359
383
endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -370,7 +394,8 @@ def update_service(self, service, version, task_template=None, name=None,
370
394
"""
371
395
372
396
_check_api_features (
373
- self ._version , task_template , update_config , endpoint_spec
397
+ self ._version , task_template , update_config , endpoint_spec ,
398
+ rollback_config
374
399
)
375
400
376
401
if fetch_current_spec :
@@ -416,6 +441,11 @@ def update_service(self, service, version, task_template=None, name=None,
416
441
else :
417
442
data ['UpdateConfig' ] = current .get ('UpdateConfig' )
418
443
444
+ if rollback_config is not None :
445
+ data ['RollbackConfig' ] = rollback_config
446
+ else :
447
+ data ['RollbackConfig' ] = current .get ('RollbackConfig' )
448
+
419
449
if networks is not None :
420
450
converted_networks = utils .convert_service_networks (networks )
421
451
if utils .version_lt (self ._version , '1.25' ):
0 commit comments