Repository: docker/docker-py

Issue:
No support for --cpu-rt-period and --cpu-rt-runtime in containers.run
System info:
docker==2.2.1
docker-pycreds==0.2.1
Python 2.7.5
Client:
 Version:      17.04.0-ce
 API version:  1.28
 Go version:   go1.7.5
 Git commit:   4845c56
 Built:        Wed Apr  5 18:55:10 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.04.0-ce
 API version:  1.28 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   4845c56
 Built:        Wed Apr  5 18:55:10 2017
 OS/Arch:      linux/amd64
 Experimental: false

Looks like these parameters just need to be added to run function.


Discussion:

Resolving patch:
diff --git a/docker/models/containers.py b/docker/models/containers.py
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -861,6 +861,8 @@ def prune(self, filters=None):
     'cpu_shares',
     'cpuset_cpus',
     'cpuset_mems',
+    'cpu_rt_period',
+    'cpu_rt_runtime',
     'device_read_bps',
     'device_read_iops',
     'device_write_bps',
diff --git a/docker/types/containers.py b/docker/types/containers.py
--- a/docker/types/containers.py
+++ b/docker/types/containers.py
@@ -120,7 +120,8 @@ def __init__(self, version, binds=None, port_bindings=None,
                  isolation=None, auto_remove=False, storage_opt=None,
                  init=None, init_path=None, volume_driver=None,
                  cpu_count=None, cpu_percent=None, nano_cpus=None,
-                 cpuset_mems=None, runtime=None):
+                 cpuset_mems=None, runtime=None, cpu_rt_period=None,
+                 cpu_rt_runtime=None):
 
         if mem_limit is not None:
             self['Memory'] = parse_bytes(mem_limit)
@@ -339,6 +340,26 @@ def __init__(self, version, binds=None, port_bindings=None,
                 )
             self['CpusetMems'] = cpuset_mems
 
+        if cpu_rt_period:
+            if version_lt(version, '1.25'):
+                raise host_config_version_error('cpu_rt_period', '1.25')
+
+            if not isinstance(cpu_rt_period, int):
+                raise host_config_type_error(
+                    'cpu_rt_period', cpu_rt_period, 'int'
+                )
+            self['CPURealtimePeriod'] = cpu_rt_period
+
+        if cpu_rt_runtime:
+            if version_lt(version, '1.25'):
+                raise host_config_version_error('cpu_rt_runtime', '1.25')
+
+            if not isinstance(cpu_rt_runtime, int):
+                raise host_config_type_error(
+                    'cpu_rt_runtime', cpu_rt_runtime, 'int'
+                )
+            self['CPURealtimeRuntime'] = cpu_rt_runtime
+
         if blkio_weight:
             if not isinstance(blkio_weight, int):
                 raise host_config_type_error(


Test patch:
diff --git a/tests/unit/dockertypes_test.py b/tests/unit/dockertypes_test.py
--- a/tests/unit/dockertypes_test.py
+++ b/tests/unit/dockertypes_test.py
@@ -206,6 +206,28 @@ def test_create_host_config_with_nano_cpus(self):
             InvalidVersion, lambda: create_host_config(
                 version='1.24', nano_cpus=1))
 
+    def test_create_host_config_with_cpu_rt_period_types(self):
+        with pytest.raises(TypeError):
+            create_host_config(version='1.25', cpu_rt_period='1000')
+
+    def test_create_host_config_with_cpu_rt_period(self):
+        config = create_host_config(version='1.25', cpu_rt_period=1000)
+        self.assertEqual(config.get('CPURealtimePeriod'), 1000)
+        self.assertRaises(
+            InvalidVersion, lambda: create_host_config(
+                version='1.24', cpu_rt_period=1000))
+
+    def test_ctrate_host_config_with_cpu_rt_runtime_types(self):
+        with pytest.raises(TypeError):
+            create_host_config(version='1.25', cpu_rt_runtime='1000')
+
+    def test_create_host_config_with_cpu_rt_runtime(self):
+        config = create_host_config(version='1.25', cpu_rt_runtime=1000)
+        self.assertEqual(config.get('CPURealtimeRuntime'), 1000)
+        self.assertRaises(
+            InvalidVersion, lambda: create_host_config(
+                version='1.24', cpu_rt_runtime=1000))
+
 
 class ContainerConfigTest(unittest.TestCase):
     def test_create_container_config_volume_driver_warning(self):