Skip to content

Commit c2f83d5

Browse files
committed
cpus renamed to nano_cpus. Type and scale of nano_cpus are changed. Comments for new parameters are changed.
Signed-off-by: Alexey Rokhin <[email protected]>
1 parent 3f7d622 commit c2f83d5

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

docker/models/containers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,13 @@ def run(self, image, command=None, stdout=True, stderr=False,
456456
cap_add (list of str): Add kernel capabilities. For example,
457457
``["SYS_ADMIN", "MKNOD"]``.
458458
cap_drop (list of str): Drop kernel capabilities.
459-
cpu_count (int): CPU count (Windows only).
460-
cpu_percent (int): CPU percent (Windows only).
459+
cpu_count (int): Number of usable CPUs (Windows only).
460+
cpu_percent (int): Usable percentage of the available CPUs
461+
(Windows only).
461462
cpu_period (int): The length of a CPU period in microseconds.
462463
cpu_quota (int): Microseconds of CPU time that the container can
463464
get in a CPU period.
464465
cpu_shares (int): CPU shares (relative weight).
465-
cpus (float): Number of CPUs.
466466
cpuset_cpus (str): CPUs in which to allow execution (``0-3``,
467467
``0,1``).
468468
detach (bool): Run container in the background and return a
@@ -526,6 +526,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
526526
networks (:py:class:`list`): A list of network names to connect
527527
this container to.
528528
name (str): The name for this container.
529+
nano_cpus (int): CPU quota in units of 10-9 CPUs.
529530
network_disabled (bool): Disable networking.
530531
network_mode (str): One of:
531532
@@ -809,7 +810,6 @@ def prune(self, filters=None):
809810
'cpu_period',
810811
'cpu_quota',
811812
'cpu_shares',
812-
'cpus',
813813
'cpuset_cpus',
814814
'device_read_bps',
815815
'device_read_iops',
@@ -833,6 +833,7 @@ def prune(self, filters=None):
833833
'mem_reservation',
834834
'mem_swappiness',
835835
'memswap_limit',
836+
'nano_cpus',
836837
'network_mode',
837838
'oom_kill_disable',
838839
'oom_score_adj',

docker/types/containers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __init__(self, version, binds=None, port_bindings=None,
119119
cpuset_cpus=None, userns_mode=None, pids_limit=None,
120120
isolation=None, auto_remove=False, storage_opt=None,
121121
init=None, init_path=None, volume_driver=None,
122-
cpu_count=None, cpu_percent=None, cpus=None):
122+
cpu_count=None, cpu_percent=None, nano_cpus=None):
123123

124124
if mem_limit is not None:
125125
self['Memory'] = parse_bytes(mem_limit)
@@ -450,13 +450,13 @@ def __init__(self, version, binds=None, port_bindings=None,
450450

451451
self['CpuPercent'] = cpu_percent
452452

453-
if cpus:
454-
if not isinstance(cpus, (float, int)):
455-
raise host_config_type_error('cpus', cpus, 'float')
453+
if nano_cpus:
454+
if not isinstance(nano_cpus, int):
455+
raise host_config_type_error('nano_cpus', nano_cpus, 'int')
456456
if version_lt(version, '1.25'):
457-
raise host_config_version_error('cpus', '1.25')
457+
raise host_config_version_error('nano_cpus', '1.25')
458458

459-
self['NanoCpus'] = int(1000000000 * cpus)
459+
self['NanoCpus'] = nano_cpus
460460

461461

462462
def host_config_type_error(param, param_value, expected):

tests/unit/api_container_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def test_create_container_with_host_config_cpus(self):
11581158
'busybox', 'ls', host_config=self.client.create_host_config(
11591159
cpu_count=1,
11601160
cpu_percent=20,
1161-
cpus=10
1161+
nano_cpus=1000
11621162
)
11631163
)
11641164

@@ -1177,10 +1177,12 @@ def test_create_container_with_host_config_cpus(self):
11771177
"HostConfig": {
11781178
"CpuCount": 1,
11791179
"CpuPercent": 20,
1180-
"NanoCpus": 10000000000,
1180+
"NanoCpus": 1000,
11811181
"NetworkMode": "default"
11821182
}}'''))
1183-
self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'})
1183+
self.assertEqual(
1184+
args[1]['headers'], {'Content-Type': 'application/json'}
1185+
)
11841186

11851187

11861188
class ContainerTest(BaseAPIClientTest):

tests/unit/dockertypes_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_create_host_config_with_volume_driver(self):
172172

173173
config = create_host_config(version='1.21', volume_driver='local')
174174
assert config.get('VolumeDriver') == 'local'
175-
175+
176176
def test_create_host_config_invalid_cpu_count_types(self):
177177
with pytest.raises(TypeError):
178178
create_host_config(version='1.25', cpu_count='1')
@@ -195,16 +195,16 @@ def test_create_host_config_with_cpu_percent(self):
195195
InvalidVersion, lambda: create_host_config(
196196
version='1.24', cpu_percent=10))
197197

198-
def test_create_host_config_invalid_cpus_types(self):
198+
def test_create_host_config_invalid_nano_cpus_types(self):
199199
with pytest.raises(TypeError):
200-
create_host_config(version='1.25', cpus='0')
200+
create_host_config(version='1.25', nano_cpus='0')
201201

202-
def test_create_host_config_with_cpus(self):
203-
config = create_host_config(version='1.25', cpus=100)
204-
self.assertEqual(config.get('NanoCpus'), 100000000000)
202+
def test_create_host_config_with_nano_cpus(self):
203+
config = create_host_config(version='1.25', nano_cpus=1000)
204+
self.assertEqual(config.get('NanoCpus'), 1000)
205205
self.assertRaises(
206206
InvalidVersion, lambda: create_host_config(
207-
version='1.24', cpus=1))
207+
version='1.24', nano_cpus=1))
208208

209209

210210
class ContainerConfigTest(unittest.TestCase):

0 commit comments

Comments
 (0)