server: image_list: report image size

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-08-31 17:48:10 +02:00
parent 69fc590fc3
commit b16d73ab2f
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 35 additions and 13 deletions

View file

@ -41,7 +41,7 @@ type imageService struct {
// implementation. // implementation.
type ImageServer interface { type ImageServer interface {
// ListImages returns list of all images which match the filter. // ListImages returns list of all images which match the filter.
ListImages(filter string) ([]ImageResult, error) ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error)
// ImageStatus returns status of an image which matches the filter. // ImageStatus returns status of an image which matches the filter.
ImageStatus(systemContext *types.SystemContext, filter string) (*ImageResult, error) ImageStatus(systemContext *types.SystemContext, filter string) (*ImageResult, error)
// PullImage imports an image from the specified location. // PullImage imports an image from the specified location.
@ -59,25 +59,38 @@ type ImageServer interface {
ResolveNames(imageName string) ([]string, error) ResolveNames(imageName string) ([]string, error)
} }
func (svc *imageService) ListImages(filter string) ([]ImageResult, error) { func (svc *imageService) getRef(name string) (types.ImageReference, error) {
ref, err := alltransports.ParseImageName(name)
if err != nil {
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+name)
if err2 != nil {
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, name)
if err3 != nil {
return nil, err
}
ref2 = ref3
}
ref = ref2
}
return ref, nil
}
func (svc *imageService) ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error) {
results := []ImageResult{} results := []ImageResult{}
if filter != "" { if filter != "" {
ref, err := alltransports.ParseImageName(filter) ref, err := svc.getRef(filter)
if err != nil { if err != nil {
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+filter) return nil, err
if err2 != nil {
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, filter)
if err3 != nil {
return nil, err
}
ref2 = ref3
}
ref = ref2
} }
if image, err := istorage.Transport.GetStoreImage(svc.store, ref); err == nil { if image, err := istorage.Transport.GetStoreImage(svc.store, ref); err == nil {
img, err := ref.NewImage(systemContext)
if err != nil {
return nil, err
}
results = append(results, ImageResult{ results = append(results, ImageResult{
ID: image.ID, ID: image.ID,
Names: image.Names, Names: image.Names,
Size: imageSize(img),
}) })
} }
} else { } else {
@ -86,9 +99,18 @@ func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
return nil, err return nil, err
} }
for _, image := range images { for _, image := range images {
ref, err := svc.getRef(image.Names[0])
if err != nil {
return nil, err
}
img, err := ref.NewImage(systemContext)
if err != nil {
return nil, err
}
results = append(results, ImageResult{ results = append(results, ImageResult{
ID: image.ID, ID: image.ID,
Names: image.Names, Names: image.Names,
Size: imageSize(img),
}) })
} }
} }

View file

@ -17,7 +17,7 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
filter = filterImage.Image filter = filterImage.Image
} }
} }
results, err := s.StorageImageServer().ListImages(filter) results, err := s.StorageImageServer().ListImages(s.ImageContext(), filter)
if err != nil { if err != nil {
return nil, err return nil, err
} }