Kaydet (Commit) 44868fa0 authored tarafından minzhang's avatar minzhang Kaydeden (comit) Joffrey F

Added support for docker swarm api version 1.24.

3 API are added
swarm_init()
swarm_leave()
swarm_join()

Signed-off-by: Min Zhang<minzhang.work@gmail.com>
Signed-off-by: 's avatarMin Zhang <virgilerin@gmail.com>
üst 20b29d04
......@@ -6,3 +6,4 @@ from .exec_api import ExecApiMixin
from .image import ImageApiMixin
from .volume import VolumeApiMixin
from .network import NetworkApiMixin
from .swarm import SwarmApiMixin
from .. import utils
import logging
log = logging.getLogger(__name__)
class SwarmApiMixin(object):
@utils.minimum_version('1.24')
def swarm(self):
url = self._url('/swarm')
return self._result(self._get(url), True)
@utils.minimum_version('1.24')
def swarm_init(self, listen_addr, force_new_cluster=False,
swarm_opts=None):
url = self._url('/swarm/init')
if swarm_opts is not None and not isinstance(swarm_opts, dict):
raise TypeError('swarm_opts must be a dictionary')
data = {
'ListenAddr': listen_addr,
'ForceNewCluster': force_new_cluster,
'Spec': swarm_opts
}
return self._result(self._post_json(url, data=data), True)
@utils.minimum_version('1.24')
def swarm_join(self, remote_address, listen_address=None,
secret=None, ca_cert_hash=None, manager=False):
data ={
"RemoteAddr": remote_address,
"ListenAddr": listen_address,
"Secret": secret,
"CACertHash": ca_cert_hash,
"Manager": manager
}
url = self._url('/swarm/join', )
return self._result(self._post_json(url, data=data), True)
@utils.minimum_version('1.24')
def swarm_leave(self):
url = self._url('/swarm/leave')
return self._result(self._post(url))
......@@ -48,7 +48,8 @@ class Client(
api.ExecApiMixin,
api.ImageApiMixin,
api.VolumeApiMixin,
api.NetworkApiMixin):
api.NetworkApiMixin,
api.SwarmApiMixin):
def __init__(self, base_url=None, version=None,
timeout=constants.DEFAULT_TIMEOUT_SECONDS, tls=False,
user_agent=constants.DEFAULT_USER_AGENT):
......
# Using swarm for API version 1.24 or higher
Swarm initialization is done in two parts. Provide a listen_addr and `force_new_cluster` (OPTIONAL) to
the `Client().swarm_init()` method, and declare mappings in the
`swarm_opts` section.
```python
swarm_id = cli.swarm_init(listen_addr="0.0.0.0:4500",
swarm_opts={
"AcceptancePolicy": {
"Policies": [
{
"Role": "MANAGER",
"Autoaccept": True
}
]
}
})
```
Join another swarm, by providing the remote_address, listen_address(optional),
secret(optional), ca_cert_hash(optional, manager(optional)
```python
cli.swarm_join(
remote_address="swarm-master:2377",
manager=True
)
```
Leave swarm
```python
cli.swarm_leave()
```
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