#![cfg(feature = "swarm")]
pub mod models;
pub mod opts;
pub use models::*;
pub use opts::*;
use crate::{conn::Payload, Docker, Result};
api_doc! { Swarm
|
pub struct Swarm<'docker> {
docker: &'docker Docker,
}
}
impl<'docker> Swarm<'docker> {
pub fn new(docker: &'docker Docker) -> Self {
Self { docker }
}
impl_api_ep! {_swarm: Swarm, resp
Inspect -> "/swarm"
}
api_doc! { Swarm => Unlockkey
|
pub async fn get_unlock_key(&self) -> Result<UnlockKey> {
self.docker.get_json("/swarm/unlockkey").await
}}
api_doc! { Swarm => Unlock
|
pub async fn unlock_manager(&self, key: &UnlockKey) -> Result<()> {
self.docker
.post("/swarm/unlock", Payload::Json(serde_json::to_string(key)?))
.await
.map(|_| ())
}}
api_doc! { Swarm => Init
|
pub async fn initialize(&self, opts: &SwarmInitOpts) -> Result<()> {
self.docker
.post("/swarm/init", Payload::Json(opts.serialize()?))
.await
.map(|_| ())
}}
api_doc! { Swarm => Join
|
pub async fn join(&self, opts: &SwarmJoinOpts) -> Result<()> {
self.docker
.post("/swarm/join", Payload::Json(opts.serialize()?))
.await
.map(|_| ())
}}
api_doc! { Swarm => Leave
|
pub async fn leave(&self) -> Result<()> {
self.docker
.post("/swarm/leave?force=false", Payload::empty())
.await
.map(|_| ())
}}
api_doc! { Swarm => Leave
|
pub async fn force_leave(&self) -> Result<()> {
self.docker
.post("/swarm/leave?force=true", Payload::empty())
.await
.map(|_| ())
}}
}