diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-25 01:26:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 01:26:21 +0100 |
commit | 69b011d3ac39b985cdbd2bacfa1eaeba166bf224 (patch) | |
tree | 21791a26464b4fe55fd879b7c649ea8cd63884db /pkg/domain/infra | |
parent | b4520649af59780df494d75f50d0b5081eafff04 (diff) | |
parent | 1d7cb7cc48d06631e2bdfd0e25eeccc8e87b042f (diff) | |
download | podman-69b011d3ac39b985cdbd2bacfa1eaeba166bf224.tar.gz podman-69b011d3ac39b985cdbd2bacfa1eaeba166bf224.tar.bz2 podman-69b011d3ac39b985cdbd2bacfa1eaeba166bf224.zip |
Merge pull request #5604 from jwhonce/wip/images
V2 podman images/image list
Diffstat (limited to 'pkg/domain/infra')
-rw-r--r-- | pkg/domain/infra/abi/images.go | 29 | ||||
-rw-r--r-- | pkg/domain/infra/abi/images_list.go | 80 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/images.go | 11 |
3 files changed, 85 insertions, 35 deletions
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index 2db08f259..6e9d7f566 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -39,35 +39,6 @@ func (ir *ImageEngine) Prune(ctx context.Context, opts entities.ImagePruneOption return &report, nil } -func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) (*entities.ImageListReport, error) { - var ( - images []*libpodImage.Image - err error - ) - - filters := utils.ToLibpodFilters(opts.Filters) - if len(filters) > 0 { - images, err = ir.Libpod.ImageRuntime().GetImagesWithFilters(filters) - } else { - images, err = ir.Libpod.ImageRuntime().GetImages() - } - if err != nil { - return nil, err - } - - report := entities.ImageListReport{ - Images: make([]entities.ImageSummary, len(images)), - } - for i, img := range images { - hold := entities.ImageSummary{} - if err := utils.DeepCopy(&hold, img); err != nil { - return nil, err - } - report.Images[i] = hold - } - return &report, nil -} - func (ir *ImageEngine) History(ctx context.Context, nameOrId string, opts entities.ImageHistoryOptions) (*entities.ImageHistoryReport, error) { image, err := ir.Libpod.ImageRuntime().NewFromLocal(nameOrId) if err != nil { diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go new file mode 100644 index 000000000..2f4020374 --- /dev/null +++ b/pkg/domain/infra/abi/images_list.go @@ -0,0 +1,80 @@ +// +build ABISupport + +package abi + +import ( + "context" + + libpodImage "github.com/containers/libpod/libpod/image" + "github.com/containers/libpod/pkg/domain/entities" +) + +func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) { + var ( + images []*libpodImage.Image + err error + ) + + // TODO: Future work support for domain.Filters + // filters := utils.ToLibpodFilters(opts.Filters) + + if len(opts.Filter) > 0 { + images, err = ir.Libpod.ImageRuntime().GetImagesWithFilters(opts.Filter) + } else { + images, err = ir.Libpod.ImageRuntime().GetImages() + } + if err != nil { + return nil, err + } + + summaries := make([]*entities.ImageSummary, len(images)) + for i, img := range images { + var repoTags []string + if opts.All { + pairs, err := libpodImage.ReposToMap(img.Names()) + if err != nil { + return nil, err + } + + for repo, tags := range pairs { + for _, tag := range tags { + repoTags = append(repoTags, repo+":"+tag) + } + } + } else { + repoTags, _ = img.RepoTags() + } + + digests := make([]string, len(img.Digests())) + for j, d := range img.Digests() { + digests[j] = string(d) + } + + e := entities.ImageSummary{ + ID: img.ID(), + + ConfigDigest: string(img.ConfigDigest), + Created: img.Created().Unix(), + Dangling: img.Dangling(), + Digest: string(img.Digest()), + Digests: digests, + History: img.NamesHistory(), + Names: img.Names(), + ParentId: img.Parent, + ReadOnly: img.IsReadOnly(), + SharedSize: 0, + VirtualSize: img.VirtualSize, + RepoTags: repoTags, + } + e.Labels, _ = img.Labels(context.TODO()) + + ctnrs, _ := img.Containers() + e.Containers = len(ctnrs) + + sz, _ := img.Size(context.TODO()) + e.Size = int64(*sz) + + summaries[i] = &e + } + return summaries, nil +} diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index 718685e57..60df40498 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -32,23 +32,22 @@ func (ir *ImageEngine) Delete(ctx context.Context, nameOrId string, opts entitie return &report, err } -func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) (*entities.ImageListReport, error) { +func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) { images, err := images.List(ir.ClientCxt, &opts.All, opts.Filters) + if err != nil { return nil, err } - report := entities.ImageListReport{ - Images: make([]entities.ImageSummary, len(images)), - } + is := make([]*entities.ImageSummary, len(images)) for i, img := range images { hold := entities.ImageSummary{} if err := utils.DeepCopy(&hold, img); err != nil { return nil, err } - report.Images[i] = hold + is[i] = &hold } - return &report, nil + return is, nil } func (ir *ImageEngine) History(ctx context.Context, nameOrId string, opts entities.ImageHistoryOptions) (*entities.ImageHistoryReport, error) { |