22from ..types import ServiceMode
33
44
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 ):
67
78 def raise_version_error (param , min_version ):
89 raise errors .InvalidVersion (
@@ -18,10 +19,24 @@ def raise_version_error(param, min_version):
1819 if 'Monitor' in update_config :
1920 raise_version_error ('UpdateConfig.monitor' , '1.25' )
2021
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+
2128 if utils .version_lt (version , '1.29' ):
2229 if 'Order' in update_config :
2330 raise_version_error ('UpdateConfig.order' , '1.29' )
2431
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+
2540 if endpoint_spec is not None :
2641 if utils .version_lt (version , '1.32' ) and 'Ports' in endpoint_spec :
2742 if any (p .get ('PublishMode' ) for p in endpoint_spec ['Ports' ]):
@@ -99,7 +114,7 @@ class ServiceApiMixin(object):
99114 def create_service (
100115 self , task_template , name = None , labels = None , mode = None ,
101116 update_config = None , networks = None , endpoint_config = None ,
102- endpoint_spec = None
117+ endpoint_spec = None , rollback_config = None
103118 ):
104119 """
105120 Create a service.
@@ -114,6 +129,8 @@ def create_service(
114129 or global). Defaults to replicated.
115130 update_config (UpdateConfig): Specification for the update strategy
116131 of the service. Default: ``None``
132+ rollback_config (RollbackConfig): Specification for the rollback
133+ strategy of the service. Default: ``None``
117134 networks (:py:class:`list`): List of network names or IDs to attach
118135 the service to. Default: ``None``.
119136 endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -129,7 +146,8 @@ def create_service(
129146 """
130147
131148 _check_api_features (
132- self ._version , task_template , update_config , endpoint_spec
149+ self ._version , task_template , update_config , endpoint_spec ,
150+ rollback_config
133151 )
134152
135153 url = self ._url ('/services/create' )
@@ -160,6 +178,9 @@ def create_service(
160178 if update_config is not None :
161179 data ['UpdateConfig' ] = update_config
162180
181+ if rollback_config is not None :
182+ data ['RollbackConfig' ] = rollback_config
183+
163184 return self ._result (
164185 self ._post_json (url , data = data , headers = headers ), True
165186 )
@@ -336,7 +357,8 @@ def tasks(self, filters=None):
336357 def update_service (self , service , version , task_template = None , name = None ,
337358 labels = None , mode = None , update_config = None ,
338359 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 ):
340362 """
341363 Update a service.
342364
@@ -354,6 +376,8 @@ def update_service(self, service, version, task_template=None, name=None,
354376 or global). Defaults to replicated.
355377 update_config (UpdateConfig): Specification for the update strategy
356378 of the service. Default: ``None``.
379+ rollback_config (RollbackConfig): Specification for the rollback
380+ strategy of the service. Default: ``None``
357381 networks (:py:class:`list`): List of network names or IDs to attach
358382 the service to. Default: ``None``.
359383 endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -370,7 +394,8 @@ def update_service(self, service, version, task_template=None, name=None,
370394 """
371395
372396 _check_api_features (
373- self ._version , task_template , update_config , endpoint_spec
397+ self ._version , task_template , update_config , endpoint_spec ,
398+ rollback_config
374399 )
375400
376401 if fetch_current_spec :
@@ -416,6 +441,11 @@ def update_service(self, service, version, task_template=None, name=None,
416441 else :
417442 data ['UpdateConfig' ] = current .get ('UpdateConfig' )
418443
444+ if rollback_config is not None :
445+ data ['RollbackConfig' ] = rollback_config
446+ else :
447+ data ['RollbackConfig' ] = current .get ('RollbackConfig' )
448+
419449 if networks is not None :
420450 converted_networks = utils .convert_service_networks (networks )
421451 if utils .version_lt (self ._version , '1.25' ):
0 commit comments