From 9ec1cf92f5fda4b5bae02408b469cf8f65c96f9a Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 4 Dec 2015 13:38:31 -0500 Subject: [PATCH] Implement docker stop with standalone client lib. Signed-off-by: David Calavera --- api/client/lib/container_stop.go | 16 ++++++++++++++++ api/client/stop.go | 8 +------- 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 api/client/lib/container_stop.go diff --git a/api/client/lib/container_stop.go b/api/client/lib/container_stop.go new file mode 100644 index 0000000000..ea9a3d8ab0 --- /dev/null +++ b/api/client/lib/container_stop.go @@ -0,0 +1,16 @@ +package lib + +import ( + "net/url" + "strconv" +) + +// ContainerStop stops a container without terminating the process. +// The process is blocked until the container stops or the timeout expires. +func (cli *Client) ContainerStop(containerID string, timeout int) error { + var query url.Values + query.Set("t", strconv.Itoa(timeout)) + resp, err := cli.POST("/containers/"+containerID+"/stop", query, nil, nil) + ensureReaderClosed(resp) + return err +} diff --git a/api/client/stop.go b/api/client/stop.go index 91f5e65b0e..d5da5c64a6 100644 --- a/api/client/stop.go +++ b/api/client/stop.go @@ -2,8 +2,6 @@ package client import ( "fmt" - "net/url" - "strconv" Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" @@ -21,13 +19,9 @@ func (cli *DockerCli) CmdStop(args ...string) error { cmd.ParseFlags(args, true) - v := url.Values{} - v.Set("t", strconv.Itoa(*nSeconds)) - var errNames []string for _, name := range cmd.Args() { - _, _, err := readBody(cli.call("POST", "/containers/"+name+"/stop?"+v.Encode(), nil, nil)) - if err != nil { + if err := cli.client.ContainerStop(name, *nSeconds); err != nil { fmt.Fprintf(cli.err, "%s\n", err) errNames = append(errNames, name) } else {