summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/builder.rs42
-rw-r--r--src/lib.rs53
-rw-r--r--src/rep.rs3
-rw-r--r--src/transport.rs4
4 files changed, 53 insertions, 49 deletions
diff --git a/src/builder.rs b/src/builder.rs
index 32f8374..e16858e 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -14,39 +14,39 @@ use rustc_serialize::json::{self, Json, ToJson};
/// Interface for building container list request
pub struct ContainerListBuilder<'a> {
- docker: &'a mut Docker,
+ docker: &'a Docker,
params: HashMap<&'static str, String>,
}
impl<'a> ContainerListBuilder<'a> {
- pub fn new(docker: &'a mut Docker) -> ContainerListBuilder<'a> {
+ pub fn new(docker: &'a Docker) -> ContainerListBuilder<'a> {
ContainerListBuilder {
docker: docker,
params: HashMap::new(),
}
}
- pub fn all(mut self) -> ContainerListBuilder<'a> {
+ pub fn all(&mut self) -> &mut ContainerListBuilder<'a> {
self.params.insert("all", "true".to_owned());
self
}
- pub fn since(mut self, since: &str) -> ContainerListBuilder<'a> {
+ pub fn since(&mut self, since: &str) -> &mut ContainerListBuilder<'a> {
self.params.insert("since", since.to_owned());
self
}
- pub fn before(mut self, before: &str) -> ContainerListBuilder<'a> {
+ pub fn before(&mut self, before: &str) -> &mut ContainerListBuilder<'a> {
self.params.insert("before", before.to_owned());
self
}
- pub fn sized(mut self) -> ContainerListBuilder<'a> {
+ pub fn sized(&mut self) -> &mut ContainerListBuilder<'a> {
self.params.insert("size", "true".to_owned());
self
}
- pub fn get(self) -> Result<Vec<ContainerRep>> {
+ pub fn build(self) -> Result<Vec<ContainerRep>> {
let mut params = Vec::new();
for (k, v) in self.params {
params.push(format!("{}={}", k, v))
@@ -62,7 +62,7 @@ impl<'a> ContainerListBuilder<'a> {
/// Interface for building a new docker container from an existing image
pub struct ContainerBuilder<'a, 'b> {
- docker: &'a mut Docker,
+ docker: &'a Docker,
image: &'b str,
hostname: Option<String>,
user: Option<String>,
@@ -70,7 +70,7 @@ pub struct ContainerBuilder<'a, 'b> {
}
impl<'a, 'b> ContainerBuilder<'a, 'b> {
- pub fn new(docker: &'a mut Docker, image: &'b str) -> ContainerBuilder<'a, 'b> {
+ pub fn new(docker: &'a Docker, image: &'b str) -> ContainerBuilder<'a, 'b> {
ContainerBuilder {
docker: docker,
image: image,
@@ -79,17 +79,18 @@ impl<'a, 'b> ContainerBuilder<'a, 'b> {
memory: None,
}
}
- pub fn hostname(mut self, h: &str) -> ContainerBuilder<'a, 'b> {
+
+ pub fn hostname(&mut self, h: &str) -> &mut ContainerBuilder<'a, 'b> {
self.hostname = Some(h.to_owned());
self
}
- pub fn user(mut self, u: &str) -> ContainerBuilder<'a, 'b> {
+ pub fn user(&mut self, u: &str) -> &mut ContainerBuilder<'a, 'b> {
self.user = Some(u.to_owned());
self
}
- pub fn build(self) -> Result<ContainerCreateInfo> {
+ pub fn build(&self) -> Result<ContainerCreateInfo> {
let mut body = BTreeMap::new();
body.insert("Image".to_owned(), self.image.to_json());
let json_obj: Json = body.to_json();
@@ -103,15 +104,15 @@ impl<'a, 'b> ContainerBuilder<'a, 'b> {
}
/// Interface for buiding an events request
-pub struct Events<'a, 'b, 'c> {
- docker: &'a mut Docker,
+pub struct EventsBuilder<'a, 'b, 'c> {
+ docker: &'a Docker,
since: Option<&'b u64>,
until: Option<&'c u64>,
}
-impl<'a, 'b, 'c> Events<'a, 'b, 'c> {
- pub fn new(docker: &'a mut Docker) -> Events<'a, 'b, 'c> {
- Events {
+impl<'a, 'b, 'c> EventsBuilder<'a, 'b, 'c> {
+ pub fn new(docker: &'a Docker) -> EventsBuilder<'a, 'b, 'c> {
+ EventsBuilder {
docker: docker,
since: None,
until: None,
@@ -119,18 +120,19 @@ impl<'a, 'b, 'c> Events<'a, 'b, 'c> {
}
/// Filter events since a given timestamp
- pub fn since(mut self, ts: &'b u64) -> Events<'a, 'b, 'c> {
+ pub fn since(mut self, ts: &'b u64) -> EventsBuilder<'a, 'b, 'c> {
self.since = Some(ts);
self
}
/// Filter events until a given timestamp
- pub fn until(mut self, ts: &'c u64) -> Events<'a, 'b, 'c> {
+ pub fn until(mut self, ts: &'c u64) -> EventsBuilder<'a, 'b, 'c> {
self.until = Some(ts);
self
}
- pub fn get(mut self) -> Result<Box<Iterator<Item = Event>>> {
+ /// Returns an interator over streamed docker events
+ pub fn build(mut self) -> Result<Box<Iterator<Item = Event>>> {
let mut params = Vec::new();
if let Some(s) = self.since {
params.push(format!("since={}", s));
diff --git a/src/lib.rs b/src/lib.rs
index 12c1a12..44236bb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,7 @@
//! ```no_run
//! extern crate shiplift;
//!
-//! let mut docker = shiplift::Docker::new();
+//! let docker = shiplift::Docker::new();
//! let images = docker.images().list().unwrap();
//! println!("docker images in stock");
//! for i in images {
@@ -24,7 +24,7 @@ pub mod builder;
pub mod rep;
pub mod transport;
-use builder::{ContainerBuilder, ContainerListBuilder, Events};
+use builder::{ContainerBuilder, ContainerListBuilder, EventsBuilder};
use hyper::{Client, Url};
use hyper::net::{HttpsConnector, Openssl};
use hyper::method::Method;
@@ -50,13 +50,13 @@ pub struct Docker {
/// Interface for accessing and manipulating a named docker image
pub struct Image<'a, 'b> {
- docker: &'a mut Docker,
+ docker: &'a Docker,
name: &'b str,
}
impl<'a, 'b> Image<'a, 'b> {
/// Exports an interface for operations that may be performed against a named image
- pub fn new(docker: &'a mut Docker, name: &'b str) -> Image<'a, 'b> {
+ pub fn new(docker: &'a Docker, name: &'b str) -> Image<'a, 'b> {
Image {
docker: docker,
name: name,
@@ -102,12 +102,12 @@ impl<'a, 'b> Image<'a, 'b> {
/// Interface for docker images
pub struct Images<'a> {
- docker: &'a mut Docker,
+ docker: &'a Docker,
}
impl<'a> Images<'a> {
/// Exports an interface for interacting with docker images
- pub fn new(docker: &'a mut Docker) -> Images<'a> {
+ pub fn new(docker: &'a Docker) -> Images<'a> {
Images { docker: docker }
}
@@ -118,7 +118,7 @@ impl<'a> Images<'a> {
}
/// Returns a reference to a set of operations available for a named image
- pub fn get(&'a mut self, name: &'a str) -> Image {
+ pub fn get(&'a self, name: &'a str) -> Image {
Image::new(self.docker, name)
}
@@ -150,13 +150,13 @@ impl<'a> Images<'a> {
/// Interface for accessing and manipulating a docker container
pub struct Container<'a, 'b> {
- docker: &'a mut Docker,
+ docker: &'a Docker,
id: &'b str,
}
impl<'a, 'b> Container<'a, 'b> {
/// Exports an interface exposing operations against a container instance
- pub fn new(docker: &'a mut Docker, id: &'b str) -> Container<'a, 'b> {
+ pub fn new(docker: &'a Docker, id: &'b str) -> Container<'a, 'b> {
Container {
docker: docker,
id: id,
@@ -202,6 +202,7 @@ impl<'a, 'b> Container<'a, 'b> {
let raw = try!(self.docker.stream_get(&format!("/containers/{}/stats", self.id)[..]));
let it = jed::Iter::new(raw).into_iter().map(|j| {
let s = json::encode(&j).unwrap();
+ println!("stat -> {:?}", s);
json::decode::<Stats>(&s).unwrap()
});
Ok(Box::new(it))
@@ -261,27 +262,27 @@ impl<'a, 'b> Container<'a, 'b> {
/// Interface for docker containers
pub struct Containers<'a> {
- docker: &'a mut Docker,
+ docker: &'a Docker,
}
impl<'a> Containers<'a> {
/// Exports an interface for interacting with docker containers
- pub fn new(docker: &'a mut Docker) -> Containers<'a> {
+ pub fn new(docker: &'a Docker) -> Containers<'a> {
Containers { docker: docker }
}
/// Lists the container instances on the docker host
- pub fn list(self) -> ContainerListBuilder<'a> {
+ pub fn list(&self) -> ContainerListBuilder<'a> {
ContainerListBuilder::new(self.docker)
}
/// Returns a reference to a set of operations available to a specific container instance
- pub fn get(&'a mut self, name: &'a str) -> Container {
+ pub fn get(&'a self, name: &'a str) -> Container {
Container::new(self.docker, name)
}
/// Returns a builder interface for creating a new container instance
- pub fn create(&'a mut self, image: &'a str) -> ContainerBuilder {
+ pub fn create(&'a self, image: &'a str) -> ContainerBuilder {
ContainerBuilder::new(self.docker, image)
}
}
@@ -357,54 +358,54 @@ impl Docker {
}
/// Exports an interface for interacting with docker images
- pub fn images<'a>(&'a mut self) -> Images {
+ pub fn images<'a>(&'a self) -> Images {
Images::new(self)
}
/// Exports an interface for interacting with docker containers
- pub fn containers<'a>(&'a mut self) -> Containers {
+ pub fn containers<'a>(&'a self) -> Containers {
Containers::new(self)
}
/// Returns version information associated with the docker daemon
- pub fn version(&mut self) -> Result<Version> {
+ pub fn version(&self) -> Result<Version> {
let raw = try!(self.get("/version"));
Ok(json::decode::<Version>(&raw).unwrap())
}
/// Returns information associated with the docker daemon
- pub fn info(&mut self) -> Result<Info> {
+ pub fn info(&self) -> Result<Info> {
let raw = try!(self.get("/info"));
Ok(json::decode::<Info>(&raw).unwrap())
}
/// Returns a simple ping response indicating the docker daemon is accessible
- pub fn ping(&mut self) -> Result<String> {
+ pub fn ping(&self) -> Result<String> {
self.get("/_ping")
}
/// Retruns a stream of events ocurring on the current docker host
- pub fn events(&mut self) -> Events {
- Events::new(self)
+ pub fn events(&self) -> EventsBuilder {
+ EventsBuilder::new(self)
}
- fn get(&mut self, endpoint: &str) -> Result<String> {
+ fn get(&self, endpoint: &str) -> Result<String> {
self.transport.request(Method::Get, endpoint, None)
}
- fn post(&mut self, endpoint: &str, body: Option<Body>) -> Result<String> {
+ fn post(&self, endpoint: &str, body: Option<Body>) -> Result<String> {
self.transport.request(Method::Post, endpoint, body)
}
- fn delete(&mut self, endpoint: &str) -> Result<String> {
+ fn delete(&self, endpoint: &str) -> Result<String> {
self.transport.request(Method::Delete, endpoint, None)
}
- fn stream_post(&mut self, endpoint: &str) -> Result<Box<Read>> {
+ fn stream_post(&self, endpoint: &str) -> Result<Box<Read>> {
self.transport.stream(Method::Post, endpoint, None)
}
- fn stream_get(&mut self, endpoint: &str) -> Result<Box<Read>> {
+ fn stream_get(&self, endpoint: &str) -> Result<Box<Read>> {
self.transport.stream(Method::Get, endpoint, None)
}
}
diff --git a/src/rep.rs b/src/rep.rs
index 5891e14..9d4afd2 100644
--- a/src/rep.rs
+++ b/src/rep.rs
@@ -144,8 +144,9 @@ pub struct Port {
#[derive(Debug, RustcEncodable, RustcDecodable)]
pub struct Stats {
pub read: String,
- pub network: Network,
+ pub networks: HashMap<String, Network>,
pub memory_stats: MemoryStats,
+ pub blkio_stats: BlkioStats,
pub cpu_stats: CpuStats,
}
diff --git a/src/transport.rs b/src/transport.rs
index da5c904..329ff9b 100644
--- a/src/transport.rs
+++ b/src/transport.rs
@@ -53,7 +53,7 @@ impl fmt::Debug for Transport {
}
impl Transport {
- pub fn request(&mut self,
+ pub fn request(&self,
method: Method,
endpoint: &str,
body: Option<Body>)
@@ -66,7 +66,7 @@ impl Transport {
res.read_to_string(&mut body).map(|_| body)
}
- pub fn stream(&mut self,
+ pub fn stream(&self,
method: Method,
endpoint: &str,
body: Option<Body>)