mirror of https://github.com/docker/docker-py.git
Implement swarm node removal
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
d56b2d3dc8
commit
c239e40504
|
@ -224,6 +224,33 @@ class SwarmApiMixin(object):
|
|||
|
||||
return self._result(self._get(url, params=params), True)
|
||||
|
||||
@utils.check_resource
|
||||
@utils.minimum_version('1.24')
|
||||
def remove_node(self, node_id, force=False):
|
||||
"""
|
||||
Remove a node from the swarm.
|
||||
|
||||
Args:
|
||||
node_id (string): ID of the node to be removed.
|
||||
force (bool): Force remove an active node. Default: `False`
|
||||
|
||||
Raises:
|
||||
:py:class:`docker.errors.NotFound`
|
||||
If the node referenced doesn't exist in the swarm.
|
||||
|
||||
:py:class:`docker.errors.APIError`
|
||||
If the server returns an error.
|
||||
Returns:
|
||||
`True` if the request was successful.
|
||||
"""
|
||||
url = self._url('/nodes/{0}', node_id)
|
||||
params = {
|
||||
'force': force
|
||||
}
|
||||
res = self._delete(url, params=params)
|
||||
self._raise_for_status(res)
|
||||
return True
|
||||
|
||||
@utils.minimum_version('1.24')
|
||||
def update_node(self, node_id, version, node_spec=None):
|
||||
"""
|
||||
|
@ -231,6 +258,7 @@ class SwarmApiMixin(object):
|
|||
|
||||
Args:
|
||||
|
||||
node_id (string): ID of the node to be updated.
|
||||
version (int): The version number of the node object being
|
||||
updated. This is required to avoid conflicting writes.
|
||||
node_spec (dict): Configuration settings to update. Any values
|
||||
|
|
|
@ -41,6 +41,25 @@ class Node(Model):
|
|||
"""
|
||||
return self.client.api.update_node(self.id, self.version, node_spec)
|
||||
|
||||
def remove(self, force=False):
|
||||
"""
|
||||
Remove this node from the swarm.
|
||||
|
||||
Args:
|
||||
force (bool): Force remove an active node. Default: `False`
|
||||
|
||||
Returns:
|
||||
`True` if the request was successful.
|
||||
|
||||
Raises:
|
||||
:py:class:`docker.errors.NotFound`
|
||||
If the node doesn't exist in the swarm.
|
||||
|
||||
:py:class:`docker.errors.APIError`
|
||||
If the server returns an error.
|
||||
"""
|
||||
return self.client.api.remove_node(self.id, force=force)
|
||||
|
||||
|
||||
class NodeCollection(Collection):
|
||||
"""Nodes on the Docker server."""
|
||||
|
|
|
@ -159,3 +159,20 @@ class SwarmTest(BaseAPIIntegrationTest):
|
|||
node_spec=orig_spec)
|
||||
reverted_node = self.client.inspect_node(node['ID'])
|
||||
assert orig_spec == reverted_node['Spec']
|
||||
|
||||
@requires_api_version('1.24')
|
||||
def test_remove_main_node(self):
|
||||
assert self.client.init_swarm('eth0')
|
||||
nodes_list = self.client.nodes()
|
||||
node_id = nodes_list[0]['ID']
|
||||
with pytest.raises(docker.errors.NotFound):
|
||||
self.client.remove_node('foobar01')
|
||||
with pytest.raises(docker.errors.APIError) as e:
|
||||
self.client.remove_node(node_id)
|
||||
|
||||
assert e.value.response.status_code == 500
|
||||
|
||||
with pytest.raises(docker.errors.APIError) as e:
|
||||
self.client.remove_node(node_id, True)
|
||||
|
||||
assert e.value.response.status_code == 500
|
||||
|
|
Loading…
Reference in New Issue