rs_docker_api_rs/api/
system.rsuse crate::{
models,
opts::{EventsOpts, SystemDataUsageOpts},
Docker, Error, Result,
};
use containers_api::url::construct_ep;
use futures_util::{Stream, TryStreamExt};
use std::{convert::TryFrom, io};
impl Docker {
api_doc! { System => Version
|
pub async fn version(&self) -> Result<rs_docker_api_stubs::models::SystemVersion> {
self.get_json("/version").await
}}
api_doc! { System => Info
|
pub async fn info(&self) -> Result<rs_docker_api_stubs::models::SystemInfo> {
self.get_json("/info").await
}}
api_doc! { System => Ping
|
pub async fn ping(&self) -> Result<models::PingInfo> {
self.get("/_ping")
.await
.and_then(|resp| crate::models::PingInfo::try_from(resp.headers()))
}}
api_doc! { System => Events
|
pub fn events<'docker>(
&'docker self,
opts: &EventsOpts,
) -> impl Stream<Item = Result<rs_docker_api_stubs::models::EventMessage>> + Unpin + 'docker {
let ep = construct_ep("/events", opts.serialize());
let reader = Box::pin(
self.get_stream(ep)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)),
)
.into_async_read();
Box::pin(
asynchronous_codec::FramedRead::new(reader, asynchronous_codec::LinesCodec)
.map_err(Error::IO)
.and_then(|s: String| async move {
serde_json::from_str(&s).map_err(Error::SerdeJsonError)
}),
)
}}
api_doc! { System => DataUsage
|
pub async fn data_usage(&self, opts: &SystemDataUsageOpts) -> Result<rs_docker_api_stubs::models::SystemDataUsage200Response> {
let ep = construct_ep("/system/df", opts.serialize());
self.get_json(&ep).await
}}
}