mirror of https://github.com/docker/docker-py.git
Add support for rotate_manager_unlock_key
Signed-off-by: Hannes Ljungberg <hannes@5monkeys.se>
This commit is contained in:
parent
4d62dd0a64
commit
532c62ee51
|
@ -406,8 +406,10 @@ class SwarmApiMixin(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@utils.minimum_version('1.24')
|
@utils.minimum_version('1.24')
|
||||||
def update_swarm(self, version, swarm_spec=None, rotate_worker_token=False,
|
def update_swarm(self, version, swarm_spec=None,
|
||||||
rotate_manager_token=False):
|
rotate_worker_token=False,
|
||||||
|
rotate_manager_token=False,
|
||||||
|
rotate_manager_unlock_key=False):
|
||||||
"""
|
"""
|
||||||
Update the Swarm's configuration
|
Update the Swarm's configuration
|
||||||
|
|
||||||
|
@ -421,6 +423,8 @@ class SwarmApiMixin(object):
|
||||||
``False``.
|
``False``.
|
||||||
rotate_manager_token (bool): Rotate the manager join token.
|
rotate_manager_token (bool): Rotate the manager join token.
|
||||||
Default: ``False``.
|
Default: ``False``.
|
||||||
|
rotate_manager_unlock_key (bool): Rotate the manager unlock key.
|
||||||
|
Default: ``False``.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
``True`` if the request went through.
|
``True`` if the request went through.
|
||||||
|
@ -429,12 +433,20 @@ class SwarmApiMixin(object):
|
||||||
:py:class:`docker.errors.APIError`
|
:py:class:`docker.errors.APIError`
|
||||||
If the server returns an error.
|
If the server returns an error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = self._url('/swarm/update')
|
url = self._url('/swarm/update')
|
||||||
response = self._post_json(url, data=swarm_spec, params={
|
params = {
|
||||||
'rotateWorkerToken': rotate_worker_token,
|
'rotateWorkerToken': rotate_worker_token,
|
||||||
'rotateManagerToken': rotate_manager_token,
|
'rotateManagerToken': rotate_manager_token,
|
||||||
'version': version
|
'version': version
|
||||||
})
|
}
|
||||||
|
if rotate_manager_unlock_key:
|
||||||
|
if utils.version_lt(self._version, '1.25'):
|
||||||
|
raise errors.InvalidVersion(
|
||||||
|
'Rotate manager unlock key '
|
||||||
|
'is only available for API version >= 1.25'
|
||||||
|
)
|
||||||
|
params['rotateManagerUnlockKey'] = rotate_manager_unlock_key
|
||||||
|
|
||||||
|
response = self._post_json(url, data=swarm_spec, params=params)
|
||||||
self._raise_for_status(response)
|
self._raise_for_status(response)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -151,7 +151,7 @@ class Swarm(Model):
|
||||||
unlock.__doc__ = APIClient.unlock_swarm.__doc__
|
unlock.__doc__ = APIClient.unlock_swarm.__doc__
|
||||||
|
|
||||||
def update(self, rotate_worker_token=False, rotate_manager_token=False,
|
def update(self, rotate_worker_token=False, rotate_manager_token=False,
|
||||||
**kwargs):
|
rotate_manager_unlock_key=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
Update the swarm's configuration.
|
Update the swarm's configuration.
|
||||||
|
|
||||||
|
@ -164,7 +164,8 @@ class Swarm(Model):
|
||||||
``False``.
|
``False``.
|
||||||
rotate_manager_token (bool): Rotate the manager join token.
|
rotate_manager_token (bool): Rotate the manager join token.
|
||||||
Default: ``False``.
|
Default: ``False``.
|
||||||
|
rotate_manager_unlock_key (bool): Rotate the manager unlock key.
|
||||||
|
Default: ``False``.
|
||||||
Raises:
|
Raises:
|
||||||
:py:class:`docker.errors.APIError`
|
:py:class:`docker.errors.APIError`
|
||||||
If the server returns an error.
|
If the server returns an error.
|
||||||
|
@ -178,5 +179,6 @@ class Swarm(Model):
|
||||||
version=self.version,
|
version=self.version,
|
||||||
swarm_spec=self.client.api.create_swarm_spec(**kwargs),
|
swarm_spec=self.client.api.create_swarm_spec(**kwargs),
|
||||||
rotate_worker_token=rotate_worker_token,
|
rotate_worker_token=rotate_worker_token,
|
||||||
rotate_manager_token=rotate_manager_token
|
rotate_manager_token=rotate_manager_token,
|
||||||
|
rotate_manager_unlock_key=rotate_manager_unlock_key
|
||||||
)
|
)
|
||||||
|
|
|
@ -236,6 +236,19 @@ class SwarmTest(BaseAPIIntegrationTest):
|
||||||
|
|
||||||
assert e.value.response.status_code >= 400
|
assert e.value.response.status_code >= 400
|
||||||
|
|
||||||
|
@requires_api_version('1.25')
|
||||||
|
def test_rotate_manager_unlock_key(self):
|
||||||
|
spec = self.client.create_swarm_spec(autolock_managers=True)
|
||||||
|
assert self.init_swarm(swarm_spec=spec)
|
||||||
|
swarm_info = self.client.inspect_swarm()
|
||||||
|
key_1 = self.client.get_unlock_key()
|
||||||
|
assert self.client.update_swarm(
|
||||||
|
version=swarm_info['Version']['Index'],
|
||||||
|
rotate_manager_unlock_key=True
|
||||||
|
)
|
||||||
|
key_2 = self.client.get_unlock_key()
|
||||||
|
assert key_1['UnlockKey'] != key_2['UnlockKey']
|
||||||
|
|
||||||
@requires_api_version('1.30')
|
@requires_api_version('1.30')
|
||||||
def test_init_swarm_data_path_addr(self):
|
def test_init_swarm_data_path_addr(self):
|
||||||
assert self.init_swarm(data_path_addr='eth0')
|
assert self.init_swarm(data_path_addr='eth0')
|
||||||
|
|
Loading…
Reference in New Issue