diff --git a/api/api.go b/api/api.go index 991ef19917..7b03748ce7 100644 --- a/api/api.go +++ b/api/api.go @@ -102,6 +102,34 @@ func postContainersStart(c *HttpApiContext, w http.ResponseWriter, r *http.Reque fmt.Fprintf(w, "{%q:%q}", "Id", container.Id) } +// POST /containers/{name:.*}/pause +func postContainersPause(c *HttpApiContext, w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + container := c.cluster.Container(name) + if container == nil { + http.Error(w, fmt.Sprintf("Container %s not found", name), http.StatusNotFound) + return + } + if err := container.Pause(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + fmt.Fprintf(w, "{%q:%q}", "Id", container.Id) +} + +// POST /containers/{name:.*}/unpause +func postContainersUnpause(c *HttpApiContext, w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + container := c.cluster.Container(name) + if container == nil { + http.Error(w, fmt.Sprintf("Container %s not found", name), http.StatusNotFound) + return + } + if err := container.Unpause(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + fmt.Fprintf(w, "{%q:%q}", "Id", container.Id) +} + // DELETE /containers/{name:.*} func deleteContainer(c *HttpApiContext, w http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { @@ -181,8 +209,8 @@ func createRouter(c *HttpApiContext) (*mux.Router, error) { "/images/{name:.*}/tag": notImplementedHandler, "/containers/create": notImplementedHandler, "/containers/{name:.*}/kill": notImplementedHandler, - "/containers/{name:.*}/pause": notImplementedHandler, - "/containers/{name:.*}/unpause": notImplementedHandler, + "/containers/{name:.*}/pause": postContainerPause, + "/containers/{name:.*}/unpause": postContainerUnpause, "/containers/{name:.*}/restart": notImplementedHandler, "/containers/{name:.*}/start": postContainersStart, "/containers/{name:.*}/stop": notImplementedHandler, diff --git a/container.go b/container.go index f77ab628a5..0ef174514c 100644 --- a/container.go +++ b/container.go @@ -27,3 +27,11 @@ func (c *Container) Stop() error { func (c *Container) Restart(timeout int) error { return c.node.client.RestartContainer(c.Id, timeout) } + +func (c *Container) Pause() error { + return c.node.client.PauseContainer(c.Id) +} + +func (c *Container) Unpause(timeout int) error { + return c.node.client.UnpauseContainer(c.Id) +}