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)
|
return self._result(res, json=True)
|
||||||
|
|
||||||
@minimum_version('1.21')
|
@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 = {
|
data = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'driver': driver,
|
'driver': driver,
|
||||||
|
'options': options
|
||||||
}
|
}
|
||||||
url = self._url("/networks/create")
|
url = self._url("/networks/create")
|
||||||
res = self._post_json(url, data=data)
|
res = self._post_json(url, data=data)
|
||||||
|
|
|
@ -70,11 +70,15 @@ class NetworkTest(DockerClientTest):
|
||||||
json.loads(post.call_args[1]['data']),
|
json.loads(post.call_args[1]['data']),
|
||||||
{"name": "foo"})
|
{"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(
|
self.assertEqual(
|
||||||
json.loads(post.call_args[1]['data']),
|
json.loads(post.call_args[1]['data']),
|
||||||
{"name": "foo", "driver": "bridge"})
|
{"name": "foo", "driver": "bridge", "options": opts})
|
||||||
|
|
||||||
@base.requires_api_version('1.21')
|
@base.requires_api_version('1.21')
|
||||||
def test_remove_network(self):
|
def test_remove_network(self):
|
||||||
|
|
Loading…
Reference in New Issue