Skip to content

Commit b9ca875

Browse files
author
Dan Liew
committed
Add missing support for CpusetMems parameter to HostConfig.
Signed-off-by: Dan Liew <[email protected]>
1 parent 72b9b72 commit b9ca875

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

docker/api/container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ def create_host_config(self, *args, **kwargs):
479479
cpu_shares (int): CPU shares (relative weight).
480480
cpuset_cpus (str): CPUs in which to allow execution (``0-3``,
481481
``0,1``).
482+
cpuset_mems (str): Memory nodes (MEMs) in which to allow execution
483+
(``0-3``, ``0,1``). Only effective on NUMA systems.
482484
device_read_bps: Limit read rate (bytes per second) from a device
483485
in the form of: `[{"Path": "device_path", "Rate": rate}]`
484486
device_read_iops: Limit read rate (IO per second) from a device.

docker/models/containers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ def run(self, image, command=None, stdout=True, stderr=False,
483483
cpu_shares (int): CPU shares (relative weight).
484484
cpuset_cpus (str): CPUs in which to allow execution (``0-3``,
485485
``0,1``).
486+
cpuset_mems (str): Memory nodes (MEMs) in which to allow execution
487+
(``0-3``, ``0,1``). Only effective on NUMA systems.
486488
detach (bool): Run container in the background and return a
487489
:py:class:`Container` object.
488490
device_read_bps: Limit read rate (bytes per second) from a device
@@ -829,6 +831,7 @@ def prune(self, filters=None):
829831
'cpu_quota',
830832
'cpu_shares',
831833
'cpuset_cpus',
834+
'cpuset_mems',
832835
'device_read_bps',
833836
'device_read_iops',
834837
'device_write_bps',

docker/types/containers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ 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, nano_cpus=None):
122+
cpu_count=None, cpu_percent=None, nano_cpus=None,
123+
cpuset_mems=None):
123124

124125
if mem_limit is not None:
125126
self['Memory'] = parse_bytes(mem_limit)
@@ -328,6 +329,16 @@ def __init__(self, version, binds=None, port_bindings=None,
328329

329330
self['CpuSetCpus'] = cpuset_cpus
330331

332+
if cpuset_mems:
333+
if version_lt(version, '1.19'):
334+
raise host_config_version_error('cpuset_mems', '1.19')
335+
336+
if not isinstance(cpuset_mems, str):
337+
raise host_config_type_error(
338+
'cpuset_mems', cpuset_mems, 'str'
339+
)
340+
self['CpusetMems'] = cpuset_mems
341+
331342
if blkio_weight:
332343
if not isinstance(blkio_weight, int):
333344
raise host_config_type_error(

tests/unit/api_container_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,33 @@ def test_create_container_with_host_config_cpuset(self):
338338
self.assertEqual(args[1]['headers'],
339339
{'Content-Type': 'application/json'})
340340

341+
@requires_api_version('1.19')
342+
def test_create_container_with_host_config_cpuset_mems(self):
343+
self.client.create_container(
344+
'busybox', 'ls', host_config=self.client.create_host_config(
345+
cpuset_mems='0'
346+
)
347+
)
348+
349+
args = fake_request.call_args
350+
self.assertEqual(args[0][1],
351+
url_prefix + 'containers/create')
352+
353+
self.assertEqual(json.loads(args[1]['data']),
354+
json.loads('''
355+
{"Tty": false, "Image": "busybox",
356+
"Cmd": ["ls"], "AttachStdin": false,
357+
"AttachStderr": true,
358+
"AttachStdout": true, "OpenStdin": false,
359+
"StdinOnce": false,
360+
"NetworkDisabled": false,
361+
"HostConfig": {
362+
"CpusetMems": "0",
363+
"NetworkMode": "default"
364+
}}'''))
365+
self.assertEqual(args[1]['headers'],
366+
{'Content-Type': 'application/json'})
367+
341368
def test_create_container_with_cgroup_parent(self):
342369
self.client.create_container(
343370
'busybox', 'ls', host_config=self.client.create_host_config(

0 commit comments

Comments
 (0)