mirror of https://github.com/docker/docker-py.git
Merge pull request #2303 from hannseman/swarm-DataPathAddr
Add support for swarm DataPathAddr
This commit is contained in:
commit
9682422718
|
@ -84,7 +84,8 @@ class SwarmApiMixin(object):
|
|||
@utils.minimum_version('1.24')
|
||||
def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
|
||||
force_new_cluster=False, swarm_spec=None,
|
||||
default_addr_pool=None, subnet_size=None):
|
||||
default_addr_pool=None, subnet_size=None,
|
||||
data_path_addr=None):
|
||||
"""
|
||||
Initialize a new Swarm using the current connected engine as the first
|
||||
node.
|
||||
|
@ -115,6 +116,8 @@ class SwarmApiMixin(object):
|
|||
Default: None
|
||||
subnet_size (int): SubnetSize specifies the subnet size of the
|
||||
networks created from the default subnet pool. Default: None
|
||||
data_path_addr (string): Address or interface to use for data path
|
||||
traffic. For example, 192.168.1.1, or an interface, like eth0.
|
||||
|
||||
Returns:
|
||||
``True`` if successful.
|
||||
|
@ -154,6 +157,15 @@ class SwarmApiMixin(object):
|
|||
'ForceNewCluster': force_new_cluster,
|
||||
'Spec': swarm_spec,
|
||||
}
|
||||
|
||||
if data_path_addr is not None:
|
||||
if utils.version_lt(self._version, '1.30'):
|
||||
raise errors.InvalidVersion(
|
||||
'Data address path is only available for '
|
||||
'API version >= 1.30'
|
||||
)
|
||||
data['DataPathAddr'] = data_path_addr
|
||||
|
||||
response = self._post_json(url, data=data)
|
||||
self._raise_for_status(response)
|
||||
return True
|
||||
|
@ -194,7 +206,7 @@ class SwarmApiMixin(object):
|
|||
|
||||
@utils.minimum_version('1.24')
|
||||
def join_swarm(self, remote_addrs, join_token, listen_addr='0.0.0.0:2377',
|
||||
advertise_addr=None):
|
||||
advertise_addr=None, data_path_addr=None):
|
||||
"""
|
||||
Make this Engine join a swarm that has already been created.
|
||||
|
||||
|
@ -213,6 +225,8 @@ class SwarmApiMixin(object):
|
|||
the port number from the listen address is used. If
|
||||
AdvertiseAddr is not specified, it will be automatically
|
||||
detected when possible. Default: ``None``
|
||||
data_path_addr (string): Address or interface to use for data path
|
||||
traffic. For example, 192.168.1.1, or an interface, like eth0.
|
||||
|
||||
Returns:
|
||||
``True`` if the request went through.
|
||||
|
@ -222,11 +236,20 @@ class SwarmApiMixin(object):
|
|||
If the server returns an error.
|
||||
"""
|
||||
data = {
|
||||
"RemoteAddrs": remote_addrs,
|
||||
"ListenAddr": listen_addr,
|
||||
"JoinToken": join_token,
|
||||
"AdvertiseAddr": advertise_addr,
|
||||
'RemoteAddrs': remote_addrs,
|
||||
'ListenAddr': listen_addr,
|
||||
'JoinToken': join_token,
|
||||
'AdvertiseAddr': advertise_addr,
|
||||
}
|
||||
|
||||
if data_path_addr is not None:
|
||||
if utils.version_lt(self._version, '1.30'):
|
||||
raise errors.InvalidVersion(
|
||||
'Data address path is only available for '
|
||||
'API version >= 1.30'
|
||||
)
|
||||
data['DataPathAddr'] = data_path_addr
|
||||
|
||||
url = self._url('/swarm/join')
|
||||
response = self._post_json(url, data=data)
|
||||
self._raise_for_status(response)
|
||||
|
|
|
@ -35,7 +35,7 @@ class Swarm(Model):
|
|||
|
||||
def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
|
||||
force_new_cluster=False, default_addr_pool=None,
|
||||
subnet_size=None, **kwargs):
|
||||
subnet_size=None, data_path_addr=None, **kwargs):
|
||||
"""
|
||||
Initialize a new swarm on this Engine.
|
||||
|
||||
|
@ -63,6 +63,8 @@ class Swarm(Model):
|
|||
Default: None
|
||||
subnet_size (int): SubnetSize specifies the subnet size of the
|
||||
networks created from the default subnet pool. Default: None
|
||||
data_path_addr (string): Address or interface to use for data path
|
||||
traffic. For example, 192.168.1.1, or an interface, like eth0.
|
||||
task_history_retention_limit (int): Maximum number of tasks
|
||||
history stored.
|
||||
snapshot_interval (int): Number of logs entries between snapshot.
|
||||
|
@ -117,7 +119,8 @@ class Swarm(Model):
|
|||
'listen_addr': listen_addr,
|
||||
'force_new_cluster': force_new_cluster,
|
||||
'default_addr_pool': default_addr_pool,
|
||||
'subnet_size': subnet_size
|
||||
'subnet_size': subnet_size,
|
||||
'data_path_addr': data_path_addr,
|
||||
}
|
||||
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)
|
||||
self.client.api.init_swarm(**init_kwargs)
|
||||
|
|
|
@ -233,3 +233,7 @@ class SwarmTest(BaseAPIIntegrationTest):
|
|||
self.client.remove_node(node_id, True)
|
||||
|
||||
assert e.value.response.status_code >= 400
|
||||
|
||||
@requires_api_version('1.30')
|
||||
def test_init_swarm_data_path_addr(self):
|
||||
assert self.init_swarm(data_path_addr='eth0')
|
||||
|
|
|
@ -31,3 +31,15 @@ class SwarmTest(unittest.TestCase):
|
|||
cm.value.response.status_code == 406 or
|
||||
cm.value.response.status_code == 503
|
||||
)
|
||||
|
||||
def test_join_on_already_joined_swarm(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
client.swarm.init()
|
||||
join_token = client.swarm.attrs['JoinTokens']['Manager']
|
||||
with pytest.raises(docker.errors.APIError) as cm:
|
||||
client.swarm.join(
|
||||
remote_addrs=['127.0.0.1'],
|
||||
join_token=join_token,
|
||||
)
|
||||
assert cm.value.response.status_code == 503
|
||||
assert 'This node is already part of a swarm.' in cm.value.explanation
|
||||
|
|
Loading…
Reference in New Issue