Kaydet (Commit) bd948be7 authored tarafından Sumit Sahrawat's avatar Sumit Sahrawat

Allow providing options when creating networks

Following the spec:

    http://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/#create-a-network

I have added an Options argument to create_network.

This opens up the possibility of creating isolated containers with no
internet access programmatically. We require such facilities in
https://github.com/jupyter/tmpnb/issues/187.
Signed-off-by: 's avatarSumit Sahrawat <sumit.sahrawat.apm13@iitbhu.ac.in>
üst 0f091747
......@@ -19,10 +19,14 @@ class NetworkApiMixin(object):
return self._result(res, json=True)
@minimum_version('1.21')
def create_network(self, name, driver=None):
def create_network(self, name, driver=None, options=None):
if options is not None and not isinstance(options, dict):
raise TypeError('options must be a dictionary')
data = {
'name': name,
'driver': driver,
'options': options
}
url = self._url("/networks/create")
res = self._post_json(url, data=data)
......
......@@ -70,11 +70,15 @@ class NetworkTest(DockerClientTest):
json.loads(post.call_args[1]['data']),
{"name": "foo"})
self.client.create_network('foo', 'bridge')
opts = {
'com.docker.network.bridge.enable_icc': False,
'com.docker.network.bridge.enable_ip_masquerade': False,
}
self.client.create_network('foo', 'bridge', opts)
self.assertEqual(
json.loads(post.call_args[1]['data']),
{"name": "foo", "driver": "bridge"})
{"name": "foo", "driver": "bridge", "options": opts})
@base.requires_api_version('1.21')
def test_remove_network(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment