Kaydet (Commit) 25db440c authored tarafından Joffrey F's avatar Joffrey F

Update arguments for several Swarm API methods

Add Client.update_swarm method
Add test for Client.update_swarm
Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst df31f9a8
......@@ -9,7 +9,7 @@ class SwarmApiMixin(object):
return utils.SwarmSpec(*args, **kwargs)
@utils.minimum_version('1.24')
def init_swarm(self, advertise_addr, listen_addr='0.0.0.0:2377',
def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
force_new_cluster=False, swarm_spec=None):
url = self._url('/swarm/init')
if swarm_spec is not None and not isinstance(swarm_spec, dict):
......@@ -30,14 +30,13 @@ class SwarmApiMixin(object):
return self._result(self._get(url), True)
@utils.minimum_version('1.24')
def join_swarm(self, remote_addresses, listen_address=None,
secret=None, ca_cert_hash=None, manager=False):
def join_swarm(self, remote_addrs, join_token, listen_addr=None,
advertise_addr=None):
data = {
"RemoteAddrs": remote_addresses,
"ListenAddr": listen_address,
"Secret": secret,
"CACertHash": ca_cert_hash,
"Manager": manager
"RemoteAddrs": remote_addrs,
"ListenAddr": listen_addr,
"JoinToken": join_token,
"AdvertiseAddr": advertise_addr,
}
url = self._url('/swarm/join')
response = self._post_json(url, data=data)
......@@ -50,3 +49,15 @@ class SwarmApiMixin(object):
response = self._post(url, params={'force': force})
self._raise_for_status(response)
return True
@utils.minimum_version('1.24')
def update_swarm(self, version, swarm_spec=None, rotate_worker_token=False,
rotate_manager_token=False):
url = self._url('/swarm/update')
response = self._post_json(url, data=swarm_spec, params={
'rotateWorkerToken': rotate_worker_token,
'rotateManagerToken': rotate_manager_token,
'version': version
})
self._raise_for_status(response)
return True
......@@ -10,6 +10,6 @@ from .utils import (
from .types import LogConfig, Ulimit
from .types import (
SwarmAcceptancePolicy, SwarmExternalCA, SwarmSpec,
SwarmExternalCA, SwarmSpec,
)
from .decorators import check_resource, minimum_version, update_headers
......@@ -97,13 +97,11 @@ class Ulimit(DictType):
class SwarmSpec(DictType):
def __init__(self, policies=None, task_history_retention_limit=None,
def __init__(self, task_history_retention_limit=None,
snapshot_interval=None, keep_old_snapshots=None,
log_entries_for_slow_followers=None, heartbeat_tick=None,
election_tick=None, dispatcher_heartbeat_period=None,
node_cert_expiry=None, external_ca=None):
if policies is not None:
self['AcceptancePolicy'] = {'Policies': policies}
if task_history_retention_limit is not None:
self['Orchestration'] = {
'TaskHistoryRetentionLimit': task_history_retention_limit
......@@ -130,14 +128,6 @@ class SwarmSpec(DictType):
}
class SwarmAcceptancePolicy(DictType):
def __init__(self, role, auto_accept=False, secret=None):
self['Role'] = role.upper()
self['Autoaccept'] = auto_accept
if secret is not None:
self['Secret'] = secret
class SwarmExternalCA(DictType):
def __init__(self, url, protocol=None, options=None):
self['URL'] = url
......
......@@ -65,3 +65,34 @@ class SwarmTest(helpers.BaseTestCase):
with pytest.raises(docker.errors.APIError) as exc_info:
self.client.inspect_swarm()
exc_info.value.response.status_code == 406
@requires_api_version('1.24')
def test_update_swarm(self):
assert self.client.init_swarm('eth0')
swarm_info_1 = self.client.inspect_swarm()
spec = self.client.create_swarm_spec(
snapshot_interval=5000, log_entries_for_slow_followers=1200,
node_cert_expiry=7776000000000000
)
assert self.client.update_swarm(
version=swarm_info_1['Version']['Index'],
swarm_spec=spec, rotate_worker_token=True
)
swarm_info_2 = self.client.inspect_swarm()
assert (
swarm_info_1['Version']['Index'] !=
swarm_info_2['Version']['Index']
)
assert swarm_info_2['Spec']['Raft']['SnapshotInterval'] == 5000
assert (
swarm_info_2['Spec']['Raft']['LogEntriesForSlowFollowers'] == 1200
)
assert (
swarm_info_1['JoinTokens']['Manager'] ==
swarm_info_2['JoinTokens']['Manager']
)
assert (
swarm_info_1['JoinTokens']['Worker'] !=
swarm_info_2['JoinTokens']['Worker']
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment