summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-09-15 14:29:46 -0700
committerJoffrey F <joffrey@docker.com>2015-09-24 10:08:02 -0700
commit3c5185c199a0ac52c58eeca5ef9e2133e0f4803e (patch)
treea464861a0fc2c684b3730a347e80d72997075707
parentd89b2a01f05ab1be1a9e549f5db6b71ec41cf0c4 (diff)
downloaddocker-py-cpu_cfs_opts_support.tar.gz
Check API version when using cpu_period and cpu_quotacpu_cfs_opts_support
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/utils/utils.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index bbea8e7..36edf8d 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -519,7 +519,7 @@ def create_host_config(
host_config['Devices'] = parse_devices(devices)
if group_add:
- if compare_version(version, '1.20') < 0:
+ if version_lt(version, '1.20'):
raise errors.InvalidVersion(
'group_add param not supported for API version < 1.20'
)
@@ -602,20 +602,28 @@ def create_host_config(
log_config = LogConfig(**log_config)
host_config['LogConfig'] = log_config
- if cpu_quota and not isinstance(cpu_quota, int):
- raise TypeError(
- 'Invalid type for cpu_quota param: expected int but'
- ' found {0}'.format(type(cpu_quota))
- )
- elif cpu_quota:
+ if cpu_quota:
+ if not isinstance(cpu_quota, int):
+ raise TypeError(
+ 'Invalid type for cpu_quota param: expected int but'
+ ' found {0}'.format(type(cpu_quota))
+ )
+ if version_lt(version, '1.19'):
+ raise errors.InvalidVersion(
+ 'cpu_quota param not supported for API version < 1.19'
+ )
host_config['CpuQuota'] = cpu_quota
- if cpu_period and not isinstance(cpu_period, int):
- raise TypeError(
- 'Invalid type for cpu_period param: expected int but'
- ' found {0}'.format(type(cpu_period))
- )
- elif cpu_period:
+ if cpu_period:
+ if not isinstance(cpu_period, int):
+ raise TypeError(
+ 'Invalid type for cpu_period param: expected int but'
+ ' found {0}'.format(type(cpu_period))
+ )
+ if version_lt(version, '1.19'):
+ raise errors.InvalidVersion(
+ 'cpu_period param not supported for API version < 1.19'
+ )
host_config['CpuPeriod'] = cpu_period
return host_config