diff --git a/README.md b/README.md index a40d73e5..2253806d 100644 --- a/README.md +++ b/README.md @@ -112,8 +112,7 @@ dictionary whose key is the container's port and the value is a `[{'HostIp': '' all host interfaces. By leaving the `HostPort` blank, Docker will automatically assign a port. For example: `port_bindings={"2181/tcp": [{'HostIp': '' 'HostPort': ''}]}`. -`lxc_conf` allows to pass LXC configuration options using a dictionary in the form of Key Value pairs. -For example: `lxc_conf=[{"Key":"lxc.cgroup.cpu.shares","Value":"1"}, {"Key": ..., "Value": }]`. +`lxc_conf` allows to pass LXC configuration options using a dictionary. * `c.stop(container, timeout=10)` Stops a container. Similar to the `docker stop` command. diff --git a/docker/client.py b/docker/client.py index 149bad95..0ab5408d 100644 --- a/docker/client.py +++ b/docker/client.py @@ -448,6 +448,13 @@ class Client(requests.Session): def start(self, container, binds=None, port_bindings=None, lxc_conf=None): if isinstance(container, dict): container = container.get('Id') + + if isinstance(lxc_conf, dict): + formatted = [] + for k, v in six.iteritems(lxc_conf): + formatted.append({'Key': k, 'Value': str(v)}) + lxc_conf = formatted + start_config = { 'LxcConf': lxc_conf } diff --git a/tests/test.py b/tests/test.py index f06d76eb..e9941326 100644 --- a/tests/test.py +++ b/tests/test.py @@ -215,6 +215,42 @@ class DockerClientTest(unittest.TestCase): headers={'Content-Type': 'application/json'} ) + def test_start_container_with_lxc_conf(self): + try: + self.client.start( + fake_api.FAKE_CONTAINER_ID, + lxc_conf={'lxc.conf.k': 'lxc.conf.value'} + ) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + args = fake_request.call_args + self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/' + 'containers/3cc2351ab11b/start') + self.assertEqual( + json.loads(args[0][1]), + {"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]} + ) + self.assertEqual(args[1]['headers'], + {'Content-Type': 'application/json'}) + + def test_start_container_with_lxc_conf_compat(self): + try: + self.client.start( + fake_api.FAKE_CONTAINER_ID, + lxc_conf=[{'Key': 'lxc.conf.k', 'Value': 'lxc.conf.value'}] + ) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + args = fake_request.call_args + self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/' + 'containers/3cc2351ab11b/start') + self.assertEqual( + json.loads(args[0][1]), + {"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]} + ) + self.assertEqual(args[1]['headers'], + {'Content-Type': 'application/json'}) + def test_start_container_with_binds(self): try: mount_dest = '/mnt'