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 (
@@ -28,6 +29,14 @@ def raise_version_error(param, min_version):
28
29
if 'Order' in update_config :
29
30
raise_version_error ('UpdateConfig.order' , '1.29' )
30
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
+
31
40
if endpoint_spec is not None :
32
41
if utils .version_lt (version , '1.32' ) and 'Ports' in endpoint_spec :
33
42
if any (p .get ('PublishMode' ) for p in endpoint_spec ['Ports' ]):
@@ -105,7 +114,7 @@ class ServiceApiMixin(object):
105
114
def create_service (
106
115
self , task_template , name = None , labels = None , mode = None ,
107
116
update_config = None , networks = None , endpoint_config = None ,
108
- endpoint_spec = None
117
+ endpoint_spec = None , rollback_config = None
109
118
):
110
119
"""
111
120
Create a service.
@@ -120,6 +129,8 @@ def create_service(
120
129
or global). Defaults to replicated.
121
130
update_config (UpdateConfig): Specification for the update strategy
122
131
of the service. Default: ``None``
132
+ rollback_config (RollbackConfig): Specification for the rollback
133
+ strategy of the service. Default: ``None``
123
134
networks (:py:class:`list`): List of network names or IDs to attach
124
135
the service to. Default: ``None``.
125
136
endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -135,7 +146,8 @@ def create_service(
135
146
"""
136
147
137
148
_check_api_features (
138
- self ._version , task_template , update_config , endpoint_spec
149
+ self ._version , task_template , update_config , endpoint_spec ,
150
+ rollback_config
139
151
)
140
152
141
153
url = self ._url ('/services/create' )
@@ -166,6 +178,9 @@ def create_service(
166
178
if update_config is not None :
167
179
data ['UpdateConfig' ] = update_config
168
180
181
+ if rollback_config is not None :
182
+ data ['RollbackConfig' ] = rollback_config
183
+
169
184
return self ._result (
170
185
self ._post_json (url , data = data , headers = headers ), True
171
186
)
@@ -342,7 +357,8 @@ def tasks(self, filters=None):
342
357
def update_service (self , service , version , task_template = None , name = None ,
343
358
labels = None , mode = None , update_config = None ,
344
359
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 ):
346
362
"""
347
363
Update a service.
348
364
@@ -360,6 +376,8 @@ def update_service(self, service, version, task_template=None, name=None,
360
376
or global). Defaults to replicated.
361
377
update_config (UpdateConfig): Specification for the update strategy
362
378
of the service. Default: ``None``.
379
+ rollback_config (RollbackConfig): Specification for the rollback
380
+ strategy of the service. Default: ``None``
363
381
networks (:py:class:`list`): List of network names or IDs to attach
364
382
the service to. Default: ``None``.
365
383
endpoint_spec (EndpointSpec): Properties that can be configured to
@@ -376,7 +394,8 @@ def update_service(self, service, version, task_template=None, name=None,
376
394
"""
377
395
378
396
_check_api_features (
379
- self ._version , task_template , update_config , endpoint_spec
397
+ self ._version , task_template , update_config , endpoint_spec ,
398
+ rollback_config
380
399
)
381
400
382
401
if fetch_current_spec :
@@ -422,6 +441,11 @@ def update_service(self, service, version, task_template=None, name=None,
422
441
else :
423
442
data ['UpdateConfig' ] = current .get ('UpdateConfig' )
424
443
444
+ if rollback_config is not None :
445
+ data ['RollbackConfig' ] = rollback_config
446
+ else :
447
+ data ['RollbackConfig' ] = current .get ('RollbackConfig' )
448
+
425
449
if networks is not None :
426
450
converted_networks = utils .convert_service_networks (networks )
427
451
if utils .version_lt (self ._version , '1.25' ):
0 commit comments