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 (
@@ -28,6 +29,14 @@ def raise_version_error(param, min_version):
2829 if 'Order' in update_config :
2930 raise_version_error ('UpdateConfig.order' , '1.29' )
3031
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+
3140 if endpoint_spec is not None :
3241 if utils .version_lt (version , '1.32' ) and 'Ports' in endpoint_spec :
3342 if any (p .get ('PublishMode' ) for p in endpoint_spec ['Ports' ]):
@@ -105,7 +114,7 @@ class ServiceApiMixin(object):
105114 def create_service (
106115 self , task_template , name = None , labels = None , mode = None ,
107116 update_config = None , networks = None , endpoint_config = None ,
108- endpoint_spec = None
117+ endpoint_spec = None , rollback_config = None
109118 ):
110119 """
111120 Create a service.
@@ -120,6 +129,8 @@ def create_service(
120129 or global). Defaults to replicated.
121130 update_config (UpdateConfig): Specification for the update strategy
122131 of the service. Default: ``None``
132+ rollback_config (RollbackConfig): Specification for the rollback
133+ strategy of the service. Default: ``None``
123134 networks (:py:class:`list`): List of network names or IDs to attach
124135 the service to. Default: ``None``.
125136 endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -135,7 +146,8 @@ def create_service(
135146 """
136147
137148 _check_api_features (
138- self ._version , task_template , update_config , endpoint_spec
149+ self ._version , task_template , update_config , endpoint_spec ,
150+ rollback_config
139151 )
140152
141153 url = self ._url ('/services/create' )
@@ -166,6 +178,9 @@ def create_service(
166178 if update_config is not None :
167179 data ['UpdateConfig' ] = update_config
168180
181+ if rollback_config is not None :
182+ data ['RollbackConfig' ] = rollback_config
183+
169184 return self ._result (
170185 self ._post_json (url , data = data , headers = headers ), True
171186 )
@@ -342,7 +357,8 @@ def tasks(self, filters=None):
342357 def update_service (self , service , version , task_template = None , name = None ,
343358 labels = None , mode = None , update_config = None ,
344359 networks = None , endpoint_config = None ,
345- endpoint_spec = None , fetch_current_spec = False ):
360+ endpoint_spec = None , fetch_current_spec = False ,
361+ rollback_config = None ):
346362 """
347363 Update a service.
348364
@@ -360,6 +376,8 @@ def update_service(self, service, version, task_template=None, name=None,
360376 or global). Defaults to replicated.
361377 update_config (UpdateConfig): Specification for the update strategy
362378 of the service. Default: ``None``.
379+ rollback_config (RollbackConfig): Specification for the rollback
380+ strategy of the service. Default: ``None``
363381 networks (:py:class:`list`): List of network names or IDs to attach
364382 the service to. Default: ``None``.
365383 endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -376,7 +394,8 @@ def update_service(self, service, version, task_template=None, name=None,
376394 """
377395
378396 _check_api_features (
379- self ._version , task_template , update_config , endpoint_spec
397+ self ._version , task_template , update_config , endpoint_spec ,
398+ rollback_config
380399 )
381400
382401 if fetch_current_spec :
@@ -422,6 +441,11 @@ def update_service(self, service, version, task_template=None, name=None,
422441 else :
423442 data ['UpdateConfig' ] = current .get ('UpdateConfig' )
424443
444+ if rollback_config is not None :
445+ data ['RollbackConfig' ] = rollback_config
446+ else :
447+ data ['RollbackConfig' ] = current .get ('RollbackConfig' )
448+
425449 if networks is not None :
426450 converted_networks = utils .convert_service_networks (networks )
427451 if utils .version_lt (self ._version , '1.25' ):
0 commit comments