|
4 | 4 |
|
5 | 5 |
|
6 | 6 | def _check_api_features(version, task_template, update_config):
|
| 7 | + |
| 8 | + def raise_version_error(param, min_version): |
| 9 | + raise errors.InvalidVersion( |
| 10 | + '{} is not supported in API version < {}'.format( |
| 11 | + param, min_version |
| 12 | + ) |
| 13 | + ) |
| 14 | + |
7 | 15 | if update_config is not None:
|
8 | 16 | if utils.version_lt(version, '1.25'):
|
9 | 17 | if 'MaxFailureRatio' in update_config:
|
10 |
| - raise errors.InvalidVersion( |
11 |
| - 'UpdateConfig.max_failure_ratio is not supported in' |
12 |
| - ' API version < 1.25' |
13 |
| - ) |
| 18 | + raise_version_error('UpdateConfig.max_failure_ratio', '1.25') |
14 | 19 | if 'Monitor' in update_config:
|
15 |
| - raise errors.InvalidVersion( |
16 |
| - 'UpdateConfig.monitor is not supported in' |
17 |
| - ' API version < 1.25' |
18 |
| - ) |
| 20 | + raise_version_error('UpdateConfig.monitor', '1.25') |
19 | 21 |
|
20 | 22 | if task_template is not None:
|
21 | 23 | if 'ForceUpdate' in task_template and utils.version_lt(
|
22 | 24 | version, '1.25'):
|
23 |
| - raise errors.InvalidVersion( |
24 |
| - 'force_update is not supported in API version < 1.25' |
25 |
| - ) |
| 25 | + raise_version_error('force_update', '1.25') |
26 | 26 |
|
27 | 27 | if task_template.get('Placement'):
|
28 | 28 | if utils.version_lt(version, '1.30'):
|
29 | 29 | if task_template['Placement'].get('Platforms'):
|
30 |
| - raise errors.InvalidVersion( |
31 |
| - 'Placement.platforms is not supported in' |
32 |
| - ' API version < 1.30' |
33 |
| - ) |
34 |
| - |
| 30 | + raise_version_error('Placement.platforms', '1.30') |
35 | 31 | if utils.version_lt(version, '1.27'):
|
36 | 32 | if task_template['Placement'].get('Preferences'):
|
37 |
| - raise errors.InvalidVersion( |
38 |
| - 'Placement.preferences is not supported in' |
39 |
| - ' API version < 1.27' |
40 |
| - ) |
41 |
| - if task_template.get('ContainerSpec', {}).get('TTY'): |
| 33 | + raise_version_error('Placement.preferences', '1.27') |
| 34 | + |
| 35 | + if task_template.get('ContainerSpec'): |
| 36 | + container_spec = task_template.get('ContainerSpec') |
| 37 | + |
42 | 38 | if utils.version_lt(version, '1.25'):
|
43 |
| - raise errors.InvalidVersion( |
44 |
| - 'ContainerSpec.TTY is not supported in API version < 1.25' |
45 |
| - ) |
| 39 | + if container_spec.get('TTY'): |
| 40 | + raise_version_error('ContainerSpec.tty', '1.25') |
| 41 | + if container_spec.get('Hostname') is not None: |
| 42 | + raise_version_error('ContainerSpec.hostname', '1.25') |
| 43 | + if container_spec.get('Hosts') is not None: |
| 44 | + raise_version_error('ContainerSpec.hosts', '1.25') |
| 45 | + if container_spec.get('Groups') is not None: |
| 46 | + raise_version_error('ContainerSpec.groups', '1.25') |
| 47 | + if container_spec.get('DNSConfig') is not None: |
| 48 | + raise_version_error('ContainerSpec.dns_config', '1.25') |
| 49 | + if container_spec.get('Healthcheck') is not None: |
| 50 | + raise_version_error('ContainerSpec.healthcheck', '1.25') |
| 51 | + |
| 52 | + if utils.version_lt(version, '1.28'): |
| 53 | + if container_spec.get('ReadOnly') is not None: |
| 54 | + raise_version_error('ContainerSpec.dns_config', '1.28') |
| 55 | + if container_spec.get('StopSignal') is not None: |
| 56 | + raise_version_error('ContainerSpec.stop_signal', '1.28') |
| 57 | + |
| 58 | + if utils.version_lt(version, '1.30'): |
| 59 | + if container_spec.get('Configs') is not None: |
| 60 | + raise_version_error('ContainerSpec.configs', '1.30') |
| 61 | + if container_spec.get('Privileges') is not None: |
| 62 | + raise_version_error('ContainerSpec.privileges', '1.30') |
46 | 63 |
|
47 | 64 |
|
48 | 65 | class ServiceApiMixin(object):
|
|
0 commit comments