server: image_list: report image size
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
69fc590fc3
commit
b16d73ab2f
2 changed files with 35 additions and 13 deletions
|
@ -41,7 +41,7 @@ type imageService struct {
|
|||
// implementation.
|
||||
type ImageServer interface {
|
||||
// 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(systemContext *types.SystemContext, filter string) (*ImageResult, error)
|
||||
// PullImage imports an image from the specified location.
|
||||
|
@ -59,14 +59,12 @@ type ImageServer interface {
|
|||
ResolveNames(imageName string) ([]string, error)
|
||||
}
|
||||
|
||||
func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
|
||||
results := []ImageResult{}
|
||||
if filter != "" {
|
||||
ref, err := alltransports.ParseImageName(filter)
|
||||
func (svc *imageService) getRef(name string) (types.ImageReference, error) {
|
||||
ref, err := alltransports.ParseImageName(name)
|
||||
if err != nil {
|
||||
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+filter)
|
||||
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+name)
|
||||
if err2 != nil {
|
||||
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, filter)
|
||||
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, name)
|
||||
if err3 != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -74,10 +72,25 @@ func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
|
|||
}
|
||||
ref = ref2
|
||||
}
|
||||
return ref, nil
|
||||
}
|
||||
|
||||
func (svc *imageService) ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error) {
|
||||
results := []ImageResult{}
|
||||
if filter != "" {
|
||||
ref, err := svc.getRef(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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{
|
||||
ID: image.ID,
|
||||
Names: image.Names,
|
||||
Size: imageSize(img),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
@ -86,9 +99,18 @@ func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
|
|||
return nil, err
|
||||
}
|
||||
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{
|
||||
ID: image.ID,
|
||||
Names: image.Names,
|
||||
Size: imageSize(img),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
|
|||
filter = filterImage.Image
|
||||
}
|
||||
}
|
||||
results, err := s.StorageImageServer().ListImages(filter)
|
||||
results, err := s.StorageImageServer().ListImages(s.ImageContext(), filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue