mirror of https://github.com/docker/docker-py.git
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: Sumit Sahrawat <sumit.sahrawat.apm13@iitbhu.ac.in>
This commit is contained in:
parent
0f091747ec
commit
bd948be7d9
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue