summaryrefslogtreecommitdiff
path: root/docker/api/service.py
diff options
context:
space:
mode:
Diffstat (limited to 'docker/api/service.py')
-rw-r--r--docker/api/service.py69
1 files changed, 41 insertions, 28 deletions
diff --git a/docker/api/service.py b/docker/api/service.py
index 4972c16..aea93cb 100644
--- a/docker/api/service.py
+++ b/docker/api/service.py
@@ -3,6 +3,43 @@ from .. import auth, errors, utils
from ..types import ServiceMode
+def _check_api_features(version, task_template, update_config):
+ if update_config is not None:
+ if utils.version_lt(version, '1.25'):
+ if 'MaxFailureRatio' in update_config:
+ raise errors.InvalidVersion(
+ 'UpdateConfig.max_failure_ratio is not supported in'
+ ' API version < 1.25'
+ )
+ if 'Monitor' in update_config:
+ raise errors.InvalidVersion(
+ 'UpdateConfig.monitor is not supported in'
+ ' API version < 1.25'
+ )
+
+ if task_template is not None:
+ if 'ForceUpdate' in task_template and utils.version_lt(
+ version, '1.25'):
+ raise errors.InvalidVersion(
+ 'force_update is not supported in API version < 1.25'
+ )
+
+ if task_template.get('Placement'):
+ if utils.version_lt(version, '1.30'):
+ if task_template['Placement'].get('Platforms'):
+ raise errors.InvalidVersion(
+ 'Placement.platforms is not supported in'
+ ' API version < 1.30'
+ )
+
+ if utils.version_lt(version, '1.27'):
+ if task_template['Placement'].get('Preferences'):
+ raise errors.InvalidVersion(
+ 'Placement.preferences is not supported in'
+ ' API version < 1.27'
+ )
+
+
class ServiceApiMixin(object):
@utils.minimum_version('1.24')
def create_service(
@@ -43,6 +80,8 @@ class ServiceApiMixin(object):
)
endpoint_spec = endpoint_config
+ _check_api_features(self._version, task_template, update_config)
+
url = self._url('/services/create')
headers = {}
image = task_template.get('ContainerSpec', {}).get('Image', None)
@@ -67,17 +106,6 @@ class ServiceApiMixin(object):
}
if update_config is not None:
- if utils.version_lt(self._version, '1.25'):
- if 'MaxFailureRatio' in update_config:
- raise errors.InvalidVersion(
- 'UpdateConfig.max_failure_ratio is not supported in'
- ' API version < 1.25'
- )
- if 'Monitor' in update_config:
- raise errors.InvalidVersion(
- 'UpdateConfig.monitor is not supported in'
- ' API version < 1.25'
- )
data['UpdateConfig'] = update_config
return self._result(
@@ -282,6 +310,8 @@ class ServiceApiMixin(object):
)
endpoint_spec = endpoint_config
+ _check_api_features(self._version, task_template, update_config)
+
url = self._url('/services/{0}/update', service)
data = {}
headers = {}
@@ -294,12 +324,6 @@ class ServiceApiMixin(object):
mode = ServiceMode(mode)
data['Mode'] = mode
if task_template is not None:
- if 'ForceUpdate' in task_template and utils.version_lt(
- self._version, '1.25'):
- raise errors.InvalidVersion(
- 'force_update is not supported in API version < 1.25'
- )
-
image = task_template.get('ContainerSpec', {}).get('Image', None)
if image is not None:
registry, repo_name = auth.resolve_repository_name(image)
@@ -308,17 +332,6 @@ class ServiceApiMixin(object):
headers['X-Registry-Auth'] = auth_header
data['TaskTemplate'] = task_template
if update_config is not None:
- if utils.version_lt(self._version, '1.25'):
- if 'MaxFailureRatio' in update_config:
- raise errors.InvalidVersion(
- 'UpdateConfig.max_failure_ratio is not supported in'
- ' API version < 1.25'
- )
- if 'Monitor' in update_config:
- raise errors.InvalidVersion(
- 'UpdateConfig.monitor is not supported in'
- ' API version < 1.25'
- )
data['UpdateConfig'] = update_config
if networks is not None: