mirror of https://github.com/docker/docker-py.git
Add support for creating internal networks
Signed-off-by: Jonathan Giannuzzi <jonathan@giannuzzi.be>
This commit is contained in:
parent
966dfac3b5
commit
98b41fee3c
|
@ -22,7 +22,7 @@ class NetworkApiMixin(object):
|
||||||
|
|
||||||
@minimum_version('1.21')
|
@minimum_version('1.21')
|
||||||
def create_network(self, name, driver=None, options=None, ipam=None,
|
def create_network(self, name, driver=None, options=None, ipam=None,
|
||||||
check_duplicate=None):
|
check_duplicate=None, internal=False):
|
||||||
if options is not None and not isinstance(options, dict):
|
if options is not None and not isinstance(options, dict):
|
||||||
raise TypeError('options must be a dictionary')
|
raise TypeError('options must be a dictionary')
|
||||||
|
|
||||||
|
@ -33,6 +33,13 @@ class NetworkApiMixin(object):
|
||||||
'IPAM': ipam,
|
'IPAM': ipam,
|
||||||
'CheckDuplicate': check_duplicate
|
'CheckDuplicate': check_duplicate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if internal:
|
||||||
|
if version_lt(self._version, '1.22'):
|
||||||
|
raise InvalidVersion('Internal networks are not '
|
||||||
|
'supported in API version < 1.22')
|
||||||
|
data['Internal'] = True
|
||||||
|
|
||||||
url = self._url("/networks/create")
|
url = self._url("/networks/create")
|
||||||
res = self._post_json(url, data=data)
|
res = self._post_json(url, data=data)
|
||||||
return self._result(res, json=True)
|
return self._result(res, json=True)
|
||||||
|
|
|
@ -18,3 +18,10 @@ ipam_config = docker.utils.create_ipam_config(subnet='192.168.52.0/24', gateway=
|
||||||
|
|
||||||
docker_client.create_network("network1", driver="bridge", ipam=ipam_config)
|
docker_client.create_network("network1", driver="bridge", ipam=ipam_config)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
With Docker 1.10 you can now also create internal networks
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
docker_client.create_network("network1", driver="bridge", internal=True)
|
||||||
|
```
|
||||||
|
|
|
@ -298,3 +298,9 @@ class TestNetworks(helpers.BaseTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
net_data['IPAMConfig']['IPv6Address'], '2001:389::f00d'
|
net_data['IPAMConfig']['IPv6Address'], '2001:389::f00d'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@requires_api_version('1.23')
|
||||||
|
def test_create_internal_networks(self):
|
||||||
|
_, net_id = self.create_network(internal=True)
|
||||||
|
net = self.client.inspect_network(net_id)
|
||||||
|
assert net['Internal'] is True
|
||||||
|
|
Loading…
Reference in New Issue