mirror of https://github.com/docker/docker-py.git
Fixed lxc_conf param in Client.start to accept dict configurations. Fixes #84
This commit is contained in:
parent
4b8938ae24
commit
f6159b5593
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue