|
1 | 1 | import logging
|
2 | 2 | from six.moves import http_client
|
| 3 | +from .. import errors |
3 | 4 | from .. import types
|
4 | 5 | from .. import utils
|
| 6 | + |
5 | 7 | log = logging.getLogger(__name__)
|
6 | 8 |
|
7 | 9 |
|
@@ -68,6 +70,16 @@ def create_swarm_spec(self, *args, **kwargs):
|
68 | 70 | kwargs['external_cas'] = [ext_ca]
|
69 | 71 | return types.SwarmSpec(self._version, *args, **kwargs)
|
70 | 72 |
|
| 73 | + @utils.minimum_version('1.24') |
| 74 | + def get_unlock_key(self): |
| 75 | + """ |
| 76 | + Get the unlock key for this Swarm manager. |
| 77 | +
|
| 78 | + Returns: |
| 79 | + A ``dict`` containing an ``UnlockKey`` member |
| 80 | + """ |
| 81 | + return self._result(self._get(self._url('/swarm/unlockkey')), True) |
| 82 | + |
71 | 83 | @utils.minimum_version('1.24')
|
72 | 84 | def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
|
73 | 85 | force_new_cluster=False, swarm_spec=None):
|
@@ -270,10 +282,46 @@ def remove_node(self, node_id, force=False):
|
270 | 282 | self._raise_for_status(res)
|
271 | 283 | return True
|
272 | 284 |
|
| 285 | + @utils.minimum_version('1.24') |
| 286 | + def unlock_swarm(self, key): |
| 287 | + """ |
| 288 | + Unlock a locked swarm. |
| 289 | +
|
| 290 | + Args: |
| 291 | + key (string): The unlock key as provided by |
| 292 | + :py:meth:`get_unlock_key` |
| 293 | +
|
| 294 | + Raises: |
| 295 | + :py:class:`docker.errors.InvalidArgument` |
| 296 | + If the key argument is in an incompatible format |
| 297 | +
|
| 298 | + :py:class:`docker.errors.APIError` |
| 299 | + If the server returns an error. |
| 300 | +
|
| 301 | + Returns: |
| 302 | + `True` if the request was successful. |
| 303 | +
|
| 304 | + Example: |
| 305 | +
|
| 306 | + >>> key = client.get_unlock_key() |
| 307 | + >>> client.unlock_node(key) |
| 308 | +
|
| 309 | + """ |
| 310 | + if isinstance(key, dict): |
| 311 | + if 'UnlockKey' not in key: |
| 312 | + raise errors.InvalidArgument('Invalid unlock key format') |
| 313 | + else: |
| 314 | + key = {'UnlockKey': key} |
| 315 | + |
| 316 | + url = self._url('/swarm/unlock') |
| 317 | + res = self._post_json(url, data=key) |
| 318 | + self._raise_for_status(res) |
| 319 | + return True |
| 320 | + |
273 | 321 | @utils.minimum_version('1.24')
|
274 | 322 | def update_node(self, node_id, version, node_spec=None):
|
275 | 323 | """
|
276 |
| - Update the Node's configuration |
| 324 | + Update the node's configuration |
277 | 325 |
|
278 | 326 | Args:
|
279 | 327 |
|
|
0 commit comments