mirror of https://github.com/docker/docker-py.git
Added arguments to creeate a swarm with a custom address pool and subnet size.
Signed-off-by: Barry Shapira <barry@whiterabbit.ai>
This commit is contained in:
parent
142db4b3d3
commit
5d69a0a62e
|
@ -82,6 +82,7 @@ class SwarmApiMixin(object):
|
|||
|
||||
@utils.minimum_version('1.24')
|
||||
def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
|
||||
default_addr_pool=[], subnet_size=24,
|
||||
force_new_cluster=False, swarm_spec=None):
|
||||
"""
|
||||
Initialize a new Swarm using the current connected engine as the first
|
||||
|
@ -102,6 +103,12 @@ class SwarmApiMixin(object):
|
|||
or an interface followed by a port number, like ``eth0:4567``.
|
||||
If the port number is omitted, the default swarm listening port
|
||||
is used. Default: '0.0.0.0:2377'
|
||||
default_addr_pool (list of strings): Default Address Pool specifies
|
||||
default subnet pools for global scope networks. Each pool
|
||||
should be specified as a CIDR block, like '10.0.0.0/16'.
|
||||
Default: []
|
||||
subnet_size (int): SubnetSize specifies the subnet size of the
|
||||
networks created from the default subnet pool. Default: 24
|
||||
force_new_cluster (bool): Force creating a new Swarm, even if
|
||||
already part of one. Default: False
|
||||
swarm_spec (dict): Configuration settings of the new Swarm. Use
|
||||
|
@ -122,6 +129,8 @@ class SwarmApiMixin(object):
|
|||
data = {
|
||||
'AdvertiseAddr': advertise_addr,
|
||||
'ListenAddr': listen_addr,
|
||||
'DefaultAddrPool': default_addr_pool,
|
||||
'SubnetSize': subnet_size,
|
||||
'ForceNewCluster': force_new_cluster,
|
||||
'Spec': swarm_spec,
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ class Swarm(Model):
|
|||
get_unlock_key.__doc__ = APIClient.get_unlock_key.__doc__
|
||||
|
||||
def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
|
||||
default_addr_pool=[], subnet_size=24,
|
||||
force_new_cluster=False, **kwargs):
|
||||
"""
|
||||
Initialize a new swarm on this Engine.
|
||||
|
@ -54,6 +55,12 @@ class Swarm(Model):
|
|||
or an interface followed by a port number, like ``eth0:4567``.
|
||||
If the port number is omitted, the default swarm listening port
|
||||
is used. Default: ``0.0.0.0:2377``
|
||||
default_addr_pool (list of str): Default Address Pool specifies
|
||||
default subnet pools for global scope networks. Each pool
|
||||
should be specified as a CIDR block, like '10.0.0.0/16'.
|
||||
Default: []
|
||||
subnet_size (int): SubnetSize specifies the subnet size of the
|
||||
networks created from the default subnet pool. Default: 24
|
||||
force_new_cluster (bool): Force creating a new Swarm, even if
|
||||
already part of one. Default: False
|
||||
task_history_retention_limit (int): Maximum number of tasks
|
||||
|
@ -99,6 +106,7 @@ class Swarm(Model):
|
|||
|
||||
>>> client.swarm.init(
|
||||
advertise_addr='eth0', listen_addr='0.0.0.0:5000',
|
||||
default_addr_pool=['10.20.0.0/16], subnet_size=24,
|
||||
force_new_cluster=False, snapshot_interval=5000,
|
||||
log_entries_for_slow_followers=1200
|
||||
)
|
||||
|
@ -107,6 +115,8 @@ class Swarm(Model):
|
|||
init_kwargs = {
|
||||
'advertise_addr': advertise_addr,
|
||||
'listen_addr': listen_addr,
|
||||
'default_addr_pool': default_addr_pool,
|
||||
'subnet_size': subnet_size,
|
||||
'force_new_cluster': force_new_cluster
|
||||
}
|
||||
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)
|
||||
|
|
|
@ -35,6 +35,29 @@ class SwarmTest(BaseAPIIntegrationTest):
|
|||
version_2 = self.client.inspect_swarm()['Version']['Index']
|
||||
assert version_2 != version_1
|
||||
|
||||
@requires_api_version('1.39')
|
||||
def test_init_swarm_custom_addr_pool(self):
|
||||
assert self.init_swarm()
|
||||
results_1 = self.client.inspect_swarm()
|
||||
assert results_1['DefaultAddrPool'] is None
|
||||
assert results_1['SubnetSize'] == 24
|
||||
|
||||
assert self.init_swarm(default_addr_pool=['2.0.0.0/16'],
|
||||
force_new_cluster=True)
|
||||
results_2 = self.client.inspect_swarm()
|
||||
assert set(results_2['DefaultAddrPool']) == (
|
||||
{'2.0.0.0/16'}
|
||||
)
|
||||
assert results_2['SubnetSize'] == 24
|
||||
|
||||
assert self.init_swarm(default_addr_pool=['2.0.0.0/16', '3.0.0.0/16'],
|
||||
subnet_size=28, force_new_cluster=True)
|
||||
results_3 = self.client.inspect_swarm()
|
||||
assert set(results_3['DefaultAddrPool']) == (
|
||||
{'2.0.0.0/16', '3.0.0.0/16'}
|
||||
)
|
||||
assert results_3['SubnetSize'] == 28
|
||||
|
||||
@requires_api_version('1.24')
|
||||
def test_init_already_in_cluster(self):
|
||||
assert self.init_swarm()
|
||||
|
|
Loading…
Reference in New Issue