Repository: docker/docker-py

Issue:
CPU Affinity
Is there a way to use the new `cpuset` flag of the `run` command? Example:

```
docker run --rm --cpuset 0-1 busybox true
```

See: https://github.com/dotcloud/docker/issues/4587



Discussion:
Not yet, to my knowledge. As always patches are welcome =)


Resolving patch:
diff --git a/docker/client.py b/docker/client.py
--- a/docker/client.py
+++ b/docker/client.py
@@ -102,8 +102,8 @@ def _container_config(self, image, command, hostname=None, user=None,
                           mem_limit=0, ports=None, environment=None, dns=None,
                           volumes=None, volumes_from=None,
                           network_disabled=False, entrypoint=None,
-                          cpu_shares=None, working_dir=None, domainname=None,
-                          memswap_limit=0):
+                          cpu_shares=None, working_dir=None,
+                          domainname=None, memswap_limit=0, cpuset=None):
         if isinstance(command, six.string_types):
             command = shlex.split(str(command))
         if isinstance(environment, dict):
@@ -216,6 +216,7 @@ def _container_config(self, image, command, hostname=None, user=None,
             'NetworkDisabled': network_disabled,
             'Entrypoint': entrypoint,
             'CpuShares': cpu_shares,
+            'Cpuset': cpuset,
             'WorkingDir': working_dir,
             'MemorySwap': memswap_limit
         }
@@ -500,8 +501,8 @@ def create_container(self, image, command=None, hostname=None, user=None,
                          mem_limit=0, ports=None, environment=None, dns=None,
                          volumes=None, volumes_from=None,
                          network_disabled=False, name=None, entrypoint=None,
-                         cpu_shares=None, working_dir=None, domainname=None,
-                         memswap_limit=0):
+                         cpu_shares=None, working_dir=None,
+                         domainname=None, memswap_limit=0, cpuset=None):
 
         if isinstance(volumes, six.string_types):
             volumes = [volumes, ]
@@ -509,7 +510,8 @@ def create_container(self, image, command=None, hostname=None, user=None,
         config = self._container_config(
             image, command, hostname, user, detach, stdin_open, tty, mem_limit,
             ports, environment, dns, volumes, volumes_from, network_disabled,
-            entrypoint, cpu_shares, working_dir, domainname, memswap_limit
+            entrypoint, cpu_shares, working_dir, domainname,
+            memswap_limit, cpuset
         )
         return self.create_container_from_config(config, name)
 


Test patch:
diff --git a/tests/test.py b/tests/test.py
--- a/tests/test.py
+++ b/tests/test.py
@@ -348,6 +348,30 @@ def test_create_container_with_cpu_shares(self):
         self.assertEqual(args[1]['headers'],
                          {'Content-Type': 'application/json'})
 
+    def test_create_container_with_cpuset(self):
+        try:
+            self.client.create_container('busybox', 'ls',
+                                         cpuset='0,1')
+        except Exception as e:
+            self.fail('Command should not raise exception: {0}'.format(e))
+
+        args = fake_request.call_args
+        self.assertEqual(args[0][0],
+                         url_prefix + 'containers/create')
+        self.assertEqual(json.loads(args[1]['data']),
+                         json.loads('''
+                            {"Tty": false, "Image": "busybox",
+                             "Cmd": ["ls"], "AttachStdin": false,
+                             "Memory": 0,
+                             "AttachStderr": true,
+                             "AttachStdout": true, "OpenStdin": false,
+                             "StdinOnce": false,
+                             "NetworkDisabled": false,
+                             "Cpuset": "0,1",
+                             "MemorySwap": 0}'''))
+        self.assertEqual(args[1]['headers'],
+                         {'Content-Type': 'application/json'})
+
     def test_create_container_with_working_dir(self):
         try:
             self.client.create_container('busybox', 'ls',