Просмотр исходного кода

Implement container rename with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
David Calavera 9 лет назад
Родитель
Сommit
ac8fb77c74
2 измененных файлов с 13 добавлено и 1 удалено
  1. 12 0
      api/client/lib/container_rename.go
  2. 1 1
      api/client/rename.go

+ 12 - 0
api/client/lib/container_rename.go

@@ -0,0 +1,12 @@
+package lib
+
+import "net/url"
+
+// ContainerRename changes the name of a given container.
+func (cli *Client) ContainerRename(containerID, newContainerName string) error {
+	var query url.Values
+	query.Set("name", newContainerName)
+	resp, err := cli.POST("/containers/"+containerID+"/rename", query, nil, nil)
+	ensureReaderClosed(resp)
+	return err
+}

+ 1 - 1
api/client/rename.go

@@ -24,7 +24,7 @@ func (cli *DockerCli) CmdRename(args ...string) error {
 		return fmt.Errorf("Error: Neither old nor new names may be empty")
 	}
 
-	if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/rename?name=%s", oldName, newName), nil, nil)); err != nil {
+	if err := cli.client.ContainerRename(oldName, newName); err != nil {
 		fmt.Fprintf(cli.err, "%s\n", err)
 		return fmt.Errorf("Error: failed to rename container named %s", oldName)
 	}