Implement docker restart with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: b7de53634c3262997593d140c9b68683135b55e1
Component: engine
This commit is contained in:
David Calavera
2015-12-09 12:04:56 -05:00
parent 6f93333b24
commit 74f650b8f2
2 changed files with 18 additions and 7 deletions
@@ -0,0 +1,17 @@
package lib
import (
"net/url"
"strconv"
)
// ContainerRestart stops and starts a container again.
// It makes the daemon to wait for the container to be up again for
// a specific amount of time, given the timeout.
func (cli *Client) ContainerRestart(containerID string, timeout int) error {
var query url.Values
query.Set("t", strconv.Itoa(timeout))
resp, err := cli.POST("/containers"+containerID+"/restart", query, nil, nil)
ensureReaderClosed(resp)
return err
}
+1 -7
View File
@@ -2,8 +2,6 @@ package client
import (
"fmt"
"net/url"
"strconv"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
@@ -19,13 +17,9 @@ func (cli *DockerCli) CmdRestart(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+"/restart?"+v.Encode(), nil, nil))
if err != nil {
if err := cli.client.ContainerRestart(name, *nSeconds); err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
errNames = append(errNames, name)
} else {