summaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-03-25 01:26:21 +0100
committerGitHub <noreply@github.com>2020-03-25 01:26:21 +0100
commit69b011d3ac39b985cdbd2bacfa1eaeba166bf224 (patch)
tree21791a26464b4fe55fd879b7c649ea8cd63884db /pkg/api
parentb4520649af59780df494d75f50d0b5081eafff04 (diff)
parent1d7cb7cc48d06631e2bdfd0e25eeccc8e87b042f (diff)
downloadpodman-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/api')
-rw-r--r--pkg/api/handlers/compat/images.go3
-rw-r--r--pkg/api/handlers/libpod/images.go5
-rw-r--r--pkg/api/handlers/types.go70
-rw-r--r--pkg/api/server/swagger.go3
4 files changed, 45 insertions, 36 deletions
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go
index b18687bf9..cce718f54 100644
--- a/pkg/api/handlers/compat/images.go
+++ b/pkg/api/handlers/compat/images.go
@@ -15,6 +15,7 @@ import (
image2 "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util"
"github.com/docker/docker/api/types"
"github.com/gorilla/schema"
@@ -305,7 +306,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed get images"))
return
}
- var summaries = make([]*handlers.ImageSummary, len(images))
+ var summaries = make([]*entities.ImageSummary, len(images))
for j, img := range images {
is, err := handlers.ImageToImageSummary(img)
if err != nil {
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index b6f2f58e8..f8e666451 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -21,6 +21,7 @@ import (
image2 "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util"
"github.com/gorilla/schema"
"github.com/pkg/errors"
@@ -101,7 +102,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed get images"))
return
}
- var summaries = make([]*handlers.ImageSummary, len(images))
+ var summaries = make([]*entities.ImageSummary, len(images))
for j, img := range images {
is, err := handlers.ImageToImageSummary(img)
if err != nil {
@@ -109,7 +110,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
return
}
// libpod has additional fields that we need to populate.
- is.CreatedTime = img.Created()
+ is.Created = img.Created().Unix()
is.ReadOnly = img.IsReadOnly()
summaries[j] = is
}
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index c6b70251b..84ca0fbed 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -13,6 +13,7 @@ import (
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
libpodImage "github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/pkg/domain/entities"
docker "github.com/docker/docker/api/types"
dockerContainer "github.com/docker/docker/api/types/container"
dockerEvents "github.com/docker/docker/api/types/events"
@@ -45,12 +46,6 @@ type LibpodImagesPullReport struct {
ID string `json:"id"`
}
-type ImageSummary struct {
- docker.ImageSummary
- CreatedTime time.Time `json:"CreatedTime,omitempty"`
- ReadOnly bool `json:"ReadOnly,omitempty"`
-}
-
type ContainersPruneReport struct {
docker.ContainersPruneReport
}
@@ -195,23 +190,13 @@ func EventToApiEvent(e *events.Event) *Event {
}}
}
-func ImageToImageSummary(l *libpodImage.Image) (*ImageSummary, error) {
+func ImageToImageSummary(l *libpodImage.Image) (*entities.ImageSummary, error) {
containers, err := l.Containers()
if err != nil {
return nil, errors.Wrapf(err, "Failed to obtain Containers for image %s", l.ID())
}
containerCount := len(containers)
- var digests []string
- for _, d := range l.Digests() {
- digests = append(digests, string(d))
- }
-
- tags, err := l.RepoTags()
- if err != nil {
- return nil, errors.Wrapf(err, "Failed to obtain RepoTags for image %s", l.ID())
- }
-
// FIXME: GetParent() panics
// parent, err := l.GetParent(context.TODO())
// if err != nil {
@@ -227,20 +212,43 @@ func ImageToImageSummary(l *libpodImage.Image) (*ImageSummary, error) {
if err != nil {
return nil, errors.Wrapf(err, "Failed to obtain Size for image %s", l.ID())
}
- dockerSummary := docker.ImageSummary{
- Containers: int64(containerCount),
- Created: l.Created().Unix(),
- ID: l.ID(),
- Labels: labels,
- ParentID: l.Parent,
- RepoDigests: digests,
- RepoTags: tags,
- SharedSize: 0,
- Size: int64(*size),
- VirtualSize: int64(*size),
- }
- is := ImageSummary{
- ImageSummary: dockerSummary,
+
+ repoTags, err := l.RepoTags()
+ if err != nil {
+ return nil, errors.Wrapf(err, "Failed to obtain RepoTags for image %s", l.ID())
+ }
+
+ history, err := l.History(context.TODO())
+ if err != nil {
+ return nil, errors.Wrapf(err, "Failed to obtain History for image %s", l.ID())
+ }
+ historyIds := make([]string, len(history))
+ for i, h := range history {
+ historyIds[i] = h.ID
+ }
+
+ digests := make([]string, len(l.Digests()))
+ for i, d := range l.Digests() {
+ digests[i] = string(d)
+ }
+
+ is := entities.ImageSummary{
+ ID: l.ID(),
+ ParentId: l.Parent,
+ RepoTags: repoTags,
+ Created: l.Created().Unix(),
+ Size: int64(*size),
+ SharedSize: 0,
+ VirtualSize: l.VirtualSize,
+ Labels: labels,
+ Containers: containerCount,
+ ReadOnly: l.IsReadOnly(),
+ Dangling: l.Dangling(),
+ Names: l.Names(),
+ Digest: string(l.Digest()),
+ Digests: digests,
+ ConfigDigest: string(l.ConfigDigest),
+ History: historyIds,
}
return &is, nil
}
diff --git a/pkg/api/server/swagger.go b/pkg/api/server/swagger.go
index 50ce42b3b..9156f3f8a 100644
--- a/pkg/api/server/swagger.go
+++ b/pkg/api/server/swagger.go
@@ -2,7 +2,6 @@ package server
import (
"github.com/containers/libpod/libpod"
- "github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
"github.com/containers/libpod/pkg/domain/entities"
)
@@ -128,7 +127,7 @@ type swagPodAlreadyStopped struct {
// swagger:response DockerImageSummary
type swagImageSummary struct {
// in:body
- Body []handlers.ImageSummary
+ Body []entities.ImageSummary
}
// List Containers