Merge pull request #4715 from shin-/4708-ipam_options

Add support for IPAM options in v2 format
This commit is contained in:
Joffrey F 2017-04-10 14:40:44 -07:00 committed by GitHub
commit d0d684f03d
4 changed files with 56 additions and 0 deletions

View File

@ -253,6 +253,13 @@
"driver": {"type": "string"},
"config": {
"type": "array"
},
"options": {
"type": "object",
"patternProperties": {
"^.+$": {"type": "string"}
},
"additionalProperties": false
}
},
"additionalProperties": false

View File

@ -298,6 +298,13 @@
"driver": {"type": "string"},
"config": {
"type": "array"
},
"options": {
"type": "object",
"patternProperties": {
"^.+$": {"type": "string"}
},
"additionalProperties": false
}
},
"additionalProperties": false

View File

@ -123,6 +123,7 @@ def create_ipam_config_from_dict(ipam_dict):
)
for config in ipam_dict.get('config', [])
],
options=ipam_dict.get('options')
)
@ -157,6 +158,12 @@ def check_remote_ipam_config(remote, local):
if sorted(lc.get('AuxiliaryAddresses')) != sorted(rc.get('AuxiliaryAddresses')):
raise NetworkConfigChangedError(local.full_name, 'IPAM config aux_addresses')
remote_opts = remote_ipam.get('Options', {})
local_opts = local.ipam.get('options', {})
for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
if remote_opts.get(k) != local_opts.get(k):
raise NetworkConfigChangedError(local.full_name, 'IPAM option "{}"'.format(k))
def check_remote_network_config(remote, local):
if local.driver and remote.get('Driver') != local.driver:

View File

@ -681,6 +681,41 @@ class ProjectTest(DockerClientTestCase):
}],
}
@v2_only()
def test_up_with_ipam_options(self):
config_data = build_config(
version=V2_0,
services=[{
'name': 'web',
'image': 'busybox:latest',
'networks': {'front': None},
}],
networks={
'front': {
'driver': 'bridge',
'ipam': {
'driver': 'default',
'options': {
"com.docker.compose.network.test": "9-29-045"
}
},
},
},
)
project = Project.from_config(
client=self.client,
name='composetest',
config_data=config_data,
)
project.up()
network = self.client.networks(names=['composetest_front'])[0]
assert network['IPAM']['Options'] == {
"com.docker.compose.network.test": "9-29-045"
}
@v2_only()
def test_up_with_network_static_addresses(self):
config_data = build_config(