Implement docker load with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
c57e62d00e
commit
9073a52ea8
2 changed files with 28 additions and 13 deletions
17
api/client/lib/image_load.go
Normal file
17
api/client/lib/image_load.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// ImageLoad loads an image in the docker host from the client host.
|
||||
// It's up to the caller to close the io.ReadCloser returned by
|
||||
// this function.
|
||||
func (cli *Client) ImageLoad(input io.Reader) (io.ReadCloser, error) {
|
||||
resp, err := cli.POSTRaw("/images/load", url.Values{}, input, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.body, nil
|
||||
}
|
|
@ -17,26 +17,24 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
|||
cmd := Cli.Subcmd("load", nil, Cli.DockerCommands["load"].Description, true)
|
||||
infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
|
||||
cmd.Require(flag.Exact, 0)
|
||||
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
input io.Reader = cli.in
|
||||
err error
|
||||
)
|
||||
var input io.Reader = cli.in
|
||||
if *infile != "" {
|
||||
input, err = os.Open(*infile)
|
||||
file, err := os.Open(*infile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
input = file
|
||||
}
|
||||
sopts := &streamOpts{
|
||||
rawTerminal: true,
|
||||
in: input,
|
||||
out: cli.out,
|
||||
}
|
||||
if _, err := cli.stream("POST", "/images/load", sopts); err != nil {
|
||||
|
||||
responseBody, err := cli.client.ImageLoad(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
defer responseBody.Close()
|
||||
|
||||
_, err = io.Copy(cli.out, responseBody)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue