mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement docker images with the standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
45eca43f5b
commit
381262fbea
2 changed files with 58 additions and 26 deletions
|
@ -1,15 +1,13 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/client/lib"
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
|
@ -45,36 +43,22 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matchName := cmd.Arg(0)
|
var matchName string
|
||||||
v := url.Values{}
|
|
||||||
if imageFilterArgs.Len() > 0 {
|
|
||||||
filterJSON, err := filters.ToParam(imageFilterArgs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.Set("filters", filterJSON)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.NArg() == 1 {
|
if cmd.NArg() == 1 {
|
||||||
// FIXME rename this parameter, to not be confused with the filters flag
|
matchName = cmd.Arg(0)
|
||||||
v.Set("filter", matchName)
|
|
||||||
}
|
|
||||||
if *all {
|
|
||||||
v.Set("all", "1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serverResp, err := cli.call("GET", "/images/json?"+v.Encode(), nil, nil)
|
options := lib.ImageListOptions{
|
||||||
|
MatchName: matchName,
|
||||||
|
All: *all,
|
||||||
|
Filters: imageFilterArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
images, err := cli.client.ImageList(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer serverResp.body.Close()
|
|
||||||
|
|
||||||
images := []types.Image{}
|
|
||||||
if err := json.NewDecoder(serverResp.body).Decode(&images); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
if *showDigests {
|
if *showDigests {
|
||||||
|
|
48
api/client/lib/image_list.go
Normal file
48
api/client/lib/image_list.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/pkg/parsers/filters"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ImageListOptions holds parameters to filter the list of images with.
|
||||||
|
type ImageListOptions struct {
|
||||||
|
MatchName string
|
||||||
|
All bool
|
||||||
|
Filters filters.Args
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageList returns a list of images in the docker host.
|
||||||
|
func (cli *Client) ImageList(options ImageListOptions) ([]types.Image, error) {
|
||||||
|
var (
|
||||||
|
images []types.Image
|
||||||
|
query url.Values
|
||||||
|
)
|
||||||
|
|
||||||
|
if options.Filters.Len() > 0 {
|
||||||
|
filterJSON, err := filters.ToParam(options.Filters)
|
||||||
|
if err != nil {
|
||||||
|
return images, err
|
||||||
|
}
|
||||||
|
query.Set("filters", filterJSON)
|
||||||
|
}
|
||||||
|
if options.MatchName != "" {
|
||||||
|
// FIXME rename this parameter, to not be confused with the filters flag
|
||||||
|
query.Set("filter", options.MatchName)
|
||||||
|
}
|
||||||
|
if options.All {
|
||||||
|
query.Set("all", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
serverResp, err := cli.GET("/images/json?", query, nil)
|
||||||
|
if err != nil {
|
||||||
|
return images, err
|
||||||
|
}
|
||||||
|
defer serverResp.body.Close()
|
||||||
|
|
||||||
|
err = json.NewDecoder(serverResp.body).Decode(&images)
|
||||||
|
return images, err
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue